Skip to content

Commit

Permalink
Keep the translation missing message when default is not nil
Browse files Browse the repository at this point in the history
When either the key and the all the defaults have missing translation we
should be showing the original key in the translation missing message.

Before this commit we were showing a translation missing error in the
"no key" key.

This commit fixes a regression introduced in ruby-i18n#387.
  • Loading branch information
rafaelfranca authored and Ryan Bigg committed Nov 2, 2017
1 parent 939bb23 commit 4104295
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/i18n/backend/fallbacks.rb
Expand Up @@ -37,8 +37,7 @@ module Fallbacks
def translate(locale, key, options = {})
return super unless options.fetch(:fallback, true)
return super if options[:fallback_in_progress]
original_default = options[:default]
extract_non_symbol_default!(options)
default = extract_non_symbol_default!(options) if options[:default]

begin
options[:fallback_in_progress] = true
Expand All @@ -56,7 +55,9 @@ def translate(locale, key, options = {})
options.delete(:fallback_in_progress)
end

return super(locale, nil, options.merge(:default => original_default)) if options.key?(:default)
return if options.key?(:default) && options[:default].nil?

return super(locale, nil, options.merge(:default => default)) if default
throw(:exception, I18n::MissingTranslation.new(locale, key, options))
end

Expand Down
4 changes: 4 additions & 0 deletions test/backend/fallbacks_test.rb
Expand Up @@ -64,6 +64,10 @@ def setup
assert_nil I18n.t(:missing_bar, :locale => :'de-DE', :default => nil)
end

test "returns the translation missing message if the default is also missing" do
assert_equal 'translation missing: de-DE.missing_bar', I18n.t(:missing_bar, :locale => :'de-DE', :default => [:missing_baz])
end

test "returns the :'de-DE' default :baz translation for a missing :'de-DE' when defaults contains Symbol" do
assert_equal 'Baz in :de-DE', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:baz, "Default Bar"])
end
Expand Down

0 comments on commit 4104295

Please sign in to comment.