mattetti-globalite 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,364 @@
1
+ locale_name: 台灣 (Taiwan)
2
+ # ActiveRecord::Errors.default_error_messages
3
+ error_message_inclusion: 不在指定的名單上
4
+ error_message_exclusion: 已在指定的名單上
5
+ error_message_invalid: 是錯誤的資料
6
+ error_message_confirmation: 與指定值不同
7
+ error_message_accepted: 必須要選擇接受指定的條款
8
+ error_message_empty: 不能不填
9
+ error_message_blank: 不能是空白
10
+ error_message_too_long: 太長 (最多 %d 個字元)
11
+ error_message_too_short: 太短 (最少 %d 個字元)
12
+ error_message_wrong_length: 長度不正確 (應該要 %d 個字元)
13
+ error_message_taken: 已經有人使用
14
+ error_message_not_a_number: 不是數字
15
+
16
+ # ActionController::Base.resources_path_names
17
+ # Chinese needs to be transliterated into latin
18
+ resources_path_new: xin-de
19
+ resources_path_edit: bian-ji
20
+ # translated using google translate,
21
+ # transliterated using http://rcalvi.com/cu_archive/Transliteration/demo.html
22
+
23
+ # used by ActionView::Helpers::ActiveRecordHelper.error_messages_for
24
+ active_record_helper_header_message: 輸入資訊錯誤
25
+ active_record_helper_error_description: 請更正下列問題,
26
+
27
+ # used by ActionView::Helpers::DateHelper.distance_of_time_in_words
28
+ date_helper_less_than_x_seconds: 少於 %d 秒
29
+ date_helper_half_a_minute: 30 秒
30
+ date_helper_less_than_a_minute: 少於一分鐘
31
+ date_helper_one_minute: 一分鐘
32
+ date_helper_x_minutes: %d 分鐘
33
+ date_helper_one_hour: 約 1 小時
34
+ date_helper_x_hours: 約 %d 小時
35
+ date_helper_one_day: 1 天
36
+ date_helper_x_days: %d 天
37
+ date_helper_one_month: 1 個月
38
+ date_helper_x_months: %d 個月
39
+ date_helper_one_year: 1 年
40
+ date_helper_x_years: %d 年
41
+
42
+ # DON'T TRANSLATE, just order
43
+ date_helper_order: [:day, :month, :year] #default Rails is US ordered: :order => [:year, :month, :day]
44
+
45
+ date_helper_date_formats: # DON'T TRANSLATE, RE ORDER
46
+ default: "%Y/%m/%d"
47
+ short: "%b %e"
48
+ long: "%b %e, %Y"
49
+
50
+ date_helper_time_formats: # DON'T TRANSLATE, RE ORDER
51
+ default: "%a, %Y %b %d %H:%M:%S %z"
52
+ short: "%b %d, %H:%M"
53
+ long: "%Y/%b/%d %H:%M"
54
+
55
+ # added at the end of date if your date system doesn't use a 24 hours system
56
+ date_helper_am: am
57
+ date_helper_pm: pm
58
+
59
+ # used by ActionView::Helpers::NumberHelper.number_to_currency
60
+ number_helper_unit: "NT$"
61
+ number_helper_separator: "." #unit separator (between integer part and fraction part)
62
+ number_helper_delimiter: "," #delimiter between each group of thousands. Example: 1.234.567
63
+ number_helper_order: [ unit, number ]
64
+ #to support for instance French format, the order is different: Unit comes last (ex. "1.234,00 €")
65
+
66
+ # use by +Array#to_sentence()+
67
+ array_connector: '和'
68
+ array_skip_last_comma: 'true'
69
+
70
+ date_helper_month_names:
71
+ - # Leave that line
72
+ - # Leave that line
73
+ - 一月
74
+ - 二月
75
+ - 三月
76
+ - 四月
77
+ - 五月
78
+ - 六月
79
+ - 七月
80
+ - 八月
81
+ - 九月
82
+ - 十月
83
+ - 十一月
84
+ - 十二月
85
+
86
+ date_helper_abbr_month_names:
87
+ - # Leave that line
88
+ - # Leave that line
89
+ - 1月
90
+ - 2月
91
+ - 3月
92
+ - 4月
93
+ - 5月
94
+ - 6月
95
+ - 7月
96
+ - 8月
97
+ - 9月
98
+ - 10月
99
+ - 11月
100
+ - 12月
101
+
102
+ date_helper_day_names:
103
+ - 星期天
104
+ - 星期一
105
+ - 星期二
106
+ - 星期三
107
+ - 星期四
108
+ - 星期五
109
+ - 星期六
110
+
111
+ date_helper_abbr_day_names:
112
+ - 周日
113
+ - 周一
114
+ - 周二
115
+ - 周三
116
+ - 周四
117
+ - 周五
118
+ - 周六
119
+
120
+ countries_list:
121
+ - Afghanistan
122
+ - Albania
123
+ - Algeria
124
+ - American Samoa
125
+ - Andorra
126
+ - Angola
127
+ - Anguilla
128
+ - Antarctica
129
+ - Antigua And Barbuda
130
+ - Argentina
131
+ - Armenia
132
+ - Aruba
133
+ - Australia
134
+ - Austria
135
+ - Azerbaijan
136
+ - Bahamas
137
+ - Bahrain
138
+ - Bangladesh
139
+ - Barbados
140
+ - Belarus
141
+ - Belgium
142
+ - Belize
143
+ - Benin
144
+ - Bermuda
145
+ - Bhutan
146
+ - Bolivia
147
+ - Bosnia and Herzegowina
148
+ - Botswana
149
+ - Bouvet Island
150
+ - Brazil
151
+ - British Indian Ocean Territory
152
+ - Brunei Darussalam
153
+ - Bulgaria
154
+ - Burkina Faso
155
+ - Burma
156
+ - Burundi
157
+ - Cambodia
158
+ - Cameroon
159
+ - Canada
160
+ - Cape Verde
161
+ - Cayman Islands
162
+ - Central African Republic
163
+ - Chad
164
+ - Chile
165
+ - China
166
+ - Christmas Island
167
+ - Cocos (Keeling) Islands
168
+ - Colombia
169
+ - Comoros
170
+ - Congo
171
+ - Congo, the Democratic Republic of the
172
+ - Cook Islands
173
+ - Costa Rica
174
+ - Cote d'Ivoire
175
+ - Croatia
176
+ - Cuba
177
+ - Cyprus
178
+ - Czech Republic
179
+ - Denmark
180
+ - Djibouti
181
+ - Dominica
182
+ - Dominican Republic
183
+ - East Timor
184
+ - Ecuador
185
+ - Egypt
186
+ - El Salvador
187
+ - England
188
+ - Equatorial Guinea
189
+ - Eritrea
190
+ - Espana
191
+ - Estonia
192
+ - Ethiopia
193
+ - Falkland Islands
194
+ - Faroe Islands
195
+ - Fiji
196
+ - Finland
197
+ - France
198
+ - French Guiana
199
+ - French Polynesia
200
+ - French Southern Territories
201
+ - Gabon
202
+ - Gambia
203
+ - Georgia
204
+ - Germany
205
+ - Ghana
206
+ - Gibraltar
207
+ - Great Britain
208
+ - Greece
209
+ - Greenland
210
+ - Grenada
211
+ - Guadeloupe
212
+ - Guam
213
+ - Guatemala
214
+ - Guinea
215
+ - Guinea-Bissau
216
+ - Guyana
217
+ - Haiti
218
+ - Heard and Mc Donald Islands
219
+ - Honduras
220
+ - Hong Kong
221
+ - Hungary
222
+ - Iceland
223
+ - India
224
+ - Indonesia
225
+ - Ireland
226
+ - Israel
227
+ - Italy
228
+ - Iran
229
+ - Iraq
230
+ - Jamaica
231
+ - Japan
232
+ - Jordan
233
+ - Kazakhstan
234
+ - Kenya
235
+ - Kiribati
236
+ - Korea, Republic of
237
+ - Korea (South)
238
+ - Kuwait
239
+ - Kyrgyzstan
240
+ - Lao People's Democratic Republic
241
+ - Latvia
242
+ - Lebanon
243
+ - Lesotho
244
+ - Liberia
245
+ - Liechtenstein
246
+ - Lithuania
247
+ - Luxembourg
248
+ - Macau
249
+ - Macedonia
250
+ - Madagascar
251
+ - Malawi
252
+ - Malaysia
253
+ - Maldives
254
+ - Mali
255
+ - Malta
256
+ - Marshall Islands
257
+ - Martinique
258
+ - Mauritania
259
+ - Mauritius
260
+ - Mayotte
261
+ - Mexico
262
+ - Micronesia, Federated States of
263
+ - Moldova, Republic of
264
+ - Monaco
265
+ - Mongolia
266
+ - Montserrat
267
+ - Morocco
268
+ - Mozambique
269
+ - Myanmar
270
+ - Namibia
271
+ - Nauru
272
+ - Nepal
273
+ - Netherlands
274
+ - Netherlands Antilles
275
+ - New Caledonia
276
+ - New Zealand
277
+ - Nicaragua
278
+ - Niger
279
+ - Nigeria
280
+ - Niue
281
+ - Norfolk Island
282
+ - Northern Ireland
283
+ - Northern Mariana Islands
284
+ - Norway
285
+ - Oman
286
+ - Pakistan
287
+ - Palau
288
+ - Panama
289
+ - Papua New Guinea
290
+ - Paraguay
291
+ - Peru
292
+ - Philippines
293
+ - Pitcairn
294
+ - Poland
295
+ - Portugal
296
+ - Puerto Rico
297
+ - Qatar
298
+ - Reunion
299
+ - Romania
300
+ - Russia
301
+ - Rwanda
302
+ - Saint Kitts and Nevis
303
+ - Saint Lucia
304
+ - Saint Vincent and the Grenadines
305
+ - Samoa (Independent)
306
+ - San Marino
307
+ - Sao Tome and Principe
308
+ - Saudi Arabia
309
+ - Scotland
310
+ - Senegal
311
+ - Serbia and Montenegro
312
+ - Seychelles
313
+ - Sierra Leone
314
+ - Singapore
315
+ - Slovakia
316
+ - Slovenia
317
+ - Solomon Islands
318
+ - Somalia
319
+ - South Africa
320
+ - South Georgia and the South Sandwich Islands
321
+ - South Korea
322
+ - Spain
323
+ - Sri Lanka
324
+ - St. Helena
325
+ - St. Pierre and Miquelon
326
+ - Suriname
327
+ - Svalbard and Jan Mayen Islands
328
+ - Swaziland
329
+ - Sweden
330
+ - Switzerland
331
+ - Taiwan
332
+ - Tajikistan
333
+ - Tanzania
334
+ - Thailand
335
+ - Togo
336
+ - Tokelau
337
+ - Tonga
338
+ - Trinidad
339
+ - Trinidad and Tobago
340
+ - Tunisia
341
+ - Turkey
342
+ - Turkmenistan
343
+ - Turks and Caicos Islands
344
+ - Tuvalu
345
+ - Uganda
346
+ - Ukraine
347
+ - United Arab Emirates
348
+ - United Kingdom
349
+ - United States
350
+ - United States Minor Outlying Islands
351
+ - Uruguay
352
+ - Uzbekistan
353
+ - Vanuatu
354
+ - Vatican City State (Holy See)
355
+ - Venezuela
356
+ - Viet Nam
357
+ - Virgin Islands (British)
358
+ - Virgin Islands (U.S.)
359
+ - Wales
360
+ - Wallis and Futuna Islands
361
+ - Western Sahara
362
+ - Yemen
363
+ - Zambia
364
+ - Zimbabwe
@@ -0,0 +1,30 @@
1
+ # Add support for localization keys
2
+ require 'rails/core_ext'
3
+ require 'globalite/l10n'
4
+ require 'globalite/locale'
5
+ Symbol.send :include, SymbolExtension
6
+
7
+ module Globalite
8
+ extend L10n
9
+ def self.localize_rails
10
+ ActiveRecord::Errors.relocalize
11
+ ActionController::Base.relocalize
12
+ end
13
+ end
14
+
15
+ # Localize Rails
16
+ require 'rails/localization.rb'
17
+ require 'rails/localized_action_view'
18
+ require 'rails/localized_action_controller'
19
+ require 'rails/localized_active_record'
20
+
21
+ # added Boolean function to 'boolean' a string
22
+ module Kernel
23
+ def Boolean(string)
24
+ return true if string == true || string =~ /^true$/i
25
+ return false if string == false || string.nil? || string =~ /^false$/i
26
+ raise ArgumentError.new("invalid value for Boolean: \"#{string}\"")
27
+ end
28
+ end
29
+
30
+ Globalite.load_localization!
@@ -0,0 +1,300 @@
1
+ module Globalite
2
+
3
+ module L10n
4
+
5
+ @@default_language = :en
6
+ attr_reader :default_language
7
+
8
+ @@default_country = :*
9
+ mattr_reader :default_country
10
+
11
+ @@reserved_keys = [ :limit ]
12
+ mattr_reader :reserved_keys
13
+
14
+ @@languages = []
15
+ def languages
16
+ @@languages
17
+ end
18
+
19
+ def default_language
20
+ @@default_language
21
+ end
22
+
23
+ @@countries = []
24
+ def countries
25
+ @@countries
26
+ end
27
+
28
+ @@locales = {}
29
+ def locales
30
+ @@locales.keys
31
+ end
32
+
33
+ @@rails_locales = {}
34
+ def rails_locales
35
+ @@rails_locales
36
+ end
37
+
38
+ @@ui_locales = {}
39
+ def ui_locales
40
+ @@ui_locales
41
+ end
42
+
43
+ @@current_language = nil
44
+ def current_language
45
+ @@current_language || default_language
46
+ end
47
+ alias :language :current_language
48
+
49
+ @@current_country = nil
50
+ def country
51
+ @@current_country || default_country
52
+ end
53
+ alias :current_country :country
54
+
55
+ def current_locale
56
+ "#{current_language}-#{current_country}".to_sym
57
+ end
58
+ alias :locale :current_locale
59
+
60
+ # Set the current language ( ISO 639-1 language code in lowercase letters)
61
+ # Usage:
62
+ # Globalite.language = 'fr' or Globalite.language = :Fr
63
+ # Will save the current language code if available, otherwise nada, switching back to the previous language
64
+ #
65
+ def language=(language)
66
+
67
+ language = language.to_s.downcase.to_sym if language.class == Symbol
68
+ language = language.downcase.to_sym if language.class == String && !language.empty?
69
+
70
+ if @@languages.include?(language)
71
+ @@current_language = language
72
+ if !@@locales.include?("#{language}-#{@@current_country}".to_sym)
73
+ @@current_country = :*
74
+ end
75
+ end
76
+
77
+ #Locale.update_session_locale
78
+ localize_rails
79
+ @@current_language
80
+ end
81
+ alias :current_language= :language=
82
+
83
+ # Set the current country code (ISO 3166 country code in uppercase letters)
84
+ # Usage:
85
+ # Globalite.country = 'US' or Globalite.country = :fr
86
+ # Will store the current country code if supported
87
+ # Will try to automatically find the language for your country
88
+ # If the country isn't unknown to the system, the country will be set as :*
89
+ #
90
+ def country=(country)
91
+ load_localization! if (defined? RAILS_ENV) && (RAILS_ENV == 'development')
92
+ country = country.to_s.upcase.to_sym if country.class == Symbol
93
+ country = country.upcase.to_sym if country.class == String && !country.empty?
94
+
95
+ if @@locales.include?("#{current_language}-#{country}".to_sym)
96
+ @@current_country = country
97
+ elsif locales.each {|locale| locale =~ /[a-z][a-z]-#{country.to_s}/ }
98
+ locales.each do |key|
99
+ if key.to_s.include?(country.to_s)
100
+ @new_language = key.to_s.split('-')[0].downcase.to_sym
101
+ end
102
+ end
103
+ if @new_language && @@locales.include?("#{@new_language}-#{country}".to_sym)
104
+ @@current_language = @new_language
105
+ @@current_country = country
106
+ end
107
+ else
108
+ @@current_country = :*
109
+ end
110
+ #Locale.update_session_locale
111
+ @@current_country
112
+ end
113
+ alias :current_country= :country=
114
+
115
+ def locale=(locale)
116
+ Locale.set_code(locale)
117
+ end
118
+ alias :current_locale= :locale=
119
+
120
+ @@localization_sources = []
121
+ def add_localization_source(path)
122
+ @@localization_sources << path
123
+ load_localization!
124
+ end
125
+
126
+ def localization_sources
127
+ @@localization_sources
128
+ end
129
+
130
+ # List localizations for the current locale
131
+ def localizations
132
+ @@locales[Locale.code] || {}
133
+ end
134
+
135
+ # Return the translation for the key, a string can be passed to replaced a missing translation
136
+ def localize(key, error_msg='__localization_missing__', args={}, locale=nil)
137
+ return if reserved_keys.include? key
138
+
139
+ # Set a temporary Locale to support the localized_in method
140
+ #
141
+ unless locale.nil?
142
+ @original_locale = Locale.code
143
+ Locale.set_code(locale)
144
+ end
145
+ localized = localizations[key] || error_msg
146
+ # Get translations from another country but in the same language if Globalite can't find a translation for my locale
147
+ #
148
+ if localized == error_msg
149
+ locales.each do |t_locale|
150
+ if t_locale.to_s.include?("#{current_language.to_s}-") && t_locale != Locale.code
151
+ localized = @@locales[t_locale][key] || error_msg
152
+ end
153
+ end
154
+ end
155
+ localized = interpolate_string(localized.dup, args.dup) if localized.class == String && localized != error_msg
156
+
157
+ # let's handle pluralization if needed
158
+ # the translation must include pluralize{count, singular string} to be translated
159
+ # the translator can also pass the plural form if needed:
160
+ # pluralize{3, goose, geese}
161
+ localized = localized.gsub( /pluralize\{(.*)\}/){ |erb| pluralize(Regexp.last_match(1)) } if localized.is_a?(String) && (localized=~ /pluralize\{(.*)\}/)
162
+
163
+ # Set the locale back to normal
164
+ #
165
+ unless locale.nil?
166
+ Locale.code = @original_locale
167
+ end
168
+
169
+ return localized
170
+ end
171
+ alias :loc :localize
172
+
173
+ def localize_with_args(key, args={})
174
+ localize(key, '_localization missing_', args)
175
+ end
176
+ alias :l_with_args :localize_with_args
177
+
178
+ def add_reserved_key(*key)
179
+ (@@reserved_keys += key.flatten).uniq!
180
+ end
181
+ alias :add_reserved_keys :add_reserved_key
182
+
183
+ # modified version of the Rails pluralize method from ActionView::Helpers::TextHelper module
184
+ # TODO: load custom inflector based on the language one uses.
185
+ def pluralize(l_string) #count, singular, plural = nil)
186
+ # map the arguments like in the original pluralize method
187
+ count, singular, plural = l_string.split(',').map{ |arg| arg.strip}
188
+
189
+ "#{count} " + if count == 1 || count == '1'
190
+ singular
191
+ elsif plural
192
+ plural
193
+ elsif Object.const_defined?("Inflector")
194
+ Inflector.pluralize(singular)
195
+ else
196
+ singular + "s"
197
+ end
198
+ end
199
+
200
+ def reset_l10n_data
201
+ @@languages = []
202
+ @@countries = []
203
+ @@locales = {}
204
+ @@rails_locales = {}
205
+ @@ui_locales = {}
206
+ end
207
+
208
+ # Loads ALL the UI localization in memory, I might want to refactor this later on.
209
+ # (can be hard on the memory if you load 25 languages with 900 entries each)
210
+ def load_localization!
211
+ reset_l10n_data
212
+
213
+ # Load the rails localization
214
+ if rails_localization_files
215
+ rails_localization_files.each do |file|
216
+ lang = File.basename(file, '.*')[0,2].downcase.to_sym
217
+ # if a country is defined
218
+ if File.basename(file, '.*')[3,5]
219
+ country = File.basename(file, '.*')[3,5].upcase.to_sym
220
+ @@countries << country if ( country != :* && !@@countries.include?(country) )
221
+ if locales.include?("#{lang}-#{country}".to_sym)
222
+ @@locales["#{lang}-#{country}".to_sym].merge(YAML.load_file(file).symbolize_keys)
223
+ else
224
+ @@locales["#{lang}-#{country}".to_sym] = YAML.load_file(file).symbolize_keys
225
+ @@rails_locales[locale_name("#{lang}-#{country}")] = "#{lang}-#{country}".to_sym
226
+ end
227
+ @@languages << lang unless @@languages.include? lang
228
+ else
229
+ @@languages << lang unless @@languages.include? lang
230
+ @f_locale = "#{lang}-*".to_sym
231
+ @@locales[@f_locale] = @@locales[@f_locale].merge(YAML.load_file(file).symbolize_keys) if locales.include?(@f_locale)
232
+ @@locales[@f_locale] = YAML.load_file(file).symbolize_keys unless locales.include?(@f_locale)
233
+ end
234
+ end
235
+ end
236
+ alias :load_translations! :load_localization!
237
+ alias :load_localizations! :load_localization!
238
+
239
+ # Load the UI localization
240
+ if ui_localization_files
241
+ ui_localization_files.each do |file|
242
+ lang = File.basename(file, '.*')[0,2].downcase.to_sym
243
+ if File.basename(file, '.*')[3,5]
244
+ country = File.basename(file, '.*')[3,5].upcase.to_sym
245
+ else
246
+ country = '*'.to_sym
247
+ end
248
+ @@languages << lang unless @@languages.include? lang
249
+ @@countries << country if ( country != :* && !@@countries.include?(country) )
250
+ @file_locale = "#{lang}-#{country}".to_sym
251
+ if locales.include?(@file_locale)
252
+ @@locales[@file_locale] = @@locales[@file_locale].merge(YAML.load_file(file).symbolize_keys)
253
+ @@ui_locales[locale_name("#{lang}-#{country}")] = "#{lang}-#{country}".to_sym
254
+ else
255
+ @@locales[@file_locale] = YAML.load_file(file).symbolize_keys
256
+ @@ui_locales[locale_name("#{lang}-#{country}")] = "#{lang}-#{country}".to_sym
257
+ end
258
+ end
259
+ end
260
+ localize_rails
261
+ # Return the path of the localization files
262
+ return "#{ui_localization_files} | #{rails_localization_files}".to_s
263
+ end
264
+
265
+ def locale_name(locale_code)
266
+ locale_code = locale_code.to_sym
267
+ if locales.include?(locale_code)
268
+ @@locales[locale_code][:locale_name] || nil
269
+ end
270
+ end
271
+
272
+ protected
273
+ # Return the list of UI files used by Globalite
274
+ def ui_localization_files
275
+ loc_files = Dir[File.join(RAILS_ROOT, 'lang/ui/', '*.{yml,yaml}')]
276
+ unless @@localization_sources.empty?
277
+ @@localization_sources.each do |path|
278
+ loc_files += Dir[File.join(path, '*.{yml,yaml}')]
279
+ end
280
+ end
281
+ loc_files
282
+ end
283
+
284
+ # Return a list of the Rails localization files
285
+ def rails_localization_files
286
+ loc_files = Dir[File.join( RAILS_ROOT, '/vendor/plugins/globalite/lang/rails/', '*.{yml,yaml}')]
287
+ end
288
+
289
+ # Interpolate a string using the passed arguments
290
+ def interpolate_string(string, args={})
291
+ if args.length > 0
292
+ args.each do |arg|
293
+ string = string.gsub("{#{arg[0].to_s}}", arg[1].to_s)
294
+ end
295
+ end
296
+ string
297
+ end
298
+
299
+ end
300
+ end