i18n 0.9.5 → 1.14.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +75 -32
  3. data/lib/i18n/backend/base.rb +83 -32
  4. data/lib/i18n/backend/cache.rb +10 -11
  5. data/lib/i18n/backend/cache_file.rb +36 -0
  6. data/lib/i18n/backend/cascade.rb +3 -1
  7. data/lib/i18n/backend/chain.rb +39 -6
  8. data/lib/i18n/backend/fallbacks.rb +44 -15
  9. data/lib/i18n/backend/flatten.rb +10 -5
  10. data/lib/i18n/backend/gettext.rb +4 -2
  11. data/lib/i18n/backend/interpolation_compiler.rb +8 -8
  12. data/lib/i18n/backend/key_value.rb +31 -4
  13. data/lib/i18n/backend/lazy_loadable.rb +184 -0
  14. data/lib/i18n/backend/memoize.rb +10 -2
  15. data/lib/i18n/backend/metadata.rb +5 -3
  16. data/lib/i18n/backend/pluralization.rb +61 -18
  17. data/lib/i18n/backend/simple.rb +36 -16
  18. data/lib/i18n/backend/transliterator.rb +26 -24
  19. data/lib/i18n/backend.rb +5 -1
  20. data/lib/i18n/config.rb +22 -4
  21. data/lib/i18n/exceptions.rb +71 -18
  22. data/lib/i18n/gettext/helpers.rb +4 -2
  23. data/lib/i18n/gettext/po_parser.rb +7 -7
  24. data/lib/i18n/gettext.rb +2 -0
  25. data/lib/i18n/interpolate/ruby.rb +22 -6
  26. data/lib/i18n/locale/fallbacks.rb +29 -20
  27. data/lib/i18n/locale/tag/parents.rb +8 -6
  28. data/lib/i18n/locale/tag/simple.rb +2 -2
  29. data/lib/i18n/locale.rb +2 -0
  30. data/lib/i18n/middleware.rb +2 -0
  31. data/lib/i18n/tests/basics.rb +5 -7
  32. data/lib/i18n/tests/defaults.rb +1 -1
  33. data/lib/i18n/tests/interpolation.rb +16 -7
  34. data/lib/i18n/tests/link.rb +11 -1
  35. data/lib/i18n/tests/localization/date.rb +37 -10
  36. data/lib/i18n/tests/localization/date_time.rb +28 -7
  37. data/lib/i18n/tests/localization/procs.rb +7 -5
  38. data/lib/i18n/tests/localization/time.rb +27 -5
  39. data/lib/i18n/tests/lookup.rb +5 -5
  40. data/lib/i18n/tests/pluralization.rb +1 -1
  41. data/lib/i18n/tests/procs.rb +12 -1
  42. data/lib/i18n/tests.rb +2 -0
  43. data/lib/i18n/utils.rb +55 -0
  44. data/lib/i18n/version.rb +3 -1
  45. data/lib/i18n.rb +134 -55
  46. metadata +16 -61
  47. data/gemfiles/Gemfile.rails-3.2.x +0 -10
  48. data/gemfiles/Gemfile.rails-4.0.x +0 -10
  49. data/gemfiles/Gemfile.rails-4.1.x +0 -10
  50. data/gemfiles/Gemfile.rails-4.2.x +0 -10
  51. data/gemfiles/Gemfile.rails-5.0.x +0 -10
  52. data/gemfiles/Gemfile.rails-5.1.x +0 -10
  53. data/gemfiles/Gemfile.rails-master +0 -10
  54. data/lib/i18n/core_ext/hash.rb +0 -29
  55. data/lib/i18n/core_ext/kernel/suppress_warnings.rb +0 -8
  56. data/lib/i18n/core_ext/string/interpolate.rb +0 -9
  57. data/test/api/all_features_test.rb +0 -58
  58. data/test/api/cascade_test.rb +0 -28
  59. data/test/api/chain_test.rb +0 -24
  60. data/test/api/fallbacks_test.rb +0 -30
  61. data/test/api/key_value_test.rb +0 -24
  62. data/test/api/memoize_test.rb +0 -56
  63. data/test/api/override_test.rb +0 -42
  64. data/test/api/pluralization_test.rb +0 -30
  65. data/test/api/simple_test.rb +0 -28
  66. data/test/backend/cache_test.rb +0 -109
  67. data/test/backend/cascade_test.rb +0 -86
  68. data/test/backend/chain_test.rb +0 -122
  69. data/test/backend/exceptions_test.rb +0 -36
  70. data/test/backend/fallbacks_test.rb +0 -219
  71. data/test/backend/interpolation_compiler_test.rb +0 -118
  72. data/test/backend/key_value_test.rb +0 -61
  73. data/test/backend/memoize_test.rb +0 -79
  74. data/test/backend/metadata_test.rb +0 -48
  75. data/test/backend/pluralization_test.rb +0 -45
  76. data/test/backend/simple_test.rb +0 -103
  77. data/test/backend/transliterator_test.rb +0 -84
  78. data/test/core_ext/hash_test.rb +0 -36
  79. data/test/gettext/api_test.rb +0 -214
  80. data/test/gettext/backend_test.rb +0 -92
  81. data/test/i18n/exceptions_test.rb +0 -117
  82. data/test/i18n/gettext_plural_keys_test.rb +0 -20
  83. data/test/i18n/interpolate_test.rb +0 -91
  84. data/test/i18n/load_path_test.rb +0 -34
  85. data/test/i18n/middleware_test.rb +0 -24
  86. data/test/i18n_test.rb +0 -462
  87. data/test/locale/fallbacks_test.rb +0 -133
  88. data/test/locale/tag/rfc4646_test.rb +0 -143
  89. data/test/locale/tag/simple_test.rb +0 -32
  90. data/test/run_all.rb +0 -20
  91. data/test/test_data/locales/de.po +0 -82
  92. data/test/test_data/locales/en.rb +0 -3
  93. data/test/test_data/locales/en.yml +0 -3
  94. data/test/test_data/locales/invalid/empty.yml +0 -0
  95. data/test/test_data/locales/invalid/syntax.yml +0 -4
  96. data/test/test_data/locales/plurals.rb +0 -113
  97. data/test/test_helper.rb +0 -61
data/lib/i18n.rb CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/map'
4
+ require 'concurrent/hash'
2
5
 
3
6
  require 'i18n/version'
7
+ require 'i18n/utils'
4
8
  require 'i18n/exceptions'
5
9
  require 'i18n/interpolate/ruby'
6
10
 
@@ -12,12 +16,39 @@ module I18n
12
16
  autoload :Tests, 'i18n/tests'
13
17
  autoload :Middleware, 'i18n/middleware'
14
18
 
15
- RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :fallback_in_progress, :format, :cascade, :throw, :raise, :deep_interpolation]
16
- RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
17
-
19
+ RESERVED_KEYS = %i[
20
+ cascade
21
+ deep_interpolation
22
+ default
23
+ exception_handler
24
+ fallback
25
+ fallback_in_progress
26
+ fallback_original_locale
27
+ format
28
+ object
29
+ raise
30
+ resolve
31
+ scope
32
+ separator
33
+ throw
34
+ ]
35
+ EMPTY_HASH = {}.freeze
18
36
 
19
37
  def self.new_double_nested_cache # :nodoc:
20
- Concurrent::Map.new { |h,k| h[k] = Concurrent::Map.new }
38
+ Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new }
39
+ end
40
+
41
+ # Marks a key as reserved. Reserved keys are used internally,
42
+ # and can't also be used for interpolation. If you are using any
43
+ # extra keys as I18n options, you should call I18n.reserve_key
44
+ # before any I18n.translate (etc) calls are made.
45
+ def self.reserve_key(key)
46
+ RESERVED_KEYS << key.to_sym
47
+ @reserved_keys_pattern = nil
48
+ end
49
+
50
+ def self.reserved_keys_pattern # :nodoc:
51
+ @reserved_keys_pattern ||= /%\{(#{RESERVED_KEYS.join("|")})\}/
21
52
  end
22
53
 
23
54
  module Base
@@ -53,6 +84,13 @@ module I18n
53
84
  config.backend.reload!
54
85
  end
55
86
 
87
+ # Tells the backend to load translations now. Used in situations like the
88
+ # Rails production environment. Backends can implement whatever strategy
89
+ # is useful.
90
+ def eager_load!
91
+ config.backend.eager_load!
92
+ end
93
+
56
94
  # Translates, pluralizes and interpolates a given key using a given locale,
57
95
  # scope, and default, as well as interpolation values.
58
96
  #
@@ -92,7 +130,7 @@ module I18n
92
130
  # *PLURALIZATION*
93
131
  #
94
132
  # Translation data can contain pluralized translations. Pluralized translations
95
- # are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
133
+ # are arrays of singular/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
96
134
  #
97
135
  # Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
98
136
  # pluralization rules. Other algorithms can be supported by custom backends.
@@ -150,40 +188,55 @@ module I18n
150
188
  #
151
189
  # It is recommended to use/implement lambdas in an "idempotent" way. E.g. when
152
190
  # a cache layer is put in front of I18n.translate it will generate a cache key
153
- # from the argument values passed to #translate. Therefor your lambdas should
191
+ # from the argument values passed to #translate. Therefore your lambdas should
154
192
  # always return the same translations/values per unique combination of argument
155
193
  # values.
156
- def translate(*args)
157
- options = args.last.is_a?(Hash) ? args.pop.dup : {}
158
- key = args.shift
159
- backend = config.backend
160
- locale = options.delete(:locale) || config.locale
161
- handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise
162
-
194
+ #
195
+ # *Ruby 2.7+ keyword arguments warning*
196
+ #
197
+ # This method uses keyword arguments.
198
+ # There is a breaking change in ruby that produces warning with ruby 2.7 and won't work as expected with ruby 3.0
199
+ # The "hash" parameter must be passed as keyword argument.
200
+ #
201
+ # Good:
202
+ # I18n.t(:salutation, :gender => 'w', :name => 'Smith')
203
+ # I18n.t(:salutation, **{ :gender => 'w', :name => 'Smith' })
204
+ # I18n.t(:salutation, **any_hash)
205
+ #
206
+ # Bad:
207
+ # I18n.t(:salutation, { :gender => 'w', :name => 'Smith' })
208
+ # I18n.t(:salutation, any_hash)
209
+ #
210
+ def translate(key = nil, throw: false, raise: false, locale: nil, **options) # TODO deprecate :raise
211
+ locale ||= config.locale
212
+ raise Disabled.new('t') if locale == false
163
213
  enforce_available_locales!(locale)
164
214
 
165
- result = catch(:exception) do
166
- if key.is_a?(Array)
167
- key.map { |k| backend.translate(locale, k, options) }
168
- else
169
- backend.translate(locale, key, options)
215
+ backend = config.backend
216
+
217
+ if key.is_a?(Array)
218
+ key.map do |k|
219
+ translate_key(k, throw, raise, locale, backend, options)
170
220
  end
221
+ else
222
+ translate_key(key, throw, raise, locale, backend, options)
171
223
  end
172
- result.is_a?(MissingTranslation) ? handle_exception(handling, result, locale, key, options) : result
173
224
  end
174
225
  alias :t :translate
175
226
 
176
227
  # Wrapper for <tt>translate</tt> that adds <tt>:raise => true</tt>. With
177
228
  # this option, if no translation is found, it will raise <tt>I18n::MissingTranslationData</tt>
178
- def translate!(key, options={})
179
- translate(key, options.merge(:raise => true))
229
+ def translate!(key, **options)
230
+ translate(key, **options, raise: true)
180
231
  end
181
232
  alias :t! :translate!
182
233
 
183
234
  # Returns true if a translation exists for a given key, otherwise returns false.
184
- def exists?(key, locale = config.locale)
235
+ def exists?(key, _locale = nil, locale: _locale, **options)
236
+ locale ||= config.locale
237
+ raise Disabled.new('exists?') if locale == false
185
238
  raise I18n::ArgumentError if key.is_a?(String) && key.empty?
186
- config.backend.exists?(locale, key)
239
+ config.backend.exists?(locale, key, options)
187
240
  end
188
241
 
189
242
  # Transliterates UTF-8 characters to ASCII. By default this method will
@@ -215,14 +268,14 @@ module I18n
215
268
  #
216
269
  # Setting a Hash using Ruby:
217
270
  #
218
- # store_translations(:de, :i18n => {
219
- # :transliterate => {
220
- # :rule => {
221
- # "ü" => "ue",
222
- # "ö" => "oe"
223
- # }
224
- # }
225
- # )
271
+ # store_translations(:de, i18n: {
272
+ # transliterate: {
273
+ # rule: {
274
+ # 'ü' => 'ue',
275
+ # 'ö' => 'oe'
276
+ # }
277
+ # }
278
+ # })
226
279
  #
227
280
  # Setting a Proc:
228
281
  #
@@ -237,37 +290,40 @@ module I18n
237
290
  # I18n.transliterate("Jürgen") # => "Juergen"
238
291
  # I18n.transliterate("Jürgen", :locale => :en) # => "Jurgen"
239
292
  # I18n.transliterate("Jürgen", :locale => :de) # => "Juergen"
240
- def transliterate(*args)
241
- options = args.pop.dup if args.last.is_a?(Hash)
242
- key = args.shift
243
- locale = options && options.delete(:locale) || config.locale
244
- handling = options && (options.delete(:throw) && :throw || options.delete(:raise) && :raise)
245
- replacement = options && options.delete(:replacement)
293
+ def transliterate(key, throw: false, raise: false, locale: nil, replacement: nil, **options)
294
+ locale ||= config.locale
295
+ raise Disabled.new('transliterate') if locale == false
246
296
  enforce_available_locales!(locale)
297
+
247
298
  config.backend.transliterate(locale, key, replacement)
248
299
  rescue I18n::ArgumentError => exception
249
- handle_exception(handling, exception, locale, key, options || {})
300
+ handle_exception((throw && :throw || raise && :raise), exception, locale, key, options)
250
301
  end
251
302
 
252
303
  # Localizes certain objects, such as dates and numbers to local formatting.
253
- def localize(object, options = nil)
254
- options = options ? options.dup : {}
255
- locale = options.delete(:locale) || config.locale
256
- format = options.delete(:format) || :default
304
+ def localize(object, locale: nil, format: nil, **options)
305
+ locale ||= config.locale
306
+ raise Disabled.new('l') if locale == false
257
307
  enforce_available_locales!(locale)
308
+
309
+ format ||= :default
258
310
  config.backend.localize(locale, object, format, options)
259
311
  end
260
312
  alias :l :localize
261
313
 
262
314
  # Executes block with given I18n.locale set.
263
315
  def with_locale(tmp_locale = nil)
264
- if tmp_locale
316
+ if tmp_locale == nil
317
+ yield
318
+ else
265
319
  current_locale = self.locale
266
- self.locale = tmp_locale
320
+ self.locale = tmp_locale
321
+ begin
322
+ yield
323
+ ensure
324
+ self.locale = current_locale
325
+ end
267
326
  end
268
- yield
269
- ensure
270
- self.locale = current_locale if tmp_locale
271
327
  end
272
328
 
273
329
  # Merges the given locale, key and scope into a single array of keys.
@@ -276,11 +332,11 @@ module I18n
276
332
  def normalize_keys(locale, key, scope, separator = nil)
277
333
  separator ||= I18n.default_separator
278
334
 
279
- keys = []
280
- keys.concat normalize_key(locale, separator)
281
- keys.concat normalize_key(scope, separator)
282
- keys.concat normalize_key(key, separator)
283
- keys
335
+ [
336
+ *normalize_key(locale, separator),
337
+ *normalize_key(scope, separator),
338
+ *normalize_key(key, separator)
339
+ ]
284
340
  end
285
341
 
286
342
  # Returns true when the passed locale, which can be either a String or a
@@ -291,7 +347,7 @@ module I18n
291
347
 
292
348
  # Raises an InvalidLocale exception when the passed locale is not available.
293
349
  def enforce_available_locales!(locale)
294
- if config.enforce_available_locales
350
+ if locale != false && config.enforce_available_locales
295
351
  raise I18n::InvalidLocale.new(locale) if !locale_available?(locale)
296
352
  end
297
353
  end
@@ -302,6 +358,18 @@ module I18n
302
358
 
303
359
  private
304
360
 
361
+ def translate_key(key, throw, raise, locale, backend, options)
362
+ result = catch(:exception) do
363
+ backend.translate(locale, key, options)
364
+ end
365
+
366
+ if result.is_a?(MissingTranslation)
367
+ handle_exception((throw && :throw || raise && :raise), result, locale, key, options)
368
+ else
369
+ result
370
+ end
371
+ end
372
+
305
373
  # Any exceptions thrown in translate will be sent to the @@exception_handler
306
374
  # which can be a Symbol, a Proc or any other Object unless they're forced to
307
375
  # be raised or thrown (MissingTranslation).
@@ -342,11 +410,22 @@ module I18n
342
410
  @@normalized_key_cache[separator][key] ||=
343
411
  case key
344
412
  when Array
345
- key.map { |k| normalize_key(k, separator) }.flatten
413
+ key.flat_map { |k| normalize_key(k, separator) }
346
414
  else
347
415
  keys = key.to_s.split(separator)
348
416
  keys.delete('')
349
- keys.map! { |k| k.to_sym }
417
+ keys.map! do |k|
418
+ case k
419
+ when /\A[-+]?([1-9]\d*|0)\z/ # integer
420
+ k.to_i
421
+ when 'true'
422
+ true
423
+ when 'false'
424
+ false
425
+ else
426
+ k.to_sym
427
+ end
428
+ end
350
429
  keys
351
430
  end
352
431
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 1.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -10,10 +10,10 @@ authors:
10
10
  - Stephan Soller
11
11
  - Saimon Moore
12
12
  - Ryan Bigg
13
- autorequire:
13
+ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2018-02-13 00:00:00.000000000 Z
16
+ date: 2024-03-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: concurrent-ruby
@@ -37,17 +37,11 @@ extra_rdoc_files: []
37
37
  files:
38
38
  - MIT-LICENSE
39
39
  - README.md
40
- - gemfiles/Gemfile.rails-3.2.x
41
- - gemfiles/Gemfile.rails-4.0.x
42
- - gemfiles/Gemfile.rails-4.1.x
43
- - gemfiles/Gemfile.rails-4.2.x
44
- - gemfiles/Gemfile.rails-5.0.x
45
- - gemfiles/Gemfile.rails-5.1.x
46
- - gemfiles/Gemfile.rails-master
47
40
  - lib/i18n.rb
48
41
  - lib/i18n/backend.rb
49
42
  - lib/i18n/backend/base.rb
50
43
  - lib/i18n/backend/cache.rb
44
+ - lib/i18n/backend/cache_file.rb
51
45
  - lib/i18n/backend/cascade.rb
52
46
  - lib/i18n/backend/chain.rb
53
47
  - lib/i18n/backend/fallbacks.rb
@@ -55,15 +49,13 @@ files:
55
49
  - lib/i18n/backend/gettext.rb
56
50
  - lib/i18n/backend/interpolation_compiler.rb
57
51
  - lib/i18n/backend/key_value.rb
52
+ - lib/i18n/backend/lazy_loadable.rb
58
53
  - lib/i18n/backend/memoize.rb
59
54
  - lib/i18n/backend/metadata.rb
60
55
  - lib/i18n/backend/pluralization.rb
61
56
  - lib/i18n/backend/simple.rb
62
57
  - lib/i18n/backend/transliterator.rb
63
58
  - lib/i18n/config.rb
64
- - lib/i18n/core_ext/hash.rb
65
- - lib/i18n/core_ext/kernel/suppress_warnings.rb
66
- - lib/i18n/core_ext/string/interpolate.rb
67
59
  - lib/i18n/exceptions.rb
68
60
  - lib/i18n/gettext.rb
69
61
  - lib/i18n/gettext/helpers.rb
@@ -89,53 +81,17 @@ files:
89
81
  - lib/i18n/tests/lookup.rb
90
82
  - lib/i18n/tests/pluralization.rb
91
83
  - lib/i18n/tests/procs.rb
84
+ - lib/i18n/utils.rb
92
85
  - lib/i18n/version.rb
93
- - test/api/all_features_test.rb
94
- - test/api/cascade_test.rb
95
- - test/api/chain_test.rb
96
- - test/api/fallbacks_test.rb
97
- - test/api/key_value_test.rb
98
- - test/api/memoize_test.rb
99
- - test/api/override_test.rb
100
- - test/api/pluralization_test.rb
101
- - test/api/simple_test.rb
102
- - test/backend/cache_test.rb
103
- - test/backend/cascade_test.rb
104
- - test/backend/chain_test.rb
105
- - test/backend/exceptions_test.rb
106
- - test/backend/fallbacks_test.rb
107
- - test/backend/interpolation_compiler_test.rb
108
- - test/backend/key_value_test.rb
109
- - test/backend/memoize_test.rb
110
- - test/backend/metadata_test.rb
111
- - test/backend/pluralization_test.rb
112
- - test/backend/simple_test.rb
113
- - test/backend/transliterator_test.rb
114
- - test/core_ext/hash_test.rb
115
- - test/gettext/api_test.rb
116
- - test/gettext/backend_test.rb
117
- - test/i18n/exceptions_test.rb
118
- - test/i18n/gettext_plural_keys_test.rb
119
- - test/i18n/interpolate_test.rb
120
- - test/i18n/load_path_test.rb
121
- - test/i18n/middleware_test.rb
122
- - test/i18n_test.rb
123
- - test/locale/fallbacks_test.rb
124
- - test/locale/tag/rfc4646_test.rb
125
- - test/locale/tag/simple_test.rb
126
- - test/run_all.rb
127
- - test/test_data/locales/de.po
128
- - test/test_data/locales/en.rb
129
- - test/test_data/locales/en.yml
130
- - test/test_data/locales/invalid/empty.yml
131
- - test/test_data/locales/invalid/syntax.yml
132
- - test/test_data/locales/plurals.rb
133
- - test/test_helper.rb
134
- homepage: http://github.com/svenfuchs/i18n
86
+ homepage: https://github.com/ruby-i18n/i18n
135
87
  licenses:
136
88
  - MIT
137
- metadata: {}
138
- post_install_message:
89
+ metadata:
90
+ bug_tracker_uri: https://github.com/ruby-i18n/i18n/issues
91
+ changelog_uri: https://github.com/ruby-i18n/i18n/releases
92
+ documentation_uri: https://guides.rubyonrails.org/i18n.html
93
+ source_code_uri: https://github.com/ruby-i18n/i18n
94
+ post_install_message:
139
95
  rdoc_options: []
140
96
  require_paths:
141
97
  - lib
@@ -143,16 +99,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
99
  requirements:
144
100
  - - ">="
145
101
  - !ruby/object:Gem::Version
146
- version: 1.9.3
102
+ version: 2.3.0
147
103
  required_rubygems_version: !ruby/object:Gem::Requirement
148
104
  requirements:
149
105
  - - ">="
150
106
  - !ruby/object:Gem::Version
151
107
  version: 1.3.5
152
108
  requirements: []
153
- rubyforge_project: "[none]"
154
- rubygems_version: 2.7.4
155
- signing_key:
109
+ rubygems_version: 3.5.1
110
+ signing_key:
156
111
  specification_version: 4
157
112
  summary: New wave Internationalization support for Ruby
158
113
  test_files: []
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '..'
4
-
5
- gem 'activesupport', '~> 3.2.0'
6
- gem 'mocha'
7
- gem 'test_declarative'
8
- gem 'rake'
9
- gem 'minitest'
10
- gem 'oj'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '..'
4
-
5
- gem 'activesupport', '~> 4.0.0'
6
- gem 'mocha'
7
- gem 'test_declarative'
8
- gem 'rake'
9
- gem 'minitest'
10
- gem 'oj'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '..'
4
-
5
- gem 'activesupport', '~> 4.1.0'
6
- gem 'mocha'
7
- gem 'test_declarative'
8
- gem 'rake'
9
- gem 'minitest'
10
- gem 'oj'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '..'
4
-
5
- gem 'activesupport', '~> 4.2.0'
6
- gem 'mocha'
7
- gem 'test_declarative'
8
- gem 'rake'
9
- gem 'minitest'
10
- gem 'oj'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '..'
4
-
5
- gem 'activesupport', '~> 5.0.0'
6
- gem 'mocha'
7
- gem 'test_declarative'
8
- gem 'rake'
9
- gem 'minitest'
10
- gem 'oj'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '..'
4
-
5
- gem 'activesupport', '~> 5.1.0'
6
- gem 'mocha'
7
- gem 'test_declarative'
8
- gem 'rake'
9
- gem 'minitest'
10
- gem 'oj'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :path => '..'
4
-
5
- gem 'activesupport', github: 'rails/rails', branch: 'master'
6
- gem 'mocha'
7
- gem 'test_declarative'
8
- gem 'rake'
9
- gem 'minitest'
10
- gem 'oj'
@@ -1,29 +0,0 @@
1
- class Hash
2
- def slice(*keep_keys)
3
- h = {}
4
- keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
5
- h
6
- end unless Hash.method_defined?(:slice)
7
-
8
- def except(*less_keys)
9
- slice(*keys - less_keys)
10
- end unless Hash.method_defined?(:except)
11
-
12
- def deep_symbolize_keys
13
- inject({}) { |result, (key, value)|
14
- value = value.deep_symbolize_keys if value.is_a?(Hash)
15
- result[(key.to_sym rescue key) || key] = value
16
- result
17
- }
18
- end unless Hash.method_defined?(:deep_symbolize_keys)
19
-
20
- # deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
21
- MERGER = proc do |key, v1, v2|
22
- Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2
23
- end
24
-
25
- def deep_merge!(data)
26
- merge!(data, &MERGER)
27
- end unless Hash.method_defined?(:deep_merge!)
28
- end
29
-
@@ -1,8 +0,0 @@
1
- module Kernel
2
- def suppress_warnings
3
- original_verbosity, $VERBOSE = $VERBOSE, nil
4
- yield
5
- ensure
6
- $VERBOSE = original_verbosity
7
- end
8
- end
@@ -1,9 +0,0 @@
1
- # This file used to backport the Ruby 1.9 String interpolation syntax to Ruby 1.8.
2
- #
3
- # Since I18n has dropped support to Ruby 1.8, this file is not required anymore,
4
- # however, Rails 3.2 still requires it directly:
5
- #
6
- # https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/core_ext/string/interpolation.rb#L2
7
- #
8
- # So we can't just drop the file entirely, which would then break Rails users
9
- # under Ruby 1.9. This file can be removed once Rails 3.2 support is dropped.
@@ -1,58 +0,0 @@
1
- require 'test_helper'
2
-
3
- begin
4
- require 'rubygems'
5
- require 'active_support'
6
- rescue LoadError
7
- puts "not testing with Cache enabled because active_support can not be found"
8
- end
9
-
10
- class I18nAllFeaturesApiTest < I18n::TestCase
11
- class Backend < I18n::Backend::Simple
12
- include I18n::Backend::Metadata
13
- include I18n::Backend::Cache
14
- include I18n::Backend::Cascade
15
- include I18n::Backend::Fallbacks
16
- include I18n::Backend::Pluralization
17
- include I18n::Backend::Memoize
18
- end
19
-
20
- def setup
21
- I18n.backend = I18n::Backend::Chain.new(Backend.new, I18n::Backend::Simple.new)
22
- I18n.cache_store = cache_store
23
- super
24
- end
25
-
26
- def teardown
27
- I18n.cache_store.clear if I18n.cache_store
28
- I18n.cache_store = nil
29
- super
30
- end
31
-
32
- def cache_store
33
- ActiveSupport::Cache.lookup_store(:memory_store) if cache_available?
34
- end
35
-
36
- def cache_available?
37
- defined?(ActiveSupport) && defined?(ActiveSupport::Cache)
38
- end
39
-
40
- include I18n::Tests::Basics
41
- include I18n::Tests::Defaults
42
- include I18n::Tests::Interpolation
43
- include I18n::Tests::Link
44
- include I18n::Tests::Lookup
45
- include I18n::Tests::Pluralization
46
- include I18n::Tests::Procs
47
- include I18n::Tests::Localization::Date
48
- include I18n::Tests::Localization::DateTime
49
- include I18n::Tests::Localization::Time
50
- include I18n::Tests::Localization::Procs
51
-
52
- test "make sure we use a Chain backend with an all features backend" do
53
- assert_equal I18n::Backend::Chain, I18n.backend.class
54
- assert_equal Backend, I18n.backend.backends.first.class
55
- end
56
-
57
- # links: test that keys stored on one backend can link to keys stored on another backend
58
- end
@@ -1,28 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nCascadeApiTest < I18n::TestCase
4
- class Backend < I18n::Backend::Simple
5
- include I18n::Backend::Cascade
6
- end
7
-
8
- def setup
9
- I18n.backend = Backend.new
10
- super
11
- end
12
-
13
- include I18n::Tests::Basics
14
- include I18n::Tests::Defaults
15
- include I18n::Tests::Interpolation
16
- include I18n::Tests::Link
17
- include I18n::Tests::Lookup
18
- include I18n::Tests::Pluralization
19
- include I18n::Tests::Procs
20
- include I18n::Tests::Localization::Date
21
- include I18n::Tests::Localization::DateTime
22
- include I18n::Tests::Localization::Time
23
- include I18n::Tests::Localization::Procs
24
-
25
- test "make sure we use a backend with Cascade included" do
26
- assert_equal Backend, I18n.backend.class
27
- end
28
- end
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nApiChainTest < I18n::TestCase
4
- def setup
5
- super
6
- I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
7
- end
8
-
9
- include I18n::Tests::Basics
10
- include I18n::Tests::Defaults
11
- include I18n::Tests::Interpolation
12
- include I18n::Tests::Link
13
- include I18n::Tests::Lookup
14
- include I18n::Tests::Pluralization
15
- include I18n::Tests::Procs
16
- include I18n::Tests::Localization::Date
17
- include I18n::Tests::Localization::DateTime
18
- include I18n::Tests::Localization::Time
19
- include I18n::Tests::Localization::Procs
20
-
21
- test "make sure we use the Chain backend" do
22
- assert_equal I18n::Backend::Chain, I18n.backend.class
23
- end
24
- end