Skip to content

Commit

Permalink
fix LazyLoadable#available_locales duplicating locales
Browse files Browse the repository at this point in the history
Sometimes locales will be split across multiple files.
LazyLoadable explicitly supports that, either by using multiple
file types, or post-fixing the locale name with an _ and a descriptor.

But even so, there should only be one instance in available_locales.
  • Loading branch information
ccutrer committed Mar 29, 2023
1 parent b4cd00d commit 2acc3f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/i18n/backend/lazy_loadable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def eager_load!
# Parse the load path and extract all locales.
def available_locales
if lazy_load?
I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) }
I18n.load_path.map { |path| LocaleExtractor.locale_from_path(path) }.uniq
else
super
end
Expand Down
2 changes: 1 addition & 1 deletion test/backend/lazy_loadable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def setup
@lazy_mode_backend = I18n::Backend::LazyLoadable.new(lazy_load: true)
@eager_mode_backend = I18n::Backend::LazyLoadable.new(lazy_load: false)

I18n.load_path = [File.join(locales_dir, '/en.yml'), File.join(locales_dir, '/fr.yml')]
I18n.load_path = [File.join(locales_dir, '/en.yml'), File.join(locales_dir, '/en.yaml'), File.join(locales_dir, '/fr.yml')]
end

test "lazy mode: only loads translations for current locale" do
Expand Down

0 comments on commit 2acc3f4

Please sign in to comment.