i18n 0.6.11 → 0.7.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of i18n might be problematic. Click here for more details.

Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +3 -26
  3. data/gemfiles/Gemfile.rails-3.2.x +0 -2
  4. data/gemfiles/Gemfile.rails-3.2.x.lock +5 -9
  5. data/gemfiles/Gemfile.rails-4.0.x +0 -2
  6. data/gemfiles/Gemfile.rails-4.0.x.lock +7 -11
  7. data/gemfiles/Gemfile.rails-4.1.x +0 -2
  8. data/gemfiles/Gemfile.rails-4.1.x.lock +7 -11
  9. data/gemfiles/{Gemfile.rails-3.1.x → Gemfile.rails-master} +1 -3
  10. data/gemfiles/Gemfile.rails-master.lock +40 -0
  11. data/lib/i18n.rb +7 -30
  12. data/lib/i18n/backend/base.rb +0 -1
  13. data/lib/i18n/backend/interpolation_compiler.rb +1 -1
  14. data/lib/i18n/backend/key_value.rb +0 -1
  15. data/lib/i18n/config.rb +16 -6
  16. data/lib/i18n/exceptions.rb +4 -28
  17. data/lib/i18n/version.rb +1 -1
  18. data/test/api/key_value_test.rb +2 -6
  19. data/test/api/memoize_test.rb +2 -6
  20. data/test/api/override_test.rb +2 -3
  21. data/test/backend/cache_test.rb +1 -0
  22. data/test/backend/cascade_test.rb +1 -0
  23. data/test/backend/chain_test.rb +1 -0
  24. data/test/backend/exceptions_test.rb +1 -0
  25. data/test/backend/fallbacks_test.rb +8 -2
  26. data/test/backend/key_value_test.rb +2 -5
  27. data/test/backend/memoize_test.rb +2 -2
  28. data/test/backend/metadata_test.rb +1 -0
  29. data/test/backend/pluralization_test.rb +1 -0
  30. data/test/backend/simple_test.rb +2 -1
  31. data/test/backend/transliterator_test.rb +4 -5
  32. data/test/gettext/api_test.rb +1 -0
  33. data/test/gettext/backend_test.rb +73 -82
  34. data/test/i18n/exceptions_test.rb +0 -15
  35. data/test/i18n/interpolate_test.rb +2 -1
  36. data/test/i18n/load_path_test.rb +1 -0
  37. data/test/i18n_test.rb +35 -0
  38. data/test/locale/fallbacks_test.rb +1 -4
  39. data/test/locale/tag/rfc4646_test.rb +1 -0
  40. data/test/run_all.rb +1 -1
  41. data/test/test_helper.rb +20 -41
  42. metadata +19 -28
  43. data/gemfiles/Gemfile.rails-2.3.x +0 -11
  44. data/gemfiles/Gemfile.rails-2.3.x.lock +0 -30
  45. data/gemfiles/Gemfile.rails-3.0.x +0 -11
  46. data/gemfiles/Gemfile.rails-3.0.x.lock +0 -30
  47. data/gemfiles/Gemfile.rails-3.1.x.lock +0 -30
  48. data/lib/i18n/core_ext/string/interpolate.rb +0 -105
  49. data/test/all.rb +0 -8
  50. data/test/core_ext/string/interpolate_test.rb +0 -99
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8187a8b397f09fc92f74aab28add40becb5c0bf
4
+ data.tar.gz: 2c51a444a3b6919d4f407444cfa920500efc0dff
5
+ SHA512:
6
+ metadata.gz: 89409a78b2822b57ac485a0479017c5b725d28b22f1143f1b579f6b41a82b1f11e94e92509faaf8489e4c43ec7e2f4306cd9613767e895bfecba444637582318
7
+ data.tar.gz: bc606a452a926441015813ee126218249e862ab414388de14f8b9d263838214058c0fdc010c1837fdcbd6f24f80e6960c6925ab083565887e4468b750683627d
data/README.md CHANGED
@@ -35,39 +35,16 @@ For more information and lots of resources see: [http://ruby-i18n.org/wiki](http
35
35
 
36
36
  ## Installation
37
37
 
38
- gem install i18n
39
-
40
- #### Rails version warning
41
-
42
- On Rails < 2.3.6 the method I18n.localize will fail with MissingInterpolationArgument (issue [20](http://github.com/svenfuchs/i18n/issues/issue/20). Upgrade to Rails 2.3.6 or higher (2.3.8 preferably) is recommended.
43
-
44
- ### Installation on Rails < 2.3.5 (deprecated)
45
-
46
- Up to version 2.3.4 Rails will not accept i18n gems > 0.1.3. There is an unpacked
47
- gem inside of active_support/lib/vendor which gets loaded unless `gem 'i18n', '~> 0.1.3'`.
48
- This requirement is relaxed in [6da03653](http://github.com/rails/rails/commit/6da03653)
49
-
50
- The new i18n gem can be loaded from vendor/plugins like this:
51
-
52
38
  ```
53
- def reload_i18n!
54
- raise "Move to i18n version 0.2.0 or greater" if Rails.version > "2.3.4"
55
-
56
- $:.grep(/i18n/).each { |path| $:.delete(path) }
57
- I18n::Backend.send :remove_const, "Simple"
58
- $: << Rails.root.join('vendor', 'plugins', 'i18n', 'lib').to_s
59
- end
39
+ gem install i18n
60
40
  ```
61
41
 
62
- Then you can `reload_i18n!` inside an i18n initializer.
63
-
64
42
  ## Tests
65
43
 
66
44
  You can run tests both with
67
45
 
68
46
  * `rake test` or just `rake`
69
- * run any test file directly, e.g. `ruby -Ilib -Itest test/api/simple_test.rb`
70
- * run all tests with `ruby -Ilib -Itest test/all.rb`
47
+ * run any test file directly, e.g. `ruby -Ilib:test test/api/simple_test.rb`
71
48
 
72
49
  You can run all tests against all Gemfiles with
73
50
 
@@ -98,7 +75,7 @@ follow the usual test setup and should be easy to grok.
98
75
 
99
76
  ## Contributors
100
77
 
101
- http://github.com/svenfuchs/i18n/contributors
78
+ https://github.com/svenfuchs/i18n/graphs/contributors
102
79
 
103
80
  ## License
104
81
 
@@ -5,6 +5,4 @@ gemspec :path => '..'
5
5
  gem 'activesupport', '~> 3.2.0'
6
6
  gem 'mocha'
7
7
  gem 'test_declarative'
8
- gem 'rufus-tokyo'
9
- gem 'ffi'
10
8
  gem 'rake'
@@ -1,21 +1,19 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- i18n (0.6.11)
4
+ i18n (0.7.0.beta1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (3.2.18)
9
+ activesupport (3.2.19)
10
10
  i18n (~> 0.6, >= 0.6.4)
11
11
  multi_json (~> 1.0)
12
- ffi (1.9.3)
13
12
  metaclass (0.0.4)
14
- mocha (1.0.0)
13
+ mocha (1.1.0)
15
14
  metaclass (~> 0.0.1)
16
- multi_json (1.10.0)
17
- rake (10.3.1)
18
- rufus-tokyo (1.0.7)
15
+ multi_json (1.10.1)
16
+ rake (10.3.2)
19
17
  test_declarative (0.0.5)
20
18
 
21
19
  PLATFORMS
@@ -23,9 +21,7 @@ PLATFORMS
23
21
 
24
22
  DEPENDENCIES
25
23
  activesupport (~> 3.2.0)
26
- ffi
27
24
  i18n!
28
25
  mocha
29
26
  rake
30
- rufus-tokyo
31
27
  test_declarative
@@ -5,6 +5,4 @@ gemspec :path => '..'
5
5
  gem 'activesupport', '~> 4.0.0'
6
6
  gem 'mocha'
7
7
  gem 'test_declarative'
8
- gem 'rufus-tokyo'
9
- gem 'ffi'
10
8
  gem 'rake'
@@ -1,37 +1,33 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- i18n (0.6.11)
4
+ i18n (0.7.0.beta1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (4.0.5)
9
+ activesupport (4.0.8)
10
10
  i18n (~> 0.6, >= 0.6.9)
11
11
  minitest (~> 4.2)
12
12
  multi_json (~> 1.3)
13
13
  thread_safe (~> 0.1)
14
14
  tzinfo (~> 0.3.37)
15
- ffi (1.9.3)
16
15
  metaclass (0.0.4)
17
16
  minitest (4.7.5)
18
- mocha (1.0.0)
17
+ mocha (1.1.0)
19
18
  metaclass (~> 0.0.1)
20
- multi_json (1.10.0)
21
- rake (10.3.1)
22
- rufus-tokyo (1.0.7)
19
+ multi_json (1.10.1)
20
+ rake (10.3.2)
23
21
  test_declarative (0.0.5)
24
- thread_safe (0.3.3)
25
- tzinfo (0.3.39)
22
+ thread_safe (0.3.4)
23
+ tzinfo (0.3.40)
26
24
 
27
25
  PLATFORMS
28
26
  ruby
29
27
 
30
28
  DEPENDENCIES
31
29
  activesupport (~> 4.0.0)
32
- ffi
33
30
  i18n!
34
31
  mocha
35
32
  rake
36
- rufus-tokyo
37
33
  test_declarative
@@ -5,6 +5,4 @@ gemspec :path => '..'
5
5
  gem 'activesupport', '~> 4.1.0'
6
6
  gem 'mocha'
7
7
  gem 'test_declarative'
8
- gem 'rufus-tokyo'
9
- gem 'ffi'
10
8
  gem 'rake'
@@ -1,28 +1,26 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- i18n (0.6.11)
4
+ i18n (0.7.0.beta1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (4.1.1)
9
+ activesupport (4.1.4)
10
10
  i18n (~> 0.6, >= 0.6.9)
11
11
  json (~> 1.7, >= 1.7.7)
12
12
  minitest (~> 5.1)
13
13
  thread_safe (~> 0.1)
14
14
  tzinfo (~> 1.1)
15
- ffi (1.9.3)
16
15
  json (1.8.1)
17
16
  metaclass (0.0.4)
18
- minitest (5.3.3)
19
- mocha (1.0.0)
17
+ minitest (5.4.0)
18
+ mocha (1.1.0)
20
19
  metaclass (~> 0.0.1)
21
- rake (10.3.1)
22
- rufus-tokyo (1.0.7)
20
+ rake (10.3.2)
23
21
  test_declarative (0.0.5)
24
- thread_safe (0.3.3)
25
- tzinfo (1.1.0)
22
+ thread_safe (0.3.4)
23
+ tzinfo (1.2.1)
26
24
  thread_safe (~> 0.1)
27
25
 
28
26
  PLATFORMS
@@ -30,9 +28,7 @@ PLATFORMS
30
28
 
31
29
  DEPENDENCIES
32
30
  activesupport (~> 4.1.0)
33
- ffi
34
31
  i18n!
35
32
  mocha
36
33
  rake
37
- rufus-tokyo
38
34
  test_declarative
@@ -2,9 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec :path => '..'
4
4
 
5
- gem 'activesupport', '~> 3.1.0'
5
+ gem 'activesupport', github: 'rails/rails', branch: 'master'
6
6
  gem 'mocha'
7
7
  gem 'test_declarative'
8
- gem 'rufus-tokyo'
9
- gem 'ffi'
10
8
  gem 'rake'
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ i18n (0.7.0.beta1)
5
+
6
+ GIT
7
+ remote: git://github.com/rails/rails.git
8
+ revision: c9cd532ba6be0316d80e93a8ac1b28f532222dcb
9
+ branch: master
10
+ specs:
11
+ activesupport (4.2.0.alpha)
12
+ i18n (>= 0.7.0.beta1, < 0.8)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 1.1)
17
+
18
+ GEM
19
+ remote: https://rubygems.org/
20
+ specs:
21
+ json (1.8.1)
22
+ metaclass (0.0.4)
23
+ minitest (5.4.0)
24
+ mocha (1.1.0)
25
+ metaclass (~> 0.0.1)
26
+ rake (10.3.2)
27
+ test_declarative (0.0.5)
28
+ thread_safe (0.3.4)
29
+ tzinfo (1.2.2)
30
+ thread_safe (~> 0.1)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ activesupport!
37
+ i18n!
38
+ mocha
39
+ rake
40
+ test_declarative
@@ -9,7 +9,7 @@ module I18n
9
9
  autoload :Locale, 'i18n/locale'
10
10
  autoload :Tests, 'i18n/tests'
11
11
 
12
- RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :throw, :raise, :rescue_format]
12
+ RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :throw, :raise]
13
13
  RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
14
14
 
15
15
  extend(Module.new {
@@ -41,6 +41,7 @@ module I18n
41
41
  # Rails development environment. Backends can implement whatever strategy
42
42
  # is useful.
43
43
  def reload!
44
+ config.clear_available_locales_set
44
45
  config.backend.reload!
45
46
  end
46
47
 
@@ -279,15 +280,11 @@ module I18n
279
280
 
280
281
  # Raises an InvalidLocale exception when the passed locale is not available.
281
282
  def enforce_available_locales!(locale)
282
- handle_enforce_available_locales_deprecation
283
-
284
283
  if config.enforce_available_locales
285
284
  raise I18n::InvalidLocale.new(locale) if !locale_available?(locale)
286
285
  end
287
286
  end
288
287
 
289
- # making these private until Ruby 1.9.2 can send to protected methods again
290
- # see http://redmine.ruby-lang.org/repositories/revision/ruby-19?rev=24280
291
288
  private
292
289
 
293
290
  # Any exceptions thrown in translate will be sent to the @@exception_handler
@@ -300,18 +297,18 @@ module I18n
300
297
  #
301
298
  # Examples:
302
299
  #
303
- # I18n.exception_handler = :default_exception_handler # this is the default
304
- # I18n.default_exception_handler(exception, locale, key, options) # will be called like this
300
+ # I18n.exception_handler = :custom_exception_handler # this is the default
301
+ # I18n.custom_exception_handler(exception, locale, key, options) # will be called like this
305
302
  #
306
303
  # I18n.exception_handler = lambda { |*args| ... } # a lambda
307
304
  # I18n.exception_handler.call(exception, locale, key, options) # will be called like this
308
305
  #
309
- # I18n.exception_handler = I18nExceptionHandler.new # an object
310
- # I18n.exception_handler.call(exception, locale, key, options) # will be called like this
306
+ # I18n.exception_handler = I18nExceptionHandler.new # an object
307
+ # I18n.exception_handler.call(exception, locale, key, options) # will be called like this
311
308
  def handle_exception(handling, exception, locale, key, options)
312
309
  case handling
313
310
  when :raise
314
- raise(exception.respond_to?(:to_exception) ? exception.to_exception : exception)
311
+ raise exception.respond_to?(:to_exception) ? exception.to_exception : exception
315
312
  when :throw
316
313
  throw :exception, exception
317
314
  else
@@ -340,25 +337,5 @@ module I18n
340
337
  def normalized_key_cache
341
338
  @normalized_key_cache ||= Hash.new { |h,k| h[k] = {} }
342
339
  end
343
-
344
- # DEPRECATED. Use I18n.normalize_keys instead.
345
- def normalize_translation_keys(locale, key, scope, separator = nil)
346
- puts "I18n.normalize_translation_keys is deprecated. Please use the class I18n.normalize_keys instead."
347
- normalize_keys(locale, key, scope, separator)
348
- end
349
-
350
- # DEPRECATED. Please use the I18n::ExceptionHandler class instead.
351
- def default_exception_handler(exception, locale, key, options)
352
- puts "I18n.default_exception_handler is deprecated. Please use the class I18n::ExceptionHandler instead " +
353
- "(an instance of which is set to I18n.exception_handler by default)."
354
- exception.is_a?(MissingTranslation) ? exception.message : raise(exception)
355
- end
356
-
357
- def handle_enforce_available_locales_deprecation
358
- if config.enforce_available_locales.nil? && !defined?(@unenforced_available_locales_deprecation)
359
- $stderr.puts "[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message."
360
- @unenforced_available_locales_deprecation = true
361
- end
362
- end
363
340
  })
364
341
  end
@@ -81,7 +81,6 @@ module I18n
81
81
  end
82
82
 
83
83
  def reload!
84
- @skip_syntax_deprecation = false
85
84
  end
86
85
 
87
86
  protected
@@ -12,7 +12,7 @@
12
12
  #
13
13
  # Note that InterpolationCompiler does not yield meaningful results and consequently
14
14
  # should not be used with Ruby 1.9 (YARV) but improves performance everywhere else
15
- # (jRuby, Rubinius and 1.8.7).
15
+ # (jRuby, Rubinius).
16
16
  module I18n
17
17
  module Backend
18
18
  module InterpolationCompiler
@@ -1,6 +1,5 @@
1
1
  require 'i18n/backend/base'
2
2
  require 'active_support/json'
3
- require 'active_support/ordered_hash' # active_support/json/encoding uses ActiveSupport::OrderedHash but does not require it
4
3
 
5
4
  module I18n
6
5
  module Backend
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module I18n
2
4
  class Config
3
5
  # The only configuration value that is not global and scoped to thread is :locale.
@@ -9,7 +11,7 @@ module I18n
9
11
  # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
10
12
  def locale=(locale)
11
13
  I18n.enforce_available_locales!(locale)
12
- @locale = locale.to_sym rescue nil
14
+ @locale = locale && locale.to_sym
13
15
  end
14
16
 
15
17
  # Returns the current backend. Defaults to +Backend::Simple+.
@@ -30,7 +32,7 @@ module I18n
30
32
  # Sets the current default locale. Used to set a custom default locale.
31
33
  def default_locale=(locale)
32
34
  I18n.enforce_available_locales!(locale)
33
- @@default_locale = locale.to_sym rescue nil
35
+ @@default_locale = locale && locale.to_sym
34
36
  end
35
37
 
36
38
  # Returns an array of locales for which translations are available.
@@ -56,6 +58,12 @@ module I18n
56
58
  @@available_locales_set = nil
57
59
  end
58
60
 
61
+ # Clears the available locales set so it can be recomputed again after I18n
62
+ # gets reloaded.
63
+ def clear_available_locales_set #:nodoc:
64
+ @@available_locales_set = nil
65
+ end
66
+
59
67
  # Returns the current default scope separator. Defaults to '.'
60
68
  def default_separator
61
69
  @@default_separator ||= '.'
@@ -66,7 +74,8 @@ module I18n
66
74
  @@default_separator = separator
67
75
  end
68
76
 
69
- # Return the current exception handler. Defaults to :default_exception_handler.
77
+ # Returns the current exception handler. Defaults to an instance of
78
+ # I18n::ExceptionHandler.
70
79
  def exception_handler
71
80
  @@exception_handler ||= ExceptionHandler.new
72
81
  end
@@ -117,10 +126,11 @@ module I18n
117
126
  @@load_path = load_path
118
127
  end
119
128
 
120
- # [Deprecated] this will default to true in the future
121
- # Defaults to nil so that it triggers the deprecation warning
129
+ # Whether or not to verify if locales are in the list of available locales.
130
+ # Defaults to true.
131
+ @@enforce_available_locales = true
122
132
  def enforce_available_locales
123
- defined?(@@enforce_available_locales) ? @@enforce_available_locales : nil
133
+ @@enforce_available_locales
124
134
  end
125
135
 
126
136
  def enforce_available_locales=(enforce_available_locales)
@@ -8,21 +8,10 @@ module I18n
8
8
  class ExceptionHandler
9
9
  include Module.new {
10
10
  def call(exception, locale, key, options)
11
- if exception.is_a?(MissingTranslation)
12
- #
13
- # TODO: this block is to be replaced by `exception.message` when
14
- # rescue_format is removed
15
- if options[:rescue_format] == :html
16
- if !defined?(@rescue_format_deprecation)
17
- $stderr.puts "[DEPRECATED] I18n's :recue_format option will be removed from a future release. All exception messages will be plain text. If you need the exception handler to return an html format please set or pass a custom exception handler."
18
- @rescue_format_deprecation = true
19
- end
20
- exception.html_message
21
- else
22
- exception.message
23
- end
24
-
25
- elsif exception.is_a?(Exception)
11
+ case exception
12
+ when MissingTranslation
13
+ exception.message
14
+ when Exception
26
15
  raise exception
27
16
  else
28
17
  throw :exception, exception
@@ -58,12 +47,6 @@ module I18n
58
47
  options.each { |k, v| self.options[k] = v.inspect if v.is_a?(Proc) }
59
48
  end
60
49
 
61
- def html_message
62
- key = CGI.escapeHTML titleize(keys.last)
63
- path = CGI.escapeHTML keys.join('.')
64
- %(<span class="translation_missing" title="translation missing: #{path}">#{key}</span>)
65
- end
66
-
67
50
  def keys
68
51
  @keys ||= I18n.normalize_keys(locale, key, options[:scope]).tap do |keys|
69
52
  keys << 'no key' if keys.size < 2
@@ -78,13 +61,6 @@ module I18n
78
61
  def to_exception
79
62
  MissingTranslationData.new(locale, key, options)
80
63
  end
81
-
82
- protected
83
-
84
- # TODO : remove when #html_message is removed
85
- def titleize(key)
86
- key.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
87
- end
88
64
  end
89
65
 
90
66
  include Base