From bf22484addda5d8c1b5155adfa14155f834a7963 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 18 Mar 2026 14:15:11 +1100 Subject: [PATCH] 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. --- config/application.rb | 5 +---- lib/open_food_network/i18n_config.rb | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 506430dc1f..f20dfa9010 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/lib/open_food_network/i18n_config.rb b/lib/open_food_network/i18n_config.rb index d0d71d0450..6c132442d5 100644 --- a/lib/open_food_network/i18n_config.rb +++ b/lib/open_food_network/i18n_config.rb @@ -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