Skip to content

Commit

Permalink
Merge pull request #2477 from tvdeyen/respect-application-available-l…
Browse files Browse the repository at this point in the history
…ocales

Respect available locales set in application
  • Loading branch information
tvdeyen authored May 25, 2023
2 parents 945b753 + 7f663b8 commit 0b21a53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/alchemy/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ def translate(msg, **options)
end

def available_locales
@@available_locales ||= nil
@@available_locales || translation_files.collect { |f|
f.match(LOCALE_FILE_PATTERN)[1].to_sym
}.uniq.sort
Rails.application.config.i18n.available_locales || begin
@@available_locales ||= nil
@@available_locales || translation_files.collect { |f|
f.match(LOCALE_FILE_PATTERN)[1].to_sym
}.uniq.sort
end
end

def available_locales=(locales)
Expand Down
7 changes: 7 additions & 0 deletions spec/libraries/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ module Alchemy
it { is_expected.to be_a Array }
it { is_expected.to include(:en) }

context "when locales are already set in application available_locales" do
it "returns them" do
expect(Rails.application.config.i18n).to receive(:available_locales) { [:de, :it] }
is_expected.to match_array([:de, :it])
end
end

context "when locales are already set in @@available_locales" do
before { I18n.class_variable_set(:@@available_locales, [:kl, :jp]) }
it { is_expected.to match_array([:kl, :jp]) }
Expand Down

0 comments on commit 0b21a53

Please sign in to comment.