Skip to content

Commit

Permalink
Fix 18n fallback when "mount_at_root" is false (#2602)
Browse files Browse the repository at this point in the history
* Fix fallback locale with "mount_at_root: false"

ruby-i18n does not add the default_locale to the list of fallbacks
anymore since v1.1.0. This breaks fallbacks when "mount_at_root"
config options is set to "false". Fixed this by explicitly adding
the default_locale to the list of fallbacks.

* Added translation fallbacks test with "mount_at_root: false"

---------

Co-authored-by: phernandez <pedrohdezmlg@gmail.com>
  • Loading branch information
guillerodriguez and phvega committed Feb 7, 2023
1 parent 7ca4c42 commit 17e647f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions middleman-core/features/i18n_builder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ Feature: i18n Builder
| hello.html |
And the file "en/index.html" should contain "Howdy"
And the file "en/hello.html" should contain "Hello World"
And the file "en/fallback.html" should contain "Fallback"
And the file "es/index.html" should contain "Como Esta?"
And the file "es/hola.html" should contain "Hola World"
And the file "es/fallback.html" should contain "Fallback"

Scenario: Running localize with the subset config
Given a fixture app "i18n-test-app"
Expand Down
1 change: 1 addition & 0 deletions middleman-core/fixtures/i18n-test-app/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ en:
greetings: "Howdy"
hi: "Hello"
tac: "Terms & Conditions"
fallback: "Fallback"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= I18n.t(:fallback) %>
2 changes: 1 addition & 1 deletion middleman-core/lib/middleman-core/core_extensions/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def configure_i18n
::I18n.default_locale = @mount_at_root

# Reset fallbacks to fall back to our new default
::I18n.fallbacks = ::I18n::Locale::Fallbacks.new if ::I18n.respond_to?(:fallbacks)
::I18n.fallbacks = ::I18n::Locale::Fallbacks.new(::I18n.default_locale) if ::I18n.respond_to?(:fallbacks)
end

Contract ArrayOf[Symbol]
Expand Down

0 comments on commit 17e647f

Please sign in to comment.