mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Ensure we have min i18n fallbacks
This setting defines which locales will be exported to the frontend. In general, ofn currently functions under a single locale (which is also the default locale) but all translations are made from the `en` locale. The current process of ensuring translations are translated and make their way into code is manual and prone to issues so occasionally translations for keys in the default locale of a particular instance are not deployed and the UI displays `missing translation` messages. In these cases, it is far friendlier for the user to see fallbacks to `en` rather than these errors so this commit ensure that at the very least apart from the current default locale, `en` is also made available and as such will be exported to the frontend so that it's translations are available as a fallback in JS land. I18n fallback config was already enabled in both frontend and backend. Until now, available locales may not have been set (determined by the `AVAILABLE_LOCALES` env var) and the translations for `en` not therefore be present in the frontend for fallback to actually work. This commit will ensure that a fallback to `en` is always possible in the case of missing translations.
This commit is contained in:
@@ -98,7 +98,8 @@ module Openfoodnetwork
|
||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||
config.i18n.default_locale = ENV["LOCALE"] || ENV["I18N_LOCALE"] || "en"
|
||||
config.i18n.available_locales = ENV["AVAILABLE_LOCALES"].andand.split(',').andand.map(&:strip) || [config.i18n.default_locale]
|
||||
config.i18n.available_locales = ENV["AVAILABLE_LOCALES"].andand.split(/[\s,]/).andand.map(&:strip) || []
|
||||
config.i18n.available_locales = (config.i18n.available_locales + [config.i18n.default_locale, 'en']).uniq
|
||||
I18n.locale = config.i18n.locale = config.i18n.default_locale
|
||||
|
||||
# Setting this to true causes a performance regression in Rails 3.2.17
|
||||
|
||||
Reference in New Issue
Block a user