From 2acc3f4868940d105d6b0e4ccd05ba6016a8fce7 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Wed, 29 Mar 2023 15:18:31 -0600 Subject: [PATCH] fix LazyLoadable#available_locales duplicating locales 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. --- lib/i18n/backend/lazy_loadable.rb | 2 +- test/backend/lazy_loadable_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/i18n/backend/lazy_loadable.rb b/lib/i18n/backend/lazy_loadable.rb index 60f21fa1..575b32bf 100644 --- a/lib/i18n/backend/lazy_loadable.rb +++ b/lib/i18n/backend/lazy_loadable.rb @@ -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 diff --git a/test/backend/lazy_loadable_test.rb b/test/backend/lazy_loadable_test.rb index a15ab009..01e2efcc 100644 --- a/test/backend/lazy_loadable_test.rb +++ b/test/backend/lazy_loadable_test.rb @@ -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