i18n 0.9.5 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +54 -13
  3. data/lib/i18n/backend/base.rb +46 -17
  4. data/lib/i18n/backend/cache.rb +8 -9
  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 +33 -3
  8. data/lib/i18n/backend/fallbacks.rb +11 -13
  9. data/lib/i18n/backend/flatten.rb +2 -0
  10. data/lib/i18n/backend/gettext.rb +4 -0
  11. data/lib/i18n/backend/interpolation_compiler.rb +3 -1
  12. data/lib/i18n/backend/key_value.rb +31 -2
  13. data/lib/i18n/backend/memoize.rb +10 -2
  14. data/lib/i18n/backend/metadata.rb +5 -3
  15. data/lib/i18n/backend/pluralization.rb +2 -0
  16. data/lib/i18n/backend/simple.rb +26 -8
  17. data/lib/i18n/backend/transliterator.rb +2 -0
  18. data/lib/i18n/backend.rb +3 -0
  19. data/lib/i18n/config.rb +20 -2
  20. data/lib/i18n/core_ext/hash.rb +42 -24
  21. data/lib/i18n/exceptions.rb +23 -16
  22. data/lib/i18n/gettext/helpers.rb +3 -1
  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 +5 -3
  26. data/lib/i18n/locale/fallbacks.rb +1 -1
  27. data/lib/i18n/locale.rb +2 -0
  28. data/lib/i18n/middleware.rb +2 -0
  29. data/lib/i18n/tests/interpolation.rb +5 -4
  30. data/lib/i18n/tests/localization/date.rb +28 -6
  31. data/lib/i18n/tests/localization/date_time.rb +27 -6
  32. data/lib/i18n/tests/localization/time.rb +26 -4
  33. data/lib/i18n/tests.rb +2 -0
  34. data/lib/i18n/version.rb +3 -1
  35. data/lib/i18n.rb +72 -30
  36. metadata +24 -58
  37. data/gemfiles/Gemfile.rails-3.2.x +0 -10
  38. data/gemfiles/Gemfile.rails-4.0.x +0 -10
  39. data/gemfiles/Gemfile.rails-4.1.x +0 -10
  40. data/gemfiles/Gemfile.rails-4.2.x +0 -10
  41. data/gemfiles/Gemfile.rails-5.0.x +0 -10
  42. data/gemfiles/Gemfile.rails-5.1.x +0 -10
  43. data/gemfiles/Gemfile.rails-master +0 -10
  44. data/lib/i18n/core_ext/kernel/suppress_warnings.rb +0 -8
  45. data/lib/i18n/core_ext/string/interpolate.rb +0 -9
  46. data/test/api/all_features_test.rb +0 -58
  47. data/test/api/cascade_test.rb +0 -28
  48. data/test/api/chain_test.rb +0 -24
  49. data/test/api/fallbacks_test.rb +0 -30
  50. data/test/api/key_value_test.rb +0 -24
  51. data/test/api/memoize_test.rb +0 -56
  52. data/test/api/override_test.rb +0 -42
  53. data/test/api/pluralization_test.rb +0 -30
  54. data/test/api/simple_test.rb +0 -28
  55. data/test/backend/cache_test.rb +0 -109
  56. data/test/backend/cascade_test.rb +0 -86
  57. data/test/backend/chain_test.rb +0 -122
  58. data/test/backend/exceptions_test.rb +0 -36
  59. data/test/backend/fallbacks_test.rb +0 -219
  60. data/test/backend/interpolation_compiler_test.rb +0 -118
  61. data/test/backend/key_value_test.rb +0 -61
  62. data/test/backend/memoize_test.rb +0 -79
  63. data/test/backend/metadata_test.rb +0 -48
  64. data/test/backend/pluralization_test.rb +0 -45
  65. data/test/backend/simple_test.rb +0 -103
  66. data/test/backend/transliterator_test.rb +0 -84
  67. data/test/core_ext/hash_test.rb +0 -36
  68. data/test/gettext/api_test.rb +0 -214
  69. data/test/gettext/backend_test.rb +0 -92
  70. data/test/i18n/exceptions_test.rb +0 -117
  71. data/test/i18n/gettext_plural_keys_test.rb +0 -20
  72. data/test/i18n/interpolate_test.rb +0 -91
  73. data/test/i18n/load_path_test.rb +0 -34
  74. data/test/i18n/middleware_test.rb +0 -24
  75. data/test/i18n_test.rb +0 -462
  76. data/test/locale/fallbacks_test.rb +0 -133
  77. data/test/locale/tag/rfc4646_test.rb +0 -143
  78. data/test/locale/tag/simple_test.rb +0 -32
  79. data/test/run_all.rb +0 -20
  80. data/test/test_data/locales/de.po +0 -82
  81. data/test/test_data/locales/en.rb +0 -3
  82. data/test/test_data/locales/en.yml +0 -3
  83. data/test/test_data/locales/invalid/empty.yml +0 -0
  84. data/test/test_data/locales/invalid/syntax.yml +0 -4
  85. data/test/test_data/locales/plurals.rb +0 -113
  86. data/test/test_helper.rb +0 -61
data/lib/i18n.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/map'
2
4
 
3
5
  require 'i18n/version'
@@ -12,9 +14,23 @@ module I18n
12
14
  autoload :Tests, 'i18n/tests'
13
15
  autoload :Middleware, 'i18n/middleware'
14
16
 
15
- RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :fallback_in_progress, :format, :cascade, :throw, :raise, :deep_interpolation]
17
+ RESERVED_KEYS = %i[
18
+ cascade
19
+ deep_interpolation
20
+ default
21
+ exception_handler
22
+ fallback
23
+ fallback_in_progress
24
+ format
25
+ object
26
+ raise
27
+ resolve
28
+ scope
29
+ separator
30
+ throw
31
+ ].freeze
16
32
  RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
17
-
33
+ EMPTY_HASH = {}.freeze
18
34
 
19
35
  def self.new_double_nested_cache # :nodoc:
20
36
  Concurrent::Map.new { |h,k| h[k] = Concurrent::Map.new }
@@ -53,6 +69,13 @@ module I18n
53
69
  config.backend.reload!
54
70
  end
55
71
 
72
+ # Tells the backend to load translations now. Used in situations like the
73
+ # Rails production environment. Backends can implement whatever strategy
74
+ # is useful.
75
+ def eager_load!
76
+ config.backend.eager_load!
77
+ end
78
+
56
79
  # Translates, pluralizes and interpolates a given key using a given locale,
57
80
  # scope, and default, as well as interpolation values.
58
81
  #
@@ -153,15 +176,13 @@ module I18n
153
176
  # from the argument values passed to #translate. Therefor your lambdas should
154
177
  # always return the same translations/values per unique combination of argument
155
178
  # 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
-
179
+ def translate(key = nil, *, throw: false, raise: false, locale: nil, **options) # TODO deprecate :raise
180
+ locale ||= config.locale
181
+ raise Disabled.new('t') if locale == false
163
182
  enforce_available_locales!(locale)
164
183
 
184
+ backend = config.backend
185
+
165
186
  result = catch(:exception) do
166
187
  if key.is_a?(Array)
167
188
  key.map { |k| backend.translate(locale, k, options) }
@@ -169,19 +190,26 @@ module I18n
169
190
  backend.translate(locale, key, options)
170
191
  end
171
192
  end
172
- result.is_a?(MissingTranslation) ? handle_exception(handling, result, locale, key, options) : result
193
+
194
+ if result.is_a?(MissingTranslation)
195
+ handle_exception((throw && :throw || raise && :raise), result, locale, key, options)
196
+ else
197
+ result
198
+ end
173
199
  end
174
200
  alias :t :translate
175
201
 
176
202
  # Wrapper for <tt>translate</tt> that adds <tt>:raise => true</tt>. With
177
203
  # this option, if no translation is found, it will raise <tt>I18n::MissingTranslationData</tt>
178
- def translate!(key, options={})
204
+ def translate!(key, options = EMPTY_HASH)
179
205
  translate(key, options.merge(:raise => true))
180
206
  end
181
207
  alias :t! :translate!
182
208
 
183
209
  # Returns true if a translation exists for a given key, otherwise returns false.
184
- def exists?(key, locale = config.locale)
210
+ def exists?(key, _locale = nil, locale: _locale)
211
+ locale ||= config.locale
212
+ raise Disabled.new('exists?') if locale == false
185
213
  raise I18n::ArgumentError if key.is_a?(String) && key.empty?
186
214
  config.backend.exists?(locale, key)
187
215
  end
@@ -237,37 +265,40 @@ module I18n
237
265
  # I18n.transliterate("Jürgen") # => "Juergen"
238
266
  # I18n.transliterate("Jürgen", :locale => :en) # => "Jurgen"
239
267
  # 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)
268
+ def transliterate(key, *, throw: false, raise: false, locale: nil, replacement: nil, **options)
269
+ locale ||= config.locale
270
+ raise Disabled.new('transliterate') if locale == false
246
271
  enforce_available_locales!(locale)
272
+
247
273
  config.backend.transliterate(locale, key, replacement)
248
274
  rescue I18n::ArgumentError => exception
249
- handle_exception(handling, exception, locale, key, options || {})
275
+ handle_exception((throw && :throw || raise && :raise), exception, locale, key, options)
250
276
  end
251
277
 
252
278
  # 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
279
+ def localize(object, locale: nil, format: nil, **options)
280
+ locale ||= config.locale
281
+ raise Disabled.new('l') if locale == false
257
282
  enforce_available_locales!(locale)
283
+
284
+ format ||= :default
258
285
  config.backend.localize(locale, object, format, options)
259
286
  end
260
287
  alias :l :localize
261
288
 
262
289
  # Executes block with given I18n.locale set.
263
290
  def with_locale(tmp_locale = nil)
264
- if tmp_locale
291
+ if tmp_locale == nil
292
+ yield
293
+ else
265
294
  current_locale = self.locale
266
- self.locale = tmp_locale
295
+ self.locale = tmp_locale
296
+ begin
297
+ yield
298
+ ensure
299
+ self.locale = current_locale
300
+ end
267
301
  end
268
- yield
269
- ensure
270
- self.locale = current_locale if tmp_locale
271
302
  end
272
303
 
273
304
  # Merges the given locale, key and scope into a single array of keys.
@@ -291,7 +322,7 @@ module I18n
291
322
 
292
323
  # Raises an InvalidLocale exception when the passed locale is not available.
293
324
  def enforce_available_locales!(locale)
294
- if config.enforce_available_locales
325
+ if locale != false && config.enforce_available_locales
295
326
  raise I18n::InvalidLocale.new(locale) if !locale_available?(locale)
296
327
  end
297
328
  end
@@ -346,7 +377,18 @@ module I18n
346
377
  else
347
378
  keys = key.to_s.split(separator)
348
379
  keys.delete('')
349
- keys.map! { |k| k.to_sym }
380
+ keys.map! do |k|
381
+ case k
382
+ when /\A[-+]?[1-9]\d*\z/ # integer
383
+ k.to_i
384
+ when 'true'
385
+ true
386
+ when 'false'
387
+ false
388
+ else
389
+ k.to_sym
390
+ end
391
+ end
350
392
  keys
351
393
  end
352
394
  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.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2018-02-13 00:00:00.000000000 Z
16
+ date: 2019-03-03 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
@@ -62,8 +56,6 @@ files:
62
56
  - lib/i18n/backend/transliterator.rb
63
57
  - lib/i18n/config.rb
64
58
  - 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
@@ -90,52 +82,27 @@ files:
90
82
  - lib/i18n/tests/pluralization.rb
91
83
  - lib/i18n/tests/procs.rb
92
84
  - 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
85
+ homepage: http://github.com/ruby-i18n/i18n
135
86
  licenses:
136
87
  - MIT
137
- metadata: {}
138
- post_install_message:
88
+ metadata:
89
+ bug_tracker_uri: https://github.com/svenfuchs/i18n/issues
90
+ changelog_uri: https://github.com/svenfuchs/i18n/releases
91
+ documentation_uri: https://guides.rubyonrails.org/i18n.html
92
+ source_code_uri: https://github.com/svenfuchs/i18n
93
+ post_install_message: |2+
94
+
95
+ HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
96
+ But that may break your application.
97
+
98
+ Please check your Rails app for 'config.i18n.fallbacks = true'.
99
+ If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
100
+ 'config.i18n.fallbacks = [I18n.default_locale]'.
101
+ If not, fallbacks will be broken in your app by I18n 1.1.x.
102
+
103
+ For more info see:
104
+ https://github.com/svenfuchs/i18n/releases/tag/v1.1.0
105
+
139
106
  rdoc_options: []
140
107
  require_paths:
141
108
  - lib
@@ -143,15 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
110
  requirements:
144
111
  - - ">="
145
112
  - !ruby/object:Gem::Version
146
- version: 1.9.3
113
+ version: 2.3.0
147
114
  required_rubygems_version: !ruby/object:Gem::Requirement
148
115
  requirements:
149
116
  - - ">="
150
117
  - !ruby/object:Gem::Version
151
118
  version: 1.3.5
152
119
  requirements: []
153
- rubyforge_project: "[none]"
154
- rubygems_version: 2.7.4
120
+ rubygems_version: 3.0.2
155
121
  signing_key:
156
122
  specification_version: 4
157
123
  summary: New wave Internationalization support for Ruby
@@ -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,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
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nFallbacksApiTest < I18n::TestCase
4
- class Backend < I18n::Backend::Simple
5
- include I18n::Backend::Fallbacks
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 Fallbacks included" do
26
- assert_equal Backend, I18n.backend.class
27
- end
28
-
29
- # links: test that keys stored on one backend can link to keys stored on another backend
30
- end
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nKeyValueApiTest < I18n::TestCase
4
- include I18n::Tests::Basics
5
- include I18n::Tests::Defaults
6
- include I18n::Tests::Interpolation
7
- include I18n::Tests::Link
8
- include I18n::Tests::Lookup
9
- include I18n::Tests::Pluralization
10
- # include Tests::Api::Procs
11
- include I18n::Tests::Localization::Date
12
- include I18n::Tests::Localization::DateTime
13
- include I18n::Tests::Localization::Time
14
- # include Tests::Api::Localization::Procs
15
-
16
- def setup
17
- I18n.backend = I18n::Backend::KeyValue.new({})
18
- super
19
- end
20
-
21
- test "make sure we use the KeyValue backend" do
22
- assert_equal I18n::Backend::KeyValue, I18n.backend.class
23
- end
24
- end if I18n::TestCase.key_value?
@@ -1,56 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nMemoizeBackendWithSimpleApiTest < I18n::TestCase
4
- include I18n::Tests::Basics
5
- include I18n::Tests::Defaults
6
- include I18n::Tests::Interpolation
7
- include I18n::Tests::Link
8
- include I18n::Tests::Lookup
9
- include I18n::Tests::Pluralization
10
- include I18n::Tests::Procs
11
- include I18n::Tests::Localization::Date
12
- include I18n::Tests::Localization::DateTime
13
- include I18n::Tests::Localization::Time
14
- include I18n::Tests::Localization::Procs
15
-
16
- class MemoizeBackend < I18n::Backend::Simple
17
- include I18n::Backend::Memoize
18
- end
19
-
20
- def setup
21
- I18n.backend = MemoizeBackend.new
22
- super
23
- end
24
-
25
- test "make sure we use the MemoizeBackend backend" do
26
- assert_equal MemoizeBackend, I18n.backend.class
27
- end
28
- end
29
-
30
- class I18nMemoizeBackendWithKeyValueApiTest < I18n::TestCase
31
- include I18n::Tests::Basics
32
- include I18n::Tests::Defaults
33
- include I18n::Tests::Interpolation
34
- include I18n::Tests::Link
35
- include I18n::Tests::Lookup
36
- include I18n::Tests::Pluralization
37
- include I18n::Tests::Localization::Date
38
- include I18n::Tests::Localization::DateTime
39
- include I18n::Tests::Localization::Time
40
-
41
- # include I18n::Tests::Procs
42
- # include I18n::Tests::Localization::Procs
43
-
44
- class MemoizeBackend < I18n::Backend::KeyValue
45
- include I18n::Backend::Memoize
46
- end
47
-
48
- def setup
49
- I18n.backend = MemoizeBackend.new({})
50
- super
51
- end
52
-
53
- test "make sure we use the MemoizeBackend backend" do
54
- assert_equal MemoizeBackend, I18n.backend.class
55
- end
56
- end if I18n::TestCase.key_value?
@@ -1,42 +0,0 @@
1
- require 'test_helper'
2
-
3
- class I18nOverrideTest < I18n::TestCase
4
- module OverrideInverse
5
- def translate(*args)
6
- super(*args).reverse
7
- end
8
- alias :t :translate
9
- end
10
-
11
- module OverrideSignature
12
- def translate(*args)
13
- args.first + args[1]
14
- end
15
- alias :t :translate
16
- end
17
-
18
- def setup
19
- super
20
- @I18n = I18n.dup
21
- @I18n.backend = I18n::Backend::Simple.new
22
- end
23
-
24
- test "make sure modules can overwrite I18n methods" do
25
- @I18n.extend OverrideInverse
26
- @I18n.backend.store_translations('en', :foo => 'bar')
27
-
28
- assert_equal 'rab', @I18n.translate(:foo, :locale => 'en')
29
- assert_equal 'rab', @I18n.t(:foo, :locale => 'en')
30
- assert_equal 'rab', @I18n.translate!(:foo, :locale => 'en')
31
- assert_equal 'rab', @I18n.t!(:foo, :locale => 'en')
32
- end
33
-
34
- test "make sure modules can overwrite I18n signature" do
35
- exception = catch(:exception) do
36
- @I18n.t('Hello', 'Welcome message on home page', :tokenize => true, :throw => true)
37
- end
38
- assert exception.message
39
- @I18n.extend OverrideSignature
40
- assert_equal 'HelloWelcome message on home page', @I18n.translate('Hello', 'Welcome message on home page', :tokenize => true) # tr8n example
41
- end
42
- end