Skip to content

Commit

Permalink
Ensure documentation for fallbacks reflects reality
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Jul 14, 2020
1 parent f59c50f commit dfd1e29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/locale/fallbacks.rb
Expand Up @@ -26,7 +26,7 @@
#
# I18n.default_locale = :"en-US"
# I18n.fallbacks = I18n::Locale::Fallbacks.new(:"de-AT" => :"de-DE")
# I18n.fallbacks[:"de-AT"] # => [:"de-AT", :"de-DE", :de, :"en-US", :en]
# I18n.fallbacks[:"de-AT"] # => [:"de-AT", :de, :"de-DE"]
#
# # using a custom locale as default fallback locale
#
Expand Down
13 changes: 13 additions & 0 deletions test/locale/fallbacks_test.rb
Expand Up @@ -9,6 +9,19 @@ class I18nFallbacksDefaultsTest < I18n::TestCase
assert_equal [], fallbacks.defaults
end

test "documentation example #1 - does not use default locale in fallbacks - See Issues #413 & #415" do
I18n.default_locale = :"en-US"
fallbacks = Fallbacks.new(:"de-AT" => :"de-DE")
assert_equal [:"de-AT", :de, :"de-DE"], fallbacks[:"de-AT"]
end

test "documentation example #2 - does not use default locale in fallbacks - Uses custom locale - See Issues #413 & #415" do
I18n.default_locale = :"en-US"
fallbacks = Fallbacks.new(:"en-GB", :"de-AT" => :de, :"de-CH" => :de)
assert_equal [:"de-AT", :de, :"en-GB", :en], fallbacks[:"de-AT"]
assert_equal [:"de-CH", :de, :"en-GB", :en], fallbacks[:"de-CH"]
end

test "defaults reflect a manually passed default locale if any" do
fallbacks = Fallbacks.new(:'fi-FI')
assert_equal [:'fi-FI', :fi], fallbacks.defaults
Expand Down

0 comments on commit dfd1e29

Please sign in to comment.