From f76bd01852d2dcecd34bdffdd01f34eb0f46ea60 Mon Sep 17 00:00:00 2001 From: Nikos Dimitrakopoulos Date: Thu, 10 Nov 2011 13:16:53 +0200 Subject: [PATCH 01/45] Giving further access to Gettext.plural_keys so at least an outside can add more mappings than the :en default. --- lib/i18n/gettext.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/i18n/gettext.rb b/lib/i18n/gettext.rb index 26a5d482..70a4678b 100644 --- a/lib/i18n/gettext.rb +++ b/lib/i18n/gettext.rb @@ -8,11 +8,12 @@ module Gettext @@plural_keys = { :en => [:one, :other] } class << self - # returns an array of plural keys for the given locale so that we can - # convert from gettext's integer-index based style + # returns an array of plural keys for the given locale or the whole hash + # of locale mappings to plural keys so that we can convert from gettext's + # integer-index based style # TODO move this information to the pluralization module - def plural_keys(locale) - @@plural_keys[locale] || @@plural_keys[:en] + def plural_keys(*args) + args.length == 0 ? @@plural_keys : @@plural_keys[args.first] || @@plural_keys[:en] end def extract_scope(msgid, separator) From 913e40e44ca301c0449299419b3ffda2a94ad520 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Sat, 31 Aug 2013 18:26:49 +0300 Subject: [PATCH 02/45] Fix I18n.interpolate when ActiveSupport::SafeBuffer passed as argument --- lib/i18n/interpolate/ruby.rb | 2 +- test/i18n/interpolate_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/i18n/interpolate/ruby.rb b/lib/i18n/interpolate/ruby.rb index 442677f2..d2fdda75 100644 --- a/lib/i18n/interpolate/ruby.rb +++ b/lib/i18n/interpolate/ruby.rb @@ -22,7 +22,7 @@ def interpolate_hash(string, values) if match == '%%' '%' else - key = ($1 || $2).to_sym + key = ($1 || $2 || match.tr("%{}", "")).to_sym value = if values.key?(key) values[key] else diff --git a/test/i18n/interpolate_test.rb b/test/i18n/interpolate_test.rb index 7041b322..59f26791 100644 --- a/test/i18n/interpolate_test.rb +++ b/test/i18n/interpolate_test.rb @@ -58,6 +58,17 @@ class I18nInterpolateTest < Test::Unit::TestCase def test_sprintf_mix_unformatted_and_formatted_named_placeholders assert_equal "foo 1.000000", I18n.interpolate("%{name} %f", :name => "foo", :num => 1.0) end + + class RailsSafeBuffer < String + + def gsub(*args, &block) + to_str.gsub(*args, &block) + end + + end + test "with String subclass that redefined gsub method" do + assert_equal "Hello mars world", I18n.interpolate(RailsSafeBuffer.new("Hello %{planet} world"), :planet => 'mars') + end end class I18nMissingInterpolationCustomHandlerTest < Test::Unit::TestCase From 4b3c23d7181d99f08664addbf37df1da7df1f22f Mon Sep 17 00:00:00 2001 From: Chris Stringer Date: Fri, 6 Dec 2013 15:05:37 -0800 Subject: [PATCH 03/45] Error on exists? with nil key --- lib/i18n.rb | 6 +++--- test/i18n_test.rb | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index ca477ea1..ad702466 100755 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -148,7 +148,7 @@ def translate(*args) handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise enforce_available_locales!(locale) - raise I18n::ArgumentError if key.is_a?(String) && key.empty? + #raise I18n::ArgumentError if key.is_a?(String) && key.empty? result = catch(:exception) do if key.is_a?(Array) @@ -170,7 +170,7 @@ def translate!(key, options={}) # Returns true if a translation exists for a given key, otherwise returns false. def exists?(key, locale = config.locale) - raise I18n::ArgumentError if key.is_a?(String) && key.empty? + raise I18n::ArgumentError if key.nil? || (key.is_a?(String) && key.empty?) config.backend.exists?(locale, key) end @@ -359,7 +359,7 @@ def default_exception_handler(exception, locale, key, options) def handle_enforce_available_locales_deprecation if config.enforce_available_locales.nil? && !@unenforced_available_locales_deprecation - $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." + $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." @unenforced_available_locales_deprecation = true end end diff --git a/test/i18n_test.rb b/test/i18n_test.rb index 040d4cb9..cffa5df9 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -56,7 +56,7 @@ def setup assert_equal :de, Thread.current[:i18n_config].locale I18n.locale = :en end - + test "raises an I18n::InvalidLocale exception when setting an unavailable locale" do begin I18n.config.enforce_available_locales = true @@ -206,6 +206,10 @@ def setup assert_raise(I18n::ArgumentError) { I18n.t("") } end + test "translate given nil as a key raises an I18n::ArgumentError" do + assert_raise(I18n::ArgumentError) { I18n.t(nil) } + end + test "translate given an unavailable locale rases an I18n::InvalidLocale" do begin I18n.config.enforce_available_locales = true @@ -223,6 +227,14 @@ def setup assert_equal false, I18n.exists?(:bogus) end + test "exists? given an empty string will raise an error" do + assert_raise(I18n::ArgumentError) { I18n.exists?("") } + end + + test "exists? given nil will raise an error" do + assert_raise(I18n::ArgumentError) { I18n.exists?(nil) } + end + test "exists? given an existing dot-separated key will return true" do assert_equal true, I18n.exists?('currency.format.delimiter') end From 4f2830823b951637ff8ac2f5679e0fa82f41bbdb Mon Sep 17 00:00:00 2001 From: Chris Stringer Date: Fri, 6 Dec 2013 15:06:16 -0800 Subject: [PATCH 04/45] Whoops remove comment --- lib/i18n.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index ad702466..dd940201 100755 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -148,7 +148,7 @@ def translate(*args) handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise enforce_available_locales!(locale) - #raise I18n::ArgumentError if key.is_a?(String) && key.empty? + raise I18n::ArgumentError if key.is_a?(String) && key.empty? result = catch(:exception) do if key.is_a?(Array) From ca21a110bf6532fabfa668038ddab45f9e9928ad Mon Sep 17 00:00:00 2001 From: Chris Stringer Date: Wed, 18 Dec 2013 12:08:11 -0800 Subject: [PATCH 05/45] Don't allow nil keys in translate --- lib/i18n.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index dd940201..a97f7b85 100755 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -148,7 +148,7 @@ def translate(*args) handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise enforce_available_locales!(locale) - raise I18n::ArgumentError if key.is_a?(String) && key.empty? + raise I18n::ArgumentError if key.nil? || (key.is_a?(String) && key.empty?) result = catch(:exception) do if key.is_a?(Array) From 2e64e3e8609929fedd89052d70db6a2297af913c Mon Sep 17 00:00:00 2001 From: Chris Stringer Date: Wed, 18 Dec 2013 12:09:09 -0800 Subject: [PATCH 06/45] Pass in original key instead of nil when calling translate --- lib/i18n/backend/fallbacks.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/i18n/backend/fallbacks.rb b/lib/i18n/backend/fallbacks.rb index 7252bb00..6b41a752 100644 --- a/lib/i18n/backend/fallbacks.rb +++ b/lib/i18n/backend/fallbacks.rb @@ -35,6 +35,7 @@ module Fallbacks # it's a Symbol. When the default contains a String, Proc or Hash # it is evaluated last after all the fallback locales have been tried. def translate(locale, key, options = {}) + return super if options[:fallback] default = extract_non_symbol_default!(options) if options[:default] @@ -46,8 +47,7 @@ def translate(locale, key, options = {}) end end options.delete(:fallback) - - return super(locale, nil, options.merge(:default => default)) if default + return super(locale, key, options.merge(:default => default)) throw(:exception, I18n::MissingTranslation.new(locale, key, options)) end From 8ccf9a4fbf7183b1069dbe501898459922d669e4 Mon Sep 17 00:00:00 2001 From: Chris Stringer Date: Wed, 18 Dec 2013 12:10:15 -0800 Subject: [PATCH 07/45] Update tests to not send nil values as keys --- lib/i18n/tests/defaults.rb | 6 +++--- lib/i18n/tests/pluralization.rb | 14 +++++++------- lib/i18n/tests/procs.rb | 20 ++++++++++---------- test/backend/cascade_test.rb | 2 +- test/backend/chain_test.rb | 8 ++++---- test/backend/pluralization_test.rb | 10 +++++----- test/backend/simple_test.rb | 4 ++-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/i18n/tests/defaults.rb b/lib/i18n/tests/defaults.rb index 081dcbd1..c89200b9 100644 --- a/lib/i18n/tests/defaults.rb +++ b/lib/i18n/tests/defaults.rb @@ -9,11 +9,11 @@ def setup end test "defaults: given nil as a key it returns the given default" do - assert_equal 'default', I18n.t(nil, :default => 'default') + assert_equal 'default', I18n.t(:does_not_exist, :default => 'default') end test "defaults: given a symbol as a default it translates the symbol" do - assert_equal 'bar', I18n.t(nil, :default => :'foo.bar') + assert_equal 'bar', I18n.t(:does_not_exist, :default => :'foo.bar') end test "defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do @@ -33,7 +33,7 @@ def setup test "defaults: using a custom scope separator" do # data must have been stored using the custom separator when using the ActiveRecord backend I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' }) - assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|') + assert_equal 'bar', I18n.t(:does_not_exist, :default => :'foo|bar', :separator => '|') end end end diff --git a/lib/i18n/tests/pluralization.rb b/lib/i18n/tests/pluralization.rb index d3319dcd..4055fe93 100644 --- a/lib/i18n/tests/pluralization.rb +++ b/lib/i18n/tests/pluralization.rb @@ -4,31 +4,31 @@ module I18n module Tests module Pluralization test "pluralization: given 0 it returns the :zero translation if it is defined" do - assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0) + assert_equal 'zero', I18n.t(:does_not_exist, :default => { :zero => 'zero' }, :count => 0) end test "pluralization: given 0 it returns the :other translation if :zero is not defined" do - assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0) + assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 0) end test "pluralization: given 1 it returns the singular translation" do - assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1) + assert_equal 'bar', I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => 1) end test "pluralization: given 2 it returns the :other translation" do - assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2) + assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 2) end test "pluralization: given 3 it returns the :other translation" do - assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3) + assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 3) end test "pluralization: given nil it returns the whole entry" do - assert_equal({ :one => 'bar' }, I18n.t(:default => { :one => 'bar' }, :count => nil)) + assert_equal({ :one => 'bar' }, I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => nil)) end test "pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do - assert_raise(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) } + assert_raise(I18n::InvalidPluralizationData) { I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => 2) } end end end diff --git a/lib/i18n/tests/procs.rb b/lib/i18n/tests/procs.rb index 55ff9529..a1f17ab4 100644 --- a/lib/i18n/tests/procs.rb +++ b/lib/i18n/tests/procs.rb @@ -10,30 +10,30 @@ module Procs test "defaults: given a default is a Proc it calls it with the key and interpolation values" do proc = lambda { |*args| filter_args(*args) } - assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo') + assert_equal '[:does_not_exist, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => proc, :foo => 'foo') end test "defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) }) - assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo') - assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo') + assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => :a_lambda, :foo => 'foo') + assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => [nil, :a_lambda], :foo => 'foo') end test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do proc = lambda { |*args| filter_args(*args) } - assert_match %r(\[\{:foo=>#\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc) + assert_match %r(\[\{:foo=>#\}\]), I18n.t(:does_not_exist, :default => '%{foo}', :foo => proc) end - test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do + test "interpolation: given a key resolves to a lambda that returns a string then interpolation still works" do proc = lambda { |*args| "%{foo}: " + filter_args(*args) } - assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo') + assert_equal "foo: [:does_not_exist, {:foo=>\"foo\"}]", I18n.t(:does_not_exist, :default => proc, :foo => 'foo') end test "pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do proc = lambda { |*args| { :zero => 'zero', :one => 'one', :other => 'other' } } - assert_equal 'zero', I18n.t(:default => proc, :count => 0) - assert_equal 'one', I18n.t(:default => proc, :count => 1) - assert_equal 'other', I18n.t(:default => proc, :count => 2) + assert_equal 'zero', I18n.t(:does_not_exist, :default => proc, :count => 0) + assert_equal 'one', I18n.t(:does_not_exist, :default => proc, :count => 1) + assert_equal 'other', I18n.t(:does_not_exist, :default => proc, :count => 2) end test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do @@ -42,7 +42,7 @@ module Procs end test "lookup: given the option :resolve => false was passed it does not resolve proc default" do - assert_equal Proc, I18n.t(nil, :default => lambda { |*args| filter_args(*args) }, :resolve => false).class + assert_equal Proc, I18n.t(:does_not_exist, :default => lambda { |*args| filter_args(*args) }, :resolve => false).class end protected diff --git a/test/backend/cascade_test.rb b/test/backend/cascade_test.rb index c23f1674..71fae50c 100644 --- a/test/backend/cascade_test.rb +++ b/test/backend/cascade_test.rb @@ -38,7 +38,7 @@ def lookup(key, options = {}) end test "cascades defaults, too" do - assert_equal 'foo', lookup(nil, :default => [:'missing.missing', :'missing.foo']) + assert_equal 'foo', lookup(:does_not_exist, :default => [:'missing.missing', :'missing.foo']) end test "works with :offset => 2 and a single key" do diff --git a/test/backend/chain_test.rb b/test/backend/chain_test.rb index a3bb44b4..67147be5 100644 --- a/test/backend/chain_test.rb +++ b/test/backend/chain_test.rb @@ -28,10 +28,10 @@ def setup end test "default" do - assert_equal 'Fuh', I18n.t(:default => 'Fuh') - assert_equal 'Zero', I18n.t(:default => { :zero => 'Zero' }, :count => 0) - assert_equal({ :zero => 'Zero' }, I18n.t(:default => { :zero => 'Zero' })) - assert_equal 'Foo', I18n.t(:default => :foo) + assert_equal 'Fuh', I18n.t(:does_not_exist, :default => 'Fuh') + assert_equal 'Zero', I18n.t(:does_not_exist, :default => { :zero => 'Zero' }, :count => 0) + assert_equal({ :zero => 'Zero' }, I18n.t(:does_not_exist, :default => { :zero => 'Zero' })) + assert_equal 'Foo', I18n.t(:does_not_exist, :default => :foo) end test 'default is returned if translation is missing' do diff --git a/test/backend/pluralization_test.rb b/test/backend/pluralization_test.rb index 54fbba92..9d883db7 100644 --- a/test/backend/pluralization_test.rb +++ b/test/backend/pluralization_test.rb @@ -18,24 +18,24 @@ def setup end test "pluralization picks :one for 1" do - assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :xx) + assert_equal 'one', I18n.t(:does_not_exist, :count => 1, :default => @entry, :locale => :xx) end test "pluralization picks :few for 2" do - assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :xx) + assert_equal 'few', I18n.t(:does_not_exist, :count => 2, :default => @entry, :locale => :xx) end test "pluralization picks :many for 11" do - assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :xx) + assert_equal 'many', I18n.t(:does_not_exist, :count => 11, :default => @entry, :locale => :xx) end test "pluralization picks zero for 0 if the key is contained in the data" do - assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :xx) + assert_equal 'zero', I18n.t(:does_not_exist, :count => 0, :default => @entry, :locale => :xx) end test "pluralization picks few for 0 if the key is not contained in the data" do @entry.delete(:zero) - assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx) + assert_equal 'few', I18n.t(:does_not_exist, :count => 0, :default => @entry, :locale => :xx) end test "Fallbacks can pick up rules from fallback locales, too" do diff --git a/test/backend/simple_test.rb b/test/backend/simple_test.rb index 3ebc8ee4..515a1b98 100644 --- a/test/backend/simple_test.rb +++ b/test/backend/simple_test.rb @@ -7,8 +7,8 @@ def setup end # useful because this way we can use the backend with no key for interpolation/pluralization - test "simple backend translate: given nil as a key it still interpolations the default value" do - assert_equal "Hi David", I18n.t(nil, :default => "Hi %{name}", :name => "David") + test "simple backend translate: given an invalid key it still interpolates the default value" do + assert_equal "Hi David", I18n.t(:does_not_exist, :default => "Hi %{name}", :name => "David") end # loading translations From 229ee94f63f2068cc26fad50d0b60358c4845d55 Mon Sep 17 00:00:00 2001 From: Chris Stringer Date: Wed, 18 Dec 2013 14:07:39 -0800 Subject: [PATCH 08/45] Standardize on Proc (vs proc or lambda) --- lib/i18n/tests/procs.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/i18n/tests/procs.rb b/lib/i18n/tests/procs.rb index a1f17ab4..345d8995 100644 --- a/lib/i18n/tests/procs.rb +++ b/lib/i18n/tests/procs.rb @@ -3,7 +3,7 @@ module I18n module Tests module Procs - test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do + test "lookup: given a translation is a Proc it calls the Proc with the key and interpolation values" do I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) }) assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo') end @@ -19,12 +19,12 @@ module Procs assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => [nil, :a_lambda], :foo => 'foo') end - test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do + test "interpolation: given an interpolation value is a Proc it calls it with key and values before interpolating it" do proc = lambda { |*args| filter_args(*args) } assert_match %r(\[\{:foo=>#\}\]), I18n.t(:does_not_exist, :default => '%{foo}', :foo => proc) end - test "interpolation: given a key resolves to a lambda that returns a string then interpolation still works" do + test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do proc = lambda { |*args| "%{foo}: " + filter_args(*args) } assert_equal "foo: [:does_not_exist, {:foo=>\"foo\"}]", I18n.t(:does_not_exist, :default => proc, :foo => 'foo') end @@ -36,12 +36,12 @@ module Procs assert_equal 'other', I18n.t(:does_not_exist, :default => proc, :count => 2) end - test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do + test "lookup: given the option :resolve => false was passed it does not resolve Proc translations" do I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) }) assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class end - test "lookup: given the option :resolve => false was passed it does not resolve proc default" do + test "lookup: given the option :resolve => false was passed it does not resolve Proc default" do assert_equal Proc, I18n.t(:does_not_exist, :default => lambda { |*args| filter_args(*args) }, :resolve => false).class end From 1b5d29c9a6bcf6401cdacf7d25f42c9b69031752 Mon Sep 17 00:00:00 2001 From: Chipairon Date: Tue, 22 Apr 2014 12:16:12 +0200 Subject: [PATCH 09/45] The proc is executed by Kernel#eval and the methods used from within need to be fully qualified to be 'findable' when being evaluated. --- lib/i18n/tests/localization/procs.rb | 10 +++++----- lib/i18n/tests/procs.rb | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/i18n/tests/localization/procs.rb b/lib/i18n/tests/localization/procs.rb index 7b7813e2..bdfa9480 100644 --- a/lib/i18n/tests/localization/procs.rb +++ b/lib/i18n/tests/localization/procs.rb @@ -52,19 +52,19 @@ module Procs test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do setup_time_proc_translations time = ::Time.utc(2008, 3, 1, 6, 0) - assert_equal inspect_args([time, {}]), I18n.l(time, :format => :proc, :locale => :ru) + assert_equal I18n::Tests::Localization::Procs.inspect_args([time, {}]), I18n.l(time, :format => :proc, :locale => :ru) end test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do setup_time_proc_translations time = ::Time.utc(2008, 3, 1, 6, 0) options = { :foo => 'foo' } - assert_equal inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru)) + assert_equal I18n::Tests::Localization::Procs.inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru)) end protected - def inspect_args(args) + def self.inspect_args(args) args = args.map do |arg| case arg when ::Time, ::DateTime @@ -85,12 +85,12 @@ def setup_time_proc_translations I18n.backend.store_translations :ru, { :time => { :formats => { - :proc => lambda { |*args| inspect_args(args) } + :proc => lambda { |*args| I18n::Tests::Localization::Procs.inspect_args(args) } } }, :date => { :formats => { - :proc => lambda { |*args| inspect_args(args) } + :proc => lambda { |*args| I18n::Tests::Localization::Procs.inspect_args(args) } }, :'day_names' => lambda { |key, options| (options[:format] =~ /^%A/) ? diff --git a/lib/i18n/tests/procs.rb b/lib/i18n/tests/procs.rb index 55ff9529..02db95cb 100644 --- a/lib/i18n/tests/procs.rb +++ b/lib/i18n/tests/procs.rb @@ -4,28 +4,29 @@ module I18n module Tests module Procs test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do - I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) }) + I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }) assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo') end test "defaults: given a default is a Proc it calls it with the key and interpolation values" do - proc = lambda { |*args| filter_args(*args) } + proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) } assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo') end test "defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do - I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) }) + the_lambda = lambda { |*args| I18n::Tests::Procs.filter_args(*args) } + I18n.backend.store_translations(:en, :a_lambda => the_lambda) assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo') assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo') end test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do - proc = lambda { |*args| filter_args(*args) } + proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) } assert_match %r(\[\{:foo=>#\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc) end test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do - proc = lambda { |*args| "%{foo}: " + filter_args(*args) } + proc = lambda { |*args| "%{foo}: " + I18n::Tests::Procs.filter_args(*args) } assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo') end @@ -37,17 +38,16 @@ module Procs end test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do - I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| filter_args(*args) }) + I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }) assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class end test "lookup: given the option :resolve => false was passed it does not resolve proc default" do - assert_equal Proc, I18n.t(nil, :default => lambda { |*args| filter_args(*args) }, :resolve => false).class + assert_equal Proc, I18n.t(nil, :default => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }, :resolve => false).class end - protected - def filter_args(*args) + def self.filter_args(*args) args.map {|arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect end end From 6f3a5bb2c077f4dee9eb554062dcf48edbfccabc Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 21 Nov 2016 11:43:05 +1100 Subject: [PATCH 10/45] Bump to 0.8.0.beta1 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index 4a9efa9f..31178899 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.7.0" + VERSION = "0.8.0.beta1" end From 7b205f23cc3cb1a3266c7c5764f367a3b7bccdcd Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 21 Nov 2016 12:01:18 +1100 Subject: [PATCH 11/45] Add issue template --- .github/ISSUE_TEMPLATE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..9711239b --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,21 @@ +## What I tried to do + +* Fill this out! + +## What I expected to happen + +* Fill this out! + +## What actually happened + +* Fill this out! + +## Versions of i18n, rails, and anything else you think is neccessary + +* Fill this out! + +---- + +Bonus points for providing an application or a small code example which reproduces the issue. + +Thanks! :heart: From 210feb6fad5d2fc02e1329d73209cbca2a2d15d9 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 21 Nov 2016 15:48:46 +1100 Subject: [PATCH 12/45] Update bundler --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ecffb548..5489341d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - i18n (0.7.0) + i18n (0.8.0.beta1) GEM remote: https://rubygems.org/ @@ -25,4 +25,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 1.13.5 + 1.13.6 From 4f0331d51051f97e6ee8feccb59c16c6e8255e88 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 5 Dec 2016 08:24:05 +1100 Subject: [PATCH 13/45] Bump dependencies --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5489341d..2ede6301 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GEM remote: https://rubygems.org/ specs: metaclass (0.0.4) - minitest (5.9.1) + minitest (5.10.1) mocha (1.2.1) metaclass (~> 0.0.1) rake (11.3.0) From 27d7ab77b979c4bd1a403dfa41103b665c183b0e Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 5 Dec 2016 08:27:06 +1100 Subject: [PATCH 14/45] Remove Gemfile.lock from source control The gems installed here should be using the ones as specified in the gemspec (if any), as that is how Rubygems itself will install them --- .gitignore | 1 + Gemfile.lock | 28 ---------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index b066d1ea..ea8628bb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ vendor/**/* pkg .bundle .rvmrc +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 2ede6301..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,28 +0,0 @@ -PATH - remote: . - specs: - i18n (0.8.0.beta1) - -GEM - remote: https://rubygems.org/ - specs: - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - rake (11.3.0) - test_declarative (0.0.5) - -PLATFORMS - java - ruby - -DEPENDENCIES - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.13.6 From beb7b953c052e1c44f563a0f5bdfef71f61d1957 Mon Sep 17 00:00:00 2001 From: Tasos Latsas Date: Fri, 23 Dec 2016 12:36:15 +0200 Subject: [PATCH 15/45] Add test for accessing I18n::Gettext.plural_keys hash --- test/i18n/gettext_plural_keys_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/i18n/gettext_plural_keys_test.rb diff --git a/test/i18n/gettext_plural_keys_test.rb b/test/i18n/gettext_plural_keys_test.rb new file mode 100644 index 00000000..4d0c9778 --- /dev/null +++ b/test/i18n/gettext_plural_keys_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class I18nGettextPluralKeysTest < I18n::TestCase + def setup + super + I18n::Gettext.plural_keys[:zz] = [:value1, :value2] + end + + test "Returns the plural keys of the given locale if present" do + assert_equal I18n::Gettext.plural_keys(:zz), [:value1, :value2] + end + + test "Returns the plural keys of :en if given locale not present" do + assert_equal I18n::Gettext.plural_keys(:yy), [:one, :other] + end + + test "Returns the whole hash with no arguments" do + assert_equal I18n::Gettext.plural_keys, { :en => [:one, :other], :zz => [:value1, :value2] } + end +end From 0cc2cad76776b5aea06851e969f8bf81a4d58770 Mon Sep 17 00:00:00 2001 From: Tasos Latsas Date: Fri, 23 Dec 2016 12:37:11 +0200 Subject: [PATCH 16/45] Use .empty? instead of length comparison with 0 --- lib/i18n/gettext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/gettext.rb b/lib/i18n/gettext.rb index 70a4678b..392cccd3 100644 --- a/lib/i18n/gettext.rb +++ b/lib/i18n/gettext.rb @@ -13,7 +13,7 @@ class << self # integer-index based style # TODO move this information to the pluralization module def plural_keys(*args) - args.length == 0 ? @@plural_keys : @@plural_keys[args.first] || @@plural_keys[:en] + args.empty? ? @@plural_keys : @@plural_keys[args.first] || @@plural_keys[:en] end def extract_scope(msgid, separator) From 5cd5c9f80d3674ed5c0bc971b90061b6b49d9915 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 30 Dec 2016 08:28:08 +1100 Subject: [PATCH 17/45] Add link to i18n guide to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ae9faf7d..12b8ada1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Ruby Internationalization and localization solution. +[See the Rails Guide](http://guides.rubyonrails.org/i18n.html) for an example of its usage. (Note: This library can be used independently from Rails.) + Features: * translation and localization From d5fb5dd1fa204048f4c4a0123c961fa457640a69 Mon Sep 17 00:00:00 2001 From: Ignatius Reza Date: Mon, 26 Dec 2016 14:21:39 +0900 Subject: [PATCH 18/45] fix references to i18n in Gemfiles Fixes #355 --- gemfiles/Gemfile.rails-3.2.x.lock | 4 ++-- gemfiles/Gemfile.rails-4.0.x.lock | 4 ++-- gemfiles/Gemfile.rails-4.1.x.lock | 4 ++-- gemfiles/Gemfile.rails-4.2.x.lock | 4 ++-- gemfiles/Gemfile.rails-5.0.x.lock | 4 ++-- gemfiles/Gemfile.rails-master.lock | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gemfiles/Gemfile.rails-3.2.x.lock b/gemfiles/Gemfile.rails-3.2.x.lock index 1aa3d4f4..b43e2240 100644 --- a/gemfiles/Gemfile.rails-3.2.x.lock +++ b/gemfiles/Gemfile.rails-3.2.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.7.0) + i18n (0.8.0.beta1) GEM remote: https://rubygems.org/ @@ -29,4 +29,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 1.13.5 + 1.13.7 diff --git a/gemfiles/Gemfile.rails-4.0.x.lock b/gemfiles/Gemfile.rails-4.0.x.lock index d14c35f1..a891a55c 100644 --- a/gemfiles/Gemfile.rails-4.0.x.lock +++ b/gemfiles/Gemfile.rails-4.0.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.7.0) + i18n (0.8.0.beta1) GEM remote: https://rubygems.org/ @@ -34,4 +34,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 1.13.5 + 1.13.7 diff --git a/gemfiles/Gemfile.rails-4.1.x.lock b/gemfiles/Gemfile.rails-4.1.x.lock index 93dc7ae0..f734ce42 100644 --- a/gemfiles/Gemfile.rails-4.1.x.lock +++ b/gemfiles/Gemfile.rails-4.1.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.7.0) + i18n (0.8.0.beta1) GEM remote: https://rubygems.org/ @@ -35,4 +35,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 1.13.5 + 1.13.7 diff --git a/gemfiles/Gemfile.rails-4.2.x.lock b/gemfiles/Gemfile.rails-4.2.x.lock index 6459e822..859ca329 100644 --- a/gemfiles/Gemfile.rails-4.2.x.lock +++ b/gemfiles/Gemfile.rails-4.2.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.7.0) + i18n (0.8.0.beta1) GEM remote: https://rubygems.org/ @@ -35,4 +35,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 1.13.5 + 1.13.7 diff --git a/gemfiles/Gemfile.rails-5.0.x.lock b/gemfiles/Gemfile.rails-5.0.x.lock index 74442adf..618626e2 100644 --- a/gemfiles/Gemfile.rails-5.0.x.lock +++ b/gemfiles/Gemfile.rails-5.0.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.7.0) + i18n (0.8.0.beta1) GEM remote: https://rubygems.org/ @@ -34,4 +34,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 1.13.6 + 1.13.7 diff --git a/gemfiles/Gemfile.rails-master.lock b/gemfiles/Gemfile.rails-master.lock index f5b9f7bb..45e32307 100644 --- a/gemfiles/Gemfile.rails-master.lock +++ b/gemfiles/Gemfile.rails-master.lock @@ -12,7 +12,7 @@ GIT PATH remote: .. specs: - i18n (0.7.0) + i18n (0.8.0.beta1) GEM remote: https://rubygems.org/ @@ -40,4 +40,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 1.13.6 + 1.13.7 From 9481e94d243837f8f2f385f0f95368bb601ab939 Mon Sep 17 00:00:00 2001 From: Ignatius Reza Date: Mon, 26 Dec 2016 10:05:27 +0900 Subject: [PATCH 19/45] allow disabling fallback explicitly when calling translate e.g I18n.translate(:key, :fallback => false) --- lib/i18n/backend/fallbacks.rb | 7 ++++--- test/backend/fallbacks_test.rb | 10 +++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/i18n/backend/fallbacks.rb b/lib/i18n/backend/fallbacks.rb index 86bd972b..6cb36876 100644 --- a/lib/i18n/backend/fallbacks.rb +++ b/lib/i18n/backend/fallbacks.rb @@ -35,11 +35,12 @@ module Fallbacks # it's a Symbol. When the default contains a String, Proc or Hash # it is evaluated last after all the fallback locales have been tried. def translate(locale, key, options = {}) - return super if options[:fallback] + return super unless options.fetch(:fallback, true) + return super if (@fallback_locked ||= false) default = extract_non_symbol_default!(options) if options[:default] begin - options[:fallback] = true + @fallback_locked = true I18n.fallbacks[locale].each do |fallback| begin catch(:exception) do @@ -51,7 +52,7 @@ def translate(locale, key, options = {}) end end ensure - options.delete(:fallback) + @fallback_locked = false end return super(locale, nil, options.merge(:default => default)) if default diff --git a/test/backend/fallbacks_test.rb b/test/backend/fallbacks_test.rb index a1d5a74a..2b1eedb0 100644 --- a/test/backend/fallbacks_test.rb +++ b/test/backend/fallbacks_test.rb @@ -68,6 +68,14 @@ def setup assert_equal 'Default 6 Bars', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, {:other => "Default %{count} Bars"}, "Default Bar"], :count => 6) end + test "returns the default translation for a missing :de translation even when default is a String when fallback is disabled" do + assert_equal 'Default String', I18n.t(:foo, :locale => :de, :default => 'Default String', :fallback => false) + end + + test "raises I18n::MissingTranslationData exception when fallback is disabled even when fallback translation exists" do + assert_raise(I18n::MissingTranslationData) { I18n.t(:foo, :locale => :de, :fallback => false, :raise => true) } + end + test "raises I18n::MissingTranslationData exception when no translation was found" do assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :en, :raise => true) } assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :de, :raise => true) } @@ -195,4 +203,4 @@ def setup assert_equal false, I18n.exists?(:baz, :de) assert_equal false, I18n.exists?(:bogus, :'de-DE') end -end \ No newline at end of file +end From 529fc5b3707b4724396ccf34dc2b2bb029c881b3 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 1 Feb 2017 08:47:06 +1100 Subject: [PATCH 20/45] Bump to 0.8.0 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index 31178899..369db49e 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.8.0.beta1" + VERSION = "0.8.0" end From 06ac12a62b9cf28db32fb317dca838f344c99d70 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Feb 2017 15:31:34 +0900 Subject: [PATCH 21/45] Correctly test that available_locales delegates to the backend --- lib/i18n/tests/basics.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/tests/basics.rb b/lib/i18n/tests/basics.rb index dc0596a3..d2543634 100644 --- a/lib/i18n/tests/basics.rb +++ b/lib/i18n/tests/basics.rb @@ -38,7 +38,7 @@ def teardown test "available_locales delegates to the backend when not set explicitely" do I18n.backend.expects(:available_locales).twice - assert_equal I18n.available_locales, I18n.available_locales + assert_equal I18n.backend.available_locales, I18n.available_locales end test "exists? is implemented by the backend" do From 13484b8302c6e65ae8153100b634c66abf70e966 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Feb 2017 16:10:29 +0900 Subject: [PATCH 22/45] :warning: "Use assert_nil if expecting nil. This will fail in Minitest 6." --- lib/i18n/tests/basics.rb | 3 ++- lib/i18n/tests/defaults.rb | 2 +- test/i18n_test.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/i18n/tests/basics.rb b/lib/i18n/tests/basics.rb index d2543634..951d7ab5 100644 --- a/lib/i18n/tests/basics.rb +++ b/lib/i18n/tests/basics.rb @@ -37,7 +37,8 @@ def teardown end test "available_locales delegates to the backend when not set explicitely" do - I18n.backend.expects(:available_locales).twice + original_available_locales_value = I18n.backend.available_locales + I18n.backend.expects(:available_locales).returns(original_available_locales_value).twice assert_equal I18n.backend.available_locales, I18n.available_locales end diff --git a/lib/i18n/tests/defaults.rb b/lib/i18n/tests/defaults.rb index c9caf8e3..08f92887 100644 --- a/lib/i18n/tests/defaults.rb +++ b/lib/i18n/tests/defaults.rb @@ -29,7 +29,7 @@ def setup end test "defaults: given nil it returns nil" do - assert_equal nil, I18n.t(:does_not_exist, :default => nil) + assert_nil I18n.t(:does_not_exist, :default => nil) end test "defaults: given an array of missing keys it raises a MissingTranslationData exception" do diff --git a/test/i18n_test.rb b/test/i18n_test.rb index 728e7ed9..dd9d6b15 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -270,7 +270,7 @@ def setup end test "localize given nil and default returns default" do - assert_equal nil, I18n.l(nil, :default => nil) + assert_nil I18n.l(nil, :default => nil) end test "localize given an Object raises an I18n::ArgumentError" do From 98559b0a4103cc3edfbc353648c1621c0761ec17 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Feb 2017 16:25:57 +0900 Subject: [PATCH 23/45] Remove gemfiles/Gemfile.*.lock from source control The gems installed here should be using the ones as specified in the gemspec (if any), as that is how Rubygems itself will install them This follows up 27d7ab77b979c4bd1a403dfa41103b665c183b0e --- gemfiles/Gemfile.rails-3.2.x.lock | 32 ---------------------- gemfiles/Gemfile.rails-4.0.x.lock | 37 ------------------------- gemfiles/Gemfile.rails-4.1.x.lock | 38 -------------------------- gemfiles/Gemfile.rails-4.2.x.lock | 38 -------------------------- gemfiles/Gemfile.rails-5.0.x.lock | 37 ------------------------- gemfiles/Gemfile.rails-master.lock | 43 ------------------------------ 6 files changed, 225 deletions(-) delete mode 100644 gemfiles/Gemfile.rails-3.2.x.lock delete mode 100644 gemfiles/Gemfile.rails-4.0.x.lock delete mode 100644 gemfiles/Gemfile.rails-4.1.x.lock delete mode 100644 gemfiles/Gemfile.rails-4.2.x.lock delete mode 100644 gemfiles/Gemfile.rails-5.0.x.lock delete mode 100644 gemfiles/Gemfile.rails-master.lock diff --git a/gemfiles/Gemfile.rails-3.2.x.lock b/gemfiles/Gemfile.rails-3.2.x.lock deleted file mode 100644 index b43e2240..00000000 --- a/gemfiles/Gemfile.rails-3.2.x.lock +++ /dev/null @@ -1,32 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.0.beta1) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (3.2.21) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - metaclass (0.0.4) - minitest (5.9.1) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.0) - rake (10.4.2) - test_declarative (0.0.5) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 3.2.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.13.7 diff --git a/gemfiles/Gemfile.rails-4.0.x.lock b/gemfiles/Gemfile.rails-4.0.x.lock deleted file mode 100644 index a891a55c..00000000 --- a/gemfiles/Gemfile.rails-4.0.x.lock +++ /dev/null @@ -1,37 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.0.beta1) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - metaclass (0.0.4) - minitest (4.7.5) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.11.0) - rake (10.4.2) - test_declarative (0.0.5) - thread_safe (0.3.5) - tzinfo (0.3.43) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 4.0.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.13.7 diff --git a/gemfiles/Gemfile.rails-4.1.x.lock b/gemfiles/Gemfile.rails-4.1.x.lock deleted file mode 100644 index f734ce42..00000000 --- a/gemfiles/Gemfile.rails-4.1.x.lock +++ /dev/null @@ -1,38 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.0.beta1) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (4.1.10) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - json (1.8.2) - metaclass (0.0.4) - minitest (5.5.1) - mocha (1.1.0) - metaclass (~> 0.0.1) - rake (10.4.2) - test_declarative (0.0.5) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 4.1.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.13.7 diff --git a/gemfiles/Gemfile.rails-4.2.x.lock b/gemfiles/Gemfile.rails-4.2.x.lock deleted file mode 100644 index 859ca329..00000000 --- a/gemfiles/Gemfile.rails-4.2.x.lock +++ /dev/null @@ -1,38 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.0.beta1) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (4.2.1) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - json (1.8.2) - metaclass (0.0.4) - minitest (5.5.1) - mocha (1.1.0) - metaclass (~> 0.0.1) - rake (10.4.2) - test_declarative (0.0.5) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 4.2.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.13.7 diff --git a/gemfiles/Gemfile.rails-5.0.x.lock b/gemfiles/Gemfile.rails-5.0.x.lock deleted file mode 100644 index 618626e2..00000000 --- a/gemfiles/Gemfile.rails-5.0.x.lock +++ /dev/null @@ -1,37 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.0.beta1) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (5.0.0.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - concurrent-ruby (1.0.2) - metaclass (0.0.4) - minitest (5.9.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - rake (11.3.0) - test_declarative (0.0.5) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 5.0.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.13.7 diff --git a/gemfiles/Gemfile.rails-master.lock b/gemfiles/Gemfile.rails-master.lock deleted file mode 100644 index 45e32307..00000000 --- a/gemfiles/Gemfile.rails-master.lock +++ /dev/null @@ -1,43 +0,0 @@ -GIT - remote: git://github.com/rails/rails.git - revision: da23e125f8d755917b08f5cca1f7fe1ff38c8b7e - branch: master - specs: - activesupport (5.1.0.alpha) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - -PATH - remote: .. - specs: - i18n (0.8.0.beta1) - -GEM - remote: https://rubygems.org/ - specs: - concurrent-ruby (1.0.2) - metaclass (0.0.4) - minitest (5.5.1) - mocha (1.1.0) - metaclass (~> 0.0.1) - rake (10.4.2) - test_declarative (0.0.5) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport! - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.13.7 From 321b90e863282405f62587eea51bd25bb4c737c5 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Feb 2017 16:33:56 +0900 Subject: [PATCH 24/45] We aren't testing version "2.2" here And if this means ruby 2.2, it shouldn't be allowed to fail. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 77aa4460..a754256e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,6 @@ matrix: - rvm: ruby-head gemfile: gemfiles/Gemfile.rails-4.2.x allow_failures: - - rvm: 2.2 - rvm: rbx - rvm: jruby fast_finish: true From 604cf8a157fc2fa9ffd8f7113e1ec46ebdeb86a9 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Feb 2017 16:40:08 +0900 Subject: [PATCH 25/45] CI against ruby 2.4.0 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a754256e..c7d7af6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ rvm: - 2.1.8 - 2.2.4 - 2.3.1 + - 2.4.0 - ruby-head - rbx - jruby From 2588057b410ce5ddc566cc9e3032c43c1a2a3240 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Feb 2017 16:43:10 +0900 Subject: [PATCH 26/45] CI against newest stable rubies for each minor version --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c7d7af6d..8ec87f78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ before_install: rvm: - 1.9.3 - 2.0.0 - - 2.1.8 - - 2.2.4 - - 2.3.1 + - 2.1.10 + - 2.2.6 + - 2.3.3 - 2.4.0 - ruby-head - rbx @@ -28,13 +28,13 @@ matrix: gemfile: gemfiles/Gemfile.rails-master - rvm: 2.0.0 gemfile: gemfiles/Gemfile.rails-master - - rvm: 2.1.8 + - rvm: 2.1.10 gemfile: gemfiles/Gemfile.rails-master - rvm: 1.9.3 gemfile: gemfiles/Gemfile.rails-5.0.x - rvm: 2.0.0 gemfile: gemfiles/Gemfile.rails-5.0.x - - rvm: 2.1.8 + - rvm: 2.1.10 gemfile: gemfiles/Gemfile.rails-5.0.x # activesupport has a dependency on json, which does not build on this version - rvm: ruby-head From 6e1f222b26740bc3fbe1e8de381159874409b739 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 1 Feb 2017 16:40:28 +0900 Subject: [PATCH 27/45] No need to skip ruby 2.4+ x rails 4 now Since json 1.8.6 that supports ruby 2.4+ has been released. --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8ec87f78..c5b54361 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,12 +36,6 @@ matrix: gemfile: gemfiles/Gemfile.rails-5.0.x - rvm: 2.1.10 gemfile: gemfiles/Gemfile.rails-5.0.x - # activesupport has a dependency on json, which does not build on this version - - rvm: ruby-head - gemfile: gemfiles/Gemfile.rails-4.1.x - # activesupport has a dependency on json, which does not build on this version - - rvm: ruby-head - gemfile: gemfiles/Gemfile.rails-4.2.x allow_failures: - rvm: rbx - rvm: jruby From df683f1e3eff2f7870010f0075a7d5ba75f9e446 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Wed, 1 Feb 2017 16:47:44 -0500 Subject: [PATCH 28/45] Docs: Add 0.8.0 to changelog [ci skip] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7608c5f9..3c4c74ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ * `Hash#slice` ignores non existing keys. +# 0.8.0 + +See https://github.com/svenfuchs/i18n/releases/tag/v0.8.0 + # 0.7.0 * Drop support to Ruby 1.8.7 / REE From 6b60a5b523de4015842d43dff8255c360ff51dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20A=2E=20Ceccon?= Date: Tue, 21 Feb 2017 14:30:48 -0300 Subject: [PATCH 29/45] Fix transliteration to default replacement char MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit f6a4294c introduced a bug where non-ASCII chars not present in the transliteration map would be removed from the output, instead of being replaced by the default replacement char, violating the behavior stated in the documentation: I18n.transliterate("日本語") # => "" (should be "???") This fixes the issue while preserving the optimization introduced by that commit. --- lib/i18n/backend/transliterator.rb | 3 ++- test/i18n_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/i18n/backend/transliterator.rb b/lib/i18n/backend/transliterator.rb index 538dd600..2617bcf2 100644 --- a/lib/i18n/backend/transliterator.rb +++ b/lib/i18n/backend/transliterator.rb @@ -75,7 +75,8 @@ def initialize(rule = nil) add rule if rule end - def transliterate(string, replacement = DEFAULT_REPLACEMENT_CHAR) + def transliterate(string, replacement = nil) + replacement ||= DEFAULT_REPLACEMENT_CHAR string.gsub(/[^\x00-\x7f]/u) do |char| approximations[char] || replacement end diff --git a/test/i18n_test.rb b/test/i18n_test.rb index dd9d6b15..ac8a4498 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -351,6 +351,10 @@ def call(exception, locale, key, options); key; end end end + test "transliterate non-ASCII chars not in map with default replacement char" do + assert_equal "???", I18n.transliterate("日本語") + end + test "I18n.locale_available? returns true when the passed locale is available" do I18n.available_locales = [:en, :de] assert_equal true, I18n.locale_available?(:de) From 73b107b6d8ec6be35d0e41984e26b3f52fdf4f36 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 22 Feb 2017 13:46:10 +1100 Subject: [PATCH 30/45] Bump to 0.8.1 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index 369db49e..439d9366 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.8.0" + VERSION = "0.8.1" end From 3224e95500268399c01b49e2b91691857ee634d3 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 24 Mar 2017 10:46:46 +1100 Subject: [PATCH 31/45] Add Gemfile.lock for each Rails version --- gemfiles/Gemfile.rails-3.2.x.lock | 32 ++++++++++++++++++++++ gemfiles/Gemfile.rails-4.0.x.lock | 37 +++++++++++++++++++++++++ gemfiles/Gemfile.rails-4.1.x.lock | 38 ++++++++++++++++++++++++++ gemfiles/Gemfile.rails-4.2.x.lock | 36 +++++++++++++++++++++++++ gemfiles/Gemfile.rails-5.0.x.lock | 37 +++++++++++++++++++++++++ gemfiles/Gemfile.rails-master.lock | 43 ++++++++++++++++++++++++++++++ 6 files changed, 223 insertions(+) create mode 100644 gemfiles/Gemfile.rails-3.2.x.lock create mode 100644 gemfiles/Gemfile.rails-4.0.x.lock create mode 100644 gemfiles/Gemfile.rails-4.1.x.lock create mode 100644 gemfiles/Gemfile.rails-4.2.x.lock create mode 100644 gemfiles/Gemfile.rails-5.0.x.lock create mode 100644 gemfiles/Gemfile.rails-master.lock diff --git a/gemfiles/Gemfile.rails-3.2.x.lock b/gemfiles/Gemfile.rails-3.2.x.lock new file mode 100644 index 00000000..814d23d6 --- /dev/null +++ b/gemfiles/Gemfile.rails-3.2.x.lock @@ -0,0 +1,32 @@ +PATH + remote: .. + specs: + i18n (0.8.1) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (3.2.22.5) + i18n (~> 0.6, >= 0.6.4) + multi_json (~> 1.0) + metaclass (0.0.4) + minitest (5.10.1) + mocha (1.2.1) + metaclass (~> 0.0.1) + multi_json (1.12.1) + rake (12.0.0) + test_declarative (0.0.5) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport (~> 3.2.0) + i18n! + minitest + mocha + rake + test_declarative + +BUNDLED WITH + 1.14.6 diff --git a/gemfiles/Gemfile.rails-4.0.x.lock b/gemfiles/Gemfile.rails-4.0.x.lock new file mode 100644 index 00000000..cc881418 --- /dev/null +++ b/gemfiles/Gemfile.rails-4.0.x.lock @@ -0,0 +1,37 @@ +PATH + remote: .. + specs: + i18n (0.8.1) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (4.0.13) + i18n (~> 0.6, >= 0.6.9) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + metaclass (0.0.4) + minitest (4.7.5) + mocha (1.2.1) + metaclass (~> 0.0.1) + multi_json (1.12.1) + rake (12.0.0) + test_declarative (0.0.5) + thread_safe (0.3.6) + tzinfo (0.3.53) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport (~> 4.0.0) + i18n! + minitest + mocha + rake + test_declarative + +BUNDLED WITH + 1.14.6 diff --git a/gemfiles/Gemfile.rails-4.1.x.lock b/gemfiles/Gemfile.rails-4.1.x.lock new file mode 100644 index 00000000..2ee39520 --- /dev/null +++ b/gemfiles/Gemfile.rails-4.1.x.lock @@ -0,0 +1,38 @@ +PATH + remote: .. + specs: + i18n (0.8.1) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (4.1.16) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + json (1.8.6) + metaclass (0.0.4) + minitest (5.10.1) + mocha (1.2.1) + metaclass (~> 0.0.1) + rake (12.0.0) + test_declarative (0.0.5) + thread_safe (0.3.6) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport (~> 4.1.0) + i18n! + minitest + mocha + rake + test_declarative + +BUNDLED WITH + 1.14.6 diff --git a/gemfiles/Gemfile.rails-4.2.x.lock b/gemfiles/Gemfile.rails-4.2.x.lock new file mode 100644 index 00000000..68fb4b36 --- /dev/null +++ b/gemfiles/Gemfile.rails-4.2.x.lock @@ -0,0 +1,36 @@ +PATH + remote: .. + specs: + i18n (0.8.1) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (4.2.8) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + metaclass (0.0.4) + minitest (5.10.1) + mocha (1.2.1) + metaclass (~> 0.0.1) + rake (12.0.0) + test_declarative (0.0.5) + thread_safe (0.3.6) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport (~> 4.2.0) + i18n! + minitest + mocha + rake + test_declarative + +BUNDLED WITH + 1.14.6 diff --git a/gemfiles/Gemfile.rails-5.0.x.lock b/gemfiles/Gemfile.rails-5.0.x.lock new file mode 100644 index 00000000..025def22 --- /dev/null +++ b/gemfiles/Gemfile.rails-5.0.x.lock @@ -0,0 +1,37 @@ +PATH + remote: .. + specs: + i18n (0.8.1) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (5.0.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + concurrent-ruby (1.0.5) + metaclass (0.0.4) + minitest (5.10.1) + mocha (1.2.1) + metaclass (~> 0.0.1) + rake (12.0.0) + test_declarative (0.0.5) + thread_safe (0.3.6) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport (~> 5.0.0) + i18n! + minitest + mocha + rake + test_declarative + +BUNDLED WITH + 1.14.6 diff --git a/gemfiles/Gemfile.rails-master.lock b/gemfiles/Gemfile.rails-master.lock new file mode 100644 index 00000000..c1b87db7 --- /dev/null +++ b/gemfiles/Gemfile.rails-master.lock @@ -0,0 +1,43 @@ +GIT + remote: git://github.com/rails/rails.git + revision: 49aa974ec8b15721d53b3b6abea88bd6ba433a68 + branch: master + specs: + activesupport (5.1.0.alpha) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + +PATH + remote: .. + specs: + i18n (0.8.1) + +GEM + remote: https://rubygems.org/ + specs: + concurrent-ruby (1.0.5) + metaclass (0.0.4) + minitest (5.10.1) + mocha (1.2.1) + metaclass (~> 0.0.1) + rake (12.0.0) + test_declarative (0.0.5) + thread_safe (0.3.6) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport! + i18n! + minitest + mocha + rake + test_declarative + +BUNDLED WITH + 1.14.6 From d103f48327f4eaaa59a9e59a2fe04c52fadcb54a Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 24 Mar 2017 12:32:42 +1100 Subject: [PATCH 32/45] Bump to 0.8.2 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index 439d9366..25e8c4d6 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.8.1" + VERSION = "0.8.2" end From 1ba0ac378b0782515034ab89a4a23a5f32958702 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Fri, 24 Mar 2017 12:34:21 +1100 Subject: [PATCH 33/45] Bump Gemfiles --- gemfiles/Gemfile.rails-3.2.x.lock | 2 +- gemfiles/Gemfile.rails-4.0.x.lock | 2 +- gemfiles/Gemfile.rails-4.1.x.lock | 2 +- gemfiles/Gemfile.rails-4.2.x.lock | 2 +- gemfiles/Gemfile.rails-5.0.x.lock | 2 +- gemfiles/Gemfile.rails-master.lock | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gemfiles/Gemfile.rails-3.2.x.lock b/gemfiles/Gemfile.rails-3.2.x.lock index 814d23d6..ad459040 100644 --- a/gemfiles/Gemfile.rails-3.2.x.lock +++ b/gemfiles/Gemfile.rails-3.2.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.8.1) + i18n (0.8.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.rails-4.0.x.lock b/gemfiles/Gemfile.rails-4.0.x.lock index cc881418..e6f9f26e 100644 --- a/gemfiles/Gemfile.rails-4.0.x.lock +++ b/gemfiles/Gemfile.rails-4.0.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.8.1) + i18n (0.8.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.rails-4.1.x.lock b/gemfiles/Gemfile.rails-4.1.x.lock index 2ee39520..23e12631 100644 --- a/gemfiles/Gemfile.rails-4.1.x.lock +++ b/gemfiles/Gemfile.rails-4.1.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.8.1) + i18n (0.8.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.rails-4.2.x.lock b/gemfiles/Gemfile.rails-4.2.x.lock index 68fb4b36..4c761938 100644 --- a/gemfiles/Gemfile.rails-4.2.x.lock +++ b/gemfiles/Gemfile.rails-4.2.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.8.1) + i18n (0.8.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.rails-5.0.x.lock b/gemfiles/Gemfile.rails-5.0.x.lock index 025def22..a5293d1f 100644 --- a/gemfiles/Gemfile.rails-5.0.x.lock +++ b/gemfiles/Gemfile.rails-5.0.x.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n (0.8.1) + i18n (0.8.2) GEM remote: https://rubygems.org/ diff --git a/gemfiles/Gemfile.rails-master.lock b/gemfiles/Gemfile.rails-master.lock index c1b87db7..1a4c4d05 100644 --- a/gemfiles/Gemfile.rails-master.lock +++ b/gemfiles/Gemfile.rails-master.lock @@ -12,7 +12,7 @@ GIT PATH remote: .. specs: - i18n (0.8.1) + i18n (0.8.2) GEM remote: https://rubygems.org/ From 162934a2515da08ec8dfe8d22cbafd39694ebfa1 Mon Sep 17 00:00:00 2001 From: DM Date: Wed, 10 May 2017 14:58:41 +0300 Subject: [PATCH 34/45] Handle false as a key correctly --- lib/i18n/backend/base.rb | 2 +- test/i18n_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 668a4221..124d9ef5 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -23,7 +23,7 @@ def store_translations(locale, data, options = {}) def translate(locale, key, options = {}) raise InvalidLocale.new(locale) unless locale - entry = key && lookup(locale, key, options[:scope], options) + entry = lookup(locale, key, options[:scope], options) unless key.nil? if entry.nil? && options.key?(:default) entry = default(locale, key, options[:default], options) diff --git a/test/i18n_test.rb b/test/i18n_test.rb index f92eefd4..0f72c299 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -6,6 +6,7 @@ def setup super store_translations(:en, :currency => { :format => { :separator => '.', :delimiter => ',', } }) store_translations(:nl, :currency => { :format => { :separator => ',', :delimiter => '.', } }) + store_translations(:en, "true" => "Yes", "false" => "No") end test "exposes its VERSION constant" do @@ -228,6 +229,14 @@ def setup end end + test "translate given true as a key works" do + assert_equal "Yes", I18n.t(true) + end + + test "translate given false as a key works" do + assert_equal "No", I18n.t(false) + end + test "available_locales can be replaced at runtime" do begin I18n.config.enforce_available_locales = true From fd50cac2e6a1bc3be9d3b2d8d27cc74d4c20b2fa Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 31 May 2017 08:37:58 +1000 Subject: [PATCH 35/45] Update Changelog --- CHANGELOG.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c4c74ab..af66dc98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ -# master +# 0.8.3 -* `Hash#slice` ignores non existing keys. +See https://github.com/svenfuchs/i18n/releases/tag/v0.8.3 + +# 0.8.2 + +See https://github.com/svenfuchs/i18n/releases/tag/v0.8.2 + +# 0.8.1 + +See https://github.com/svenfuchs/i18n/releases/tag/v0.8.1 # 0.8.0 From 1e658089382519a52bc19f82185bc29ddd453553 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 31 May 2017 08:38:15 +1000 Subject: [PATCH 36/45] Bump to 0.8.3 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index 25e8c4d6..a8da324b 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.8.2" + VERSION = "0.8.3" end From 062dcb090c297a1b13d784c920d86d1452506b95 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 31 May 2017 11:42:06 +1000 Subject: [PATCH 37/45] Revert "Don't allow nil to be submitted as a key to i18n.translate()" --- lib/i18n.rb | 4 ++-- lib/i18n/backend/fallbacks.rb | 2 +- lib/i18n/tests/defaults.rb | 6 +++--- lib/i18n/tests/pluralization.rb | 14 +++++++------- lib/i18n/tests/procs.rb | 24 ++++++++++++------------ test/backend/cascade_test.rb | 2 +- test/backend/chain_test.rb | 8 ++++---- test/backend/pluralization_test.rb | 10 +++++----- test/backend/simple_test.rb | 4 ++-- test/i18n_test.rb | 22 +++++----------------- 10 files changed, 42 insertions(+), 54 deletions(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index f696d913..565cb248 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -149,7 +149,7 @@ def translate(*args) handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise enforce_available_locales!(locale) - raise I18n::ArgumentError if key.nil? || (key.is_a?(String) && key.empty?) + raise I18n::ArgumentError if key.is_a?(String) && key.empty? result = catch(:exception) do if key.is_a?(Array) @@ -171,7 +171,7 @@ def translate!(key, options={}) # Returns true if a translation exists for a given key, otherwise returns false. def exists?(key, locale = config.locale) - raise I18n::ArgumentError if key.nil? || (key.is_a?(String) && key.empty?) + raise I18n::ArgumentError if key.is_a?(String) && key.empty? config.backend.exists?(locale, key) end diff --git a/lib/i18n/backend/fallbacks.rb b/lib/i18n/backend/fallbacks.rb index 50953a22..6cb36876 100644 --- a/lib/i18n/backend/fallbacks.rb +++ b/lib/i18n/backend/fallbacks.rb @@ -55,7 +55,7 @@ def translate(locale, key, options = {}) @fallback_locked = false end - return super(locale, key, options.merge(:default => default)) if default + return super(locale, nil, options.merge(:default => default)) if default throw(:exception, I18n::MissingTranslation.new(locale, key, options)) end diff --git a/lib/i18n/tests/defaults.rb b/lib/i18n/tests/defaults.rb index 85be98a5..08f92887 100644 --- a/lib/i18n/tests/defaults.rb +++ b/lib/i18n/tests/defaults.rb @@ -9,11 +9,11 @@ def setup end test "defaults: given nil as a key it returns the given default" do - assert_equal 'default', I18n.t(:does_not_exist, :default => 'default') + assert_equal 'default', I18n.t(nil, :default => 'default') end test "defaults: given a symbol as a default it translates the symbol" do - assert_equal 'bar', I18n.t(:does_not_exist, :default => :'foo.bar') + assert_equal 'bar', I18n.t(nil, :default => :'foo.bar') end test "defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do @@ -41,7 +41,7 @@ def setup test "defaults: using a custom scope separator" do # data must have been stored using the custom separator when using the ActiveRecord backend I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' }) - assert_equal 'bar', I18n.t(:does_not_exist, :default => :'foo|bar', :separator => '|') + assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|') end end end diff --git a/lib/i18n/tests/pluralization.rb b/lib/i18n/tests/pluralization.rb index 4055fe93..d3319dcd 100644 --- a/lib/i18n/tests/pluralization.rb +++ b/lib/i18n/tests/pluralization.rb @@ -4,31 +4,31 @@ module I18n module Tests module Pluralization test "pluralization: given 0 it returns the :zero translation if it is defined" do - assert_equal 'zero', I18n.t(:does_not_exist, :default => { :zero => 'zero' }, :count => 0) + assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0) end test "pluralization: given 0 it returns the :other translation if :zero is not defined" do - assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 0) + assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0) end test "pluralization: given 1 it returns the singular translation" do - assert_equal 'bar', I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => 1) + assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1) end test "pluralization: given 2 it returns the :other translation" do - assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 2) + assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2) end test "pluralization: given 3 it returns the :other translation" do - assert_equal 'bars', I18n.t(:does_not_exist, :default => { :other => 'bars' }, :count => 3) + assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3) end test "pluralization: given nil it returns the whole entry" do - assert_equal({ :one => 'bar' }, I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => nil)) + assert_equal({ :one => 'bar' }, I18n.t(:default => { :one => 'bar' }, :count => nil)) end test "pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do - assert_raise(I18n::InvalidPluralizationData) { I18n.t(:does_not_exist, :default => { :one => 'bar' }, :count => 2) } + assert_raise(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) } end end end diff --git a/lib/i18n/tests/procs.rb b/lib/i18n/tests/procs.rb index 9ad2793f..02db95cb 100644 --- a/lib/i18n/tests/procs.rb +++ b/lib/i18n/tests/procs.rb @@ -3,47 +3,47 @@ module I18n module Tests module Procs - test "lookup: given a translation is a Proc it calls the Proc with the key and interpolation values" do + test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }) assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo') end test "defaults: given a default is a Proc it calls it with the key and interpolation values" do proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) } - assert_equal '[:does_not_exist, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => proc, :foo => 'foo') + assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo') end test "defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do the_lambda = lambda { |*args| I18n::Tests::Procs.filter_args(*args) } I18n.backend.store_translations(:en, :a_lambda => the_lambda) - assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => :a_lambda, :foo => 'foo') - assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => [nil, :a_lambda], :foo => 'foo') + assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo') + assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo') end test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) } - assert_match %r(\[\{:foo=>#\}\]), I18n.t(:does_not_exist, :default => '%{foo}', :foo => proc) + assert_match %r(\[\{:foo=>#\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc) end test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do proc = lambda { |*args| "%{foo}: " + I18n::Tests::Procs.filter_args(*args) } - assert_equal 'foo: [:does_not_exist, {:foo=>"foo"}]', I18n.t(:does_not_exist, :default => proc, :foo => 'foo') + assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo') end test "pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do proc = lambda { |*args| { :zero => 'zero', :one => 'one', :other => 'other' } } - assert_equal 'zero', I18n.t(:does_not_exist, :default => proc, :count => 0) - assert_equal 'one', I18n.t(:does_not_exist, :default => proc, :count => 1) - assert_equal 'other', I18n.t(:does_not_exist, :default => proc, :count => 2) + assert_equal 'zero', I18n.t(:default => proc, :count => 0) + assert_equal 'one', I18n.t(:default => proc, :count => 1) + assert_equal 'other', I18n.t(:default => proc, :count => 2) end - test "lookup: given the option :resolve => false was passed it does not resolve Proc translations" do + test "lookup: given the option :resolve => false was passed it does not resolve proc translations" do I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }) assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class end - test "lookup: given the option :resolve => false was passed it does not resolve Proc default" do - assert_equal Proc, I18n.t(:does_not_exist, :default => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }, :resolve => false).class + test "lookup: given the option :resolve => false was passed it does not resolve proc default" do + assert_equal Proc, I18n.t(nil, :default => lambda { |*args| I18n::Tests::Procs.filter_args(*args) }, :resolve => false).class end diff --git a/test/backend/cascade_test.rb b/test/backend/cascade_test.rb index d1d0c4aa..11014605 100644 --- a/test/backend/cascade_test.rb +++ b/test/backend/cascade_test.rb @@ -39,7 +39,7 @@ def lookup(key, options = {}) end test "cascades defaults, too" do - assert_equal 'foo', lookup(:does_not_exist, :default => [:'missing.missing', :'missing.foo']) + assert_equal 'foo', lookup(nil, :default => [:'missing.missing', :'missing.foo']) end test "works with :offset => 2 and a single key" do diff --git a/test/backend/chain_test.rb b/test/backend/chain_test.rb index 61f8ca36..0b402af2 100644 --- a/test/backend/chain_test.rb +++ b/test/backend/chain_test.rb @@ -39,10 +39,10 @@ def setup end test "default" do - assert_equal 'Fuh', I18n.t(:does_not_exist, :default => 'Fuh') - assert_equal 'Zero', I18n.t(:does_not_exist, :default => { :zero => 'Zero' }, :count => 0) - assert_equal({ :zero => 'Zero' }, I18n.t(:does_not_exist, :default => { :zero => 'Zero' })) - assert_equal 'Foo', I18n.t(:does_not_exist, :default => :foo) + assert_equal 'Fuh', I18n.t(:default => 'Fuh') + assert_equal 'Zero', I18n.t(:default => { :zero => 'Zero' }, :count => 0) + assert_equal({ :zero => 'Zero' }, I18n.t(:default => { :zero => 'Zero' })) + assert_equal 'Foo', I18n.t(:default => :foo) end test 'default is returned if translation is missing' do diff --git a/test/backend/pluralization_test.rb b/test/backend/pluralization_test.rb index 12c5cbad..1518efdb 100644 --- a/test/backend/pluralization_test.rb +++ b/test/backend/pluralization_test.rb @@ -19,24 +19,24 @@ def setup end test "pluralization picks :one for 1" do - assert_equal 'one', I18n.t(:does_not_exist, :count => 1, :default => @entry, :locale => :xx) + assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :xx) end test "pluralization picks :few for 2" do - assert_equal 'few', I18n.t(:does_not_exist, :count => 2, :default => @entry, :locale => :xx) + assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :xx) end test "pluralization picks :many for 11" do - assert_equal 'many', I18n.t(:does_not_exist, :count => 11, :default => @entry, :locale => :xx) + assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :xx) end test "pluralization picks zero for 0 if the key is contained in the data" do - assert_equal 'zero', I18n.t(:does_not_exist, :count => 0, :default => @entry, :locale => :xx) + assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :xx) end test "pluralization picks few for 0 if the key is not contained in the data" do @entry.delete(:zero) - assert_equal 'few', I18n.t(:does_not_exist, :count => 0, :default => @entry, :locale => :xx) + assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx) end test "Fallbacks can pick up rules from fallback locales, too" do diff --git a/test/backend/simple_test.rb b/test/backend/simple_test.rb index f6f7886f..4d0c447f 100644 --- a/test/backend/simple_test.rb +++ b/test/backend/simple_test.rb @@ -8,8 +8,8 @@ def setup end # useful because this way we can use the backend with no key for interpolation/pluralization - test "simple backend translate: given an invalid key it still interpolates the default value" do - assert_equal "Hi David", I18n.t(:does_not_exist, :default => "Hi %{name}", :name => "David") + test "simple backend translate: given nil as a key it still interpolations the default value" do + assert_equal "Hi David", I18n.t(nil, :default => "Hi %{name}", :name => "David") end # loading translations diff --git a/test/i18n_test.rb b/test/i18n_test.rb index 0f72c299..39e98e53 100644 --- a/test/i18n_test.rb +++ b/test/i18n_test.rb @@ -216,10 +216,6 @@ def setup assert_raise(I18n::ArgumentError) { I18n.t("") } end - test "translate given nil as a key raises an I18n::ArgumentError" do - assert_raise(I18n::ArgumentError) { I18n.t(nil) } - end - test "translate given an unavailable locale rases an I18n::InvalidLocale" do begin I18n.config.enforce_available_locales = true @@ -262,14 +258,6 @@ def setup assert_equal false, I18n.exists?(:bogus) end - test "exists? given an empty string will raise an error" do - assert_raise(I18n::ArgumentError) { I18n.exists?("") } - end - - test "exists? given nil will raise an error" do - assert_raise(I18n::ArgumentError) { I18n.exists?(nil) } - end - test "exists? given an existing dot-separated key will return true" do assert_equal true, I18n.exists?('currency.format.delimiter') end @@ -417,7 +405,7 @@ def call(exception, locale, key, options); key; end I18n.config.enforce_available_locales = false end end - + test 'I18n.reload! reloads the set of locales that are enforced' do begin # Clear the backend that affects the available locales and somehow can remain @@ -425,9 +413,9 @@ def call(exception, locale, key, options); key; end # For instance, it contains enough translations to cause a false positive with # this test when ran with --seed=50992 I18n.backend = I18n::Backend::Simple.new - + assert !I18n.available_locales.include?(:de), "Available locales should not include :de at this point" - + I18n.enforce_available_locales = true assert_raise(I18n::InvalidLocale) { I18n.default_locale = :de } @@ -443,11 +431,11 @@ def call(exception, locale, key, options); key; end store_translations(:en, :foo => 'Foo in :en') store_translations(:de, :foo => 'Foo in :de') store_translations(:pl, :foo => 'Foo in :pl') - + assert I18n.available_locales.include?(:de), ":de should now be allowed" assert I18n.available_locales.include?(:en), ":en should now be allowed" assert I18n.available_locales.include?(:pl), ":pl should now be allowed" - + assert_nothing_raised { I18n.default_locale = I18n.locale = :en } assert_nothing_raised { I18n.default_locale = I18n.locale = :de } assert_nothing_raised { I18n.default_locale = I18n.locale = :pl } From 46d9432ce65ed0079a8f1e27e8d76451fa555951 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Wed, 31 May 2017 11:42:48 +1000 Subject: [PATCH 38/45] Bump to 0.8.4 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index a8da324b..dc1ebc2c 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.8.3" + VERSION = "0.8.4" end From ed3623f1a9a8eedd968ac5fd7040faccbb171547 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Mon, 5 Jun 2017 13:17:18 -0700 Subject: [PATCH 39/45] Improve error message for missing pluralization key The error message for InvalidPluralizationData should include the missing key that triggered the error. For non-default pluralization rules like the CLDR rules for many languages, the sought-for key will not be obvious from the count. Also, the force_invalid_pluralization_data method in exceptions_test was not actually raising an exception, so a few assertions that relied on it were not being tested. --- lib/i18n/backend/base.rb | 4 ++-- lib/i18n/backend/pluralization.rb | 2 +- lib/i18n/exceptions.rb | 8 ++++---- test/i18n/exceptions_test.rb | 15 +++++++++------ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb index 124d9ef5..c8bb070f 100644 --- a/lib/i18n/backend/base.rb +++ b/lib/i18n/backend/base.rb @@ -136,14 +136,14 @@ def resolve(locale, object, subject, options = {}) # - It will pick the :other subkey otherwise. # - It will pick the :zero subkey in the special case where count is # equal to 0 and there is a :zero subkey present. This behaviour is - # not stand with regards to the CLDR pluralization rules. + # not standard with regards to the CLDR pluralization rules. # Other backends can implement more flexible or complex pluralization rules. def pluralize(locale, entry, count) return entry unless entry.is_a?(Hash) && count key = :zero if count == 0 && entry.has_key?(:zero) key ||= count == 1 ? :one : :other - raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key) + raise InvalidPluralizationData.new(entry, count, key) unless entry.has_key?(key) entry[key] end diff --git a/lib/i18n/backend/pluralization.rb b/lib/i18n/backend/pluralization.rb index c73a009a..01e68d27 100644 --- a/lib/i18n/backend/pluralization.rb +++ b/lib/i18n/backend/pluralization.rb @@ -32,7 +32,7 @@ def pluralize(locale, entry, count) pluralizer = pluralizer(locale) if pluralizer.respond_to?(:call) key = count == 0 && entry.has_key?(:zero) ? :zero : pluralizer.call(count) - raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key) + raise InvalidPluralizationData.new(entry, count, key) unless entry.has_key?(key) entry[key] else super diff --git a/lib/i18n/exceptions.rb b/lib/i18n/exceptions.rb index c0d7477c..7e8b0d69 100644 --- a/lib/i18n/exceptions.rb +++ b/lib/i18n/exceptions.rb @@ -71,10 +71,10 @@ class MissingTranslationData < ArgumentError end class InvalidPluralizationData < ArgumentError - attr_reader :entry, :count - def initialize(entry, count) - @entry, @count = entry, count - super "translation data #{entry.inspect} can not be used with :count => #{count}" + attr_reader :entry, :count, :key + def initialize(entry, count, key) + @entry, @count, @key = entry, count, key + super "translation data #{entry.inspect} can not be used with :count => #{count}. key '#{key}' is missing." end end diff --git a/test/i18n/exceptions_test.rb b/test/i18n/exceptions_test.rb index 3e528c64..84e1c8fc 100644 --- a/test/i18n/exceptions_test.rb +++ b/test/i18n/exceptions_test.rb @@ -32,16 +32,19 @@ def test_invalid_locale_stores_locale end end - test "InvalidPluralizationData stores entry and count" do + test "InvalidPluralizationData stores entry, count and key" do force_invalid_pluralization_data do |exception| - assert_equal [:bar], exception.entry + assert_equal({:other => "bar"}, exception.entry) assert_equal 1, exception.count + assert_equal :one, exception.key end end - test "InvalidPluralizationData message contains count and data" do + test "InvalidPluralizationData message contains count, data and missing key" do force_invalid_pluralization_data do |exception| - assert_equal 'translation data [:bar] can not be used with :count => 1', exception.message + assert_match '1', exception.message + assert_match '{:other=>"bar"}', exception.message + assert_match 'one', exception.message end end @@ -71,7 +74,7 @@ def test_invalid_locale_stores_locale assert_equal 'reserved key :scope used in "%{scope}"', exception.message end end - + test "MissingTranslationData#new can be initialized with just two arguments" do assert I18n::MissingTranslationData.new('en', 'key') end @@ -92,7 +95,7 @@ def force_missing_translation_data(options = {}) end def force_invalid_pluralization_data - store_translations('de', :foo => [:bar]) + store_translations('de', :foo => { :other => 'bar' }) I18n.translate(:foo, :count => 1, :locale => :de) rescue I18n::ArgumentError => e block_given? ? yield(e) : raise(e) From 8762c2763d5e25b84608e8aca6cf89d028acdc88 Mon Sep 17 00:00:00 2001 From: DM Date: Tue, 13 Jun 2017 21:47:32 +0300 Subject: [PATCH 40/45] Remove gemfiles/Gemfile.*.lock from the repo --- gemfiles/Gemfile.rails-3.2.x.lock | 32 ---------------------- gemfiles/Gemfile.rails-4.0.x.lock | 37 ------------------------- gemfiles/Gemfile.rails-4.1.x.lock | 38 -------------------------- gemfiles/Gemfile.rails-4.2.x.lock | 36 ------------------------- gemfiles/Gemfile.rails-5.0.x.lock | 37 ------------------------- gemfiles/Gemfile.rails-master.lock | 43 ------------------------------ 6 files changed, 223 deletions(-) delete mode 100644 gemfiles/Gemfile.rails-3.2.x.lock delete mode 100644 gemfiles/Gemfile.rails-4.0.x.lock delete mode 100644 gemfiles/Gemfile.rails-4.1.x.lock delete mode 100644 gemfiles/Gemfile.rails-4.2.x.lock delete mode 100644 gemfiles/Gemfile.rails-5.0.x.lock delete mode 100644 gemfiles/Gemfile.rails-master.lock diff --git a/gemfiles/Gemfile.rails-3.2.x.lock b/gemfiles/Gemfile.rails-3.2.x.lock deleted file mode 100644 index ad459040..00000000 --- a/gemfiles/Gemfile.rails-3.2.x.lock +++ /dev/null @@ -1,32 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.2) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (3.2.22.5) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - multi_json (1.12.1) - rake (12.0.0) - test_declarative (0.0.5) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 3.2.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.14.6 diff --git a/gemfiles/Gemfile.rails-4.0.x.lock b/gemfiles/Gemfile.rails-4.0.x.lock deleted file mode 100644 index e6f9f26e..00000000 --- a/gemfiles/Gemfile.rails-4.0.x.lock +++ /dev/null @@ -1,37 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.2) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - metaclass (0.0.4) - minitest (4.7.5) - mocha (1.2.1) - metaclass (~> 0.0.1) - multi_json (1.12.1) - rake (12.0.0) - test_declarative (0.0.5) - thread_safe (0.3.6) - tzinfo (0.3.53) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 4.0.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.14.6 diff --git a/gemfiles/Gemfile.rails-4.1.x.lock b/gemfiles/Gemfile.rails-4.1.x.lock deleted file mode 100644 index 23e12631..00000000 --- a/gemfiles/Gemfile.rails-4.1.x.lock +++ /dev/null @@ -1,38 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.2) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (4.1.16) - i18n (~> 0.6, >= 0.6.9) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.1) - tzinfo (~> 1.1) - json (1.8.6) - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - rake (12.0.0) - test_declarative (0.0.5) - thread_safe (0.3.6) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 4.1.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.14.6 diff --git a/gemfiles/Gemfile.rails-4.2.x.lock b/gemfiles/Gemfile.rails-4.2.x.lock deleted file mode 100644 index 4c761938..00000000 --- a/gemfiles/Gemfile.rails-4.2.x.lock +++ /dev/null @@ -1,36 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.2) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (4.2.8) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - rake (12.0.0) - test_declarative (0.0.5) - thread_safe (0.3.6) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 4.2.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.14.6 diff --git a/gemfiles/Gemfile.rails-5.0.x.lock b/gemfiles/Gemfile.rails-5.0.x.lock deleted file mode 100644 index a5293d1f..00000000 --- a/gemfiles/Gemfile.rails-5.0.x.lock +++ /dev/null @@ -1,37 +0,0 @@ -PATH - remote: .. - specs: - i18n (0.8.2) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (5.0.2) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - concurrent-ruby (1.0.5) - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - rake (12.0.0) - test_declarative (0.0.5) - thread_safe (0.3.6) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport (~> 5.0.0) - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.14.6 diff --git a/gemfiles/Gemfile.rails-master.lock b/gemfiles/Gemfile.rails-master.lock deleted file mode 100644 index 1a4c4d05..00000000 --- a/gemfiles/Gemfile.rails-master.lock +++ /dev/null @@ -1,43 +0,0 @@ -GIT - remote: git://github.com/rails/rails.git - revision: 49aa974ec8b15721d53b3b6abea88bd6ba433a68 - branch: master - specs: - activesupport (5.1.0.alpha) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - -PATH - remote: .. - specs: - i18n (0.8.2) - -GEM - remote: https://rubygems.org/ - specs: - concurrent-ruby (1.0.5) - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - rake (12.0.0) - test_declarative (0.0.5) - thread_safe (0.3.6) - tzinfo (1.2.2) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activesupport! - i18n! - minitest - mocha - rake - test_declarative - -BUNDLED WITH - 1.14.6 From abd1ae0d105e96f6ee2c68aece0e0851b0e69ff0 Mon Sep 17 00:00:00 2001 From: Chad Schroeder Date: Wed, 14 Jun 2017 14:06:32 -0500 Subject: [PATCH 41/45] Fixes #369 thread issue when calling translate with fallbacks --- lib/i18n/backend/fallbacks.rb | 6 +++--- lib/i18n/tests/localization/procs.rb | 2 +- lib/i18n/tests/procs.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/i18n/backend/fallbacks.rb b/lib/i18n/backend/fallbacks.rb index 6cb36876..7a49fa2c 100644 --- a/lib/i18n/backend/fallbacks.rb +++ b/lib/i18n/backend/fallbacks.rb @@ -36,11 +36,11 @@ module Fallbacks # it is evaluated last after all the fallback locales have been tried. def translate(locale, key, options = {}) return super unless options.fetch(:fallback, true) - return super if (@fallback_locked ||= false) + return super if options[:fallback_in_progress] default = extract_non_symbol_default!(options) if options[:default] begin - @fallback_locked = true + options[:fallback_in_progress] = true I18n.fallbacks[locale].each do |fallback| begin catch(:exception) do @@ -52,7 +52,7 @@ def translate(locale, key, options = {}) end end ensure - @fallback_locked = false + options.delete(:fallback_in_progress) end return super(locale, nil, options.merge(:default => default)) if default diff --git a/lib/i18n/tests/localization/procs.rb b/lib/i18n/tests/localization/procs.rb index bdfa9480..de624888 100644 --- a/lib/i18n/tests/localization/procs.rb +++ b/lib/i18n/tests/localization/procs.rb @@ -72,7 +72,7 @@ def self.inspect_args(args) when ::Date arg.strftime('%a, %d %b %Y') when Hash - arg.delete(:fallback) + arg.delete(:fallback_in_progress) arg.inspect else arg.inspect diff --git a/lib/i18n/tests/procs.rb b/lib/i18n/tests/procs.rb index 02db95cb..aa2df19a 100644 --- a/lib/i18n/tests/procs.rb +++ b/lib/i18n/tests/procs.rb @@ -48,7 +48,7 @@ module Procs def self.filter_args(*args) - args.map {|arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect + args.map {|arg| arg.delete(:fallback_in_progress) if arg.is_a?(Hash) ; arg }.inspect end end end From 260149b1683bffa4539dae9b1aa297de4c0786ac Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 8 Jul 2017 10:44:39 +1000 Subject: [PATCH 42/45] Bump to 0.8.5 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index dc1ebc2c..900e0368 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.8.4" + VERSION = "0.8.5" end From 09f806539c26157643c4cf1264ae5bde00c90178 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 10 Jul 2017 15:24:42 +1000 Subject: [PATCH 43/45] Add fallback_in_progress to RESERVED_KEYS list Fixes #378 --- lib/i18n.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n.rb b/lib/i18n.rb index 565cb248..8c1c9de6 100644 --- a/lib/i18n.rb +++ b/lib/i18n.rb @@ -9,7 +9,7 @@ module I18n autoload :Locale, 'i18n/locale' autoload :Tests, 'i18n/tests' - RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :throw, :raise, :deep_interpolation] + RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :fallback_in_progress, :format, :cascade, :throw, :raise, :deep_interpolation] RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/ module Base From bd0819c824edbad0797f048bcc5afe9bc862053b Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 10 Jul 2017 15:39:03 +1000 Subject: [PATCH 44/45] Bump to 0.8.6 --- lib/i18n/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb index 900e0368..fbd6c5a3 100644 --- a/lib/i18n/version.rb +++ b/lib/i18n/version.rb @@ -1,3 +1,3 @@ module I18n - VERSION = "0.8.5" + VERSION = "0.8.6" end From 6ab51c78be833eb011d5b4d3f5b2c54e74847512 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Tue, 11 Jul 2017 10:04:16 +1000 Subject: [PATCH 45/45] Add regression test for #378 --- test/backend/fallbacks_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/backend/fallbacks_test.rb b/test/backend/fallbacks_test.rb index 2b1eedb0..9a44c143 100644 --- a/test/backend/fallbacks_test.rb +++ b/test/backend/fallbacks_test.rb @@ -8,7 +8,7 @@ class Backend < I18n::Backend::Simple def setup super I18n.backend = Backend.new - store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en') + store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en', :interpolate => 'Interpolate %{value}') store_translations(:de, :bar => 'Bar in :de', :baz => 'Baz in :de') store_translations(:'de-DE', :baz => 'Baz in :de-DE') store_translations(:'pt-BR', :baz => 'Baz in :pt-BR') @@ -20,6 +20,10 @@ def setup assert_equal 'Baz in :de-DE', I18n.t(:baz, :locale => :'de-DE') end + test "returns interpolated value if no key provided" do + assert_equal 'Interpolate %{value}', I18n.t(:interpolate) + end + test "returns the :en translation for a missing :de translation" do assert_equal 'Foo in :en', I18n.t(:foo, :locale => :de) end