Add default locale to fallbacks

The comment about falling back to the default locale came from the first
commit, when the config was just `fallbacks = true`. The fallback logic
is a lot more sophisticated now and we can supply the country's default
locale as first fallback and our source locale `en` as last resort. It
should contain everything.

In the future, we may want to support maps like Canadian French can fall
back to original French. I18n supports this but providing the config per
isntance may be a bit tricky.
This commit is contained in:
Maikel Linke
2026-03-18 14:15:11 +11:00
parent 1696dd2de6
commit bf22484add
2 changed files with 5 additions and 4 deletions

View File

@@ -161,12 +161,9 @@ module Openfoodnetwork
# The default locale is set in the environment.
config.i18n.default_locale = OpenFoodNetwork::I18nConfig.default_locale
config.i18n.available_locales = OpenFoodNetwork::I18nConfig.available_locales
config.i18n.fallbacks = OpenFoodNetwork::I18nConfig.fallbacks
I18n.locale = config.i18n.locale = config.i18n.default_locale
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = [:en]
# Calculate digests for locale files so we can know when they change
I18nDigests.build_digests config.i18n.available_locales

View File

@@ -20,6 +20,10 @@ module OpenFoodNetwork
(selectable_locales + [default_locale, source_locale]).uniq
end
def self.fallbacks
[default_locale, source_locale].uniq
end
# The default locale that is used when the user doesn't have a preference.
def self.default_locale
ENV["LOCALE"] || ENV["I18N_LOCALE"] || source_locale