Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default: nil with fallbacks #387

Merged
merged 1 commit into from Oct 10, 2017

Conversation

daniel-rikowski
Copy link

Fixes #386

Copy link
Collaborator

@radar radar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. Thanks for fixing this bug and cleaning up the code.

@radar radar added this to the 0.9.0 milestone Oct 10, 2017
@radar radar merged commit 2ae3b70 into ruby-i18n:master Oct 10, 2017
@radar
Copy link
Collaborator

radar commented Oct 10, 2017

This will go out in the 0.9.0 release, probably next week or week after.

@rafaelfranca
Copy link
Contributor

This change introduce a regression. Here is the regression test:

diff --git a/test/backend/fallbacks_test.rb b/test/backend/fallbacks_test.rb
index 23e4713..a220c03 100644
--- a/test/backend/fallbacks_test.rb
+++ b/test/backend/fallbacks_test.rb
@@ -64,6 +64,10 @@ class I18nBackendFallbacksTranslateTest < I18n::TestCase
     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

@rafaelfranca
Copy link
Contributor

Failure message:

  1) Failure:
I18nBackendFallbacksTranslateTest#test_returns_the_translation_missing_message_if_the_default_is_also_missing [/Users/rafaelfranca/src/github/i18n/test/backend/fallbacks_test.rb:68]:
--- expected
+++ actual
@@ -1 +1 @@
-"translation missing: de-DE.missing_bar"
+"translation missing: de-DE.no key"

@rafaelfranca
Copy link
Contributor

#389 should fix that regression.

radar pushed a commit to rafaelfranca/i18n that referenced this pull request Nov 2, 2017
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.
@matheussilvasantos
Copy link

Can I force it to return nil or my default value even if the fallback translation exists? I'm trying to upgrade the gem on the application I'm working on, but we rely on this nil behaviour.

@daniel-rikowski daniel-rikowski deleted the default-nil-fallbacks branch May 25, 2022 16:10
@daniel-rikowski
Copy link
Author

Try using fallback: false, it skips all the fallback code. (See https://github.com/ruby-i18n/i18n/blob/master/lib/i18n/backend/fallbacks.rb#L42)

@matheussilvasantos
Copy link

Awesome! Thanks @daniel-rikowski.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default: nil breaks fallbacks
4 participants