From 05d757e7c4637a0b5eb77f488cc823687c79c3a2 Mon Sep 17 00:00:00 2001 From: Saimon Moore Date: Thu, 19 Oct 2017 12:23:03 +0200 Subject: [PATCH] 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. --- config/application.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index e58c7e8115..d5b30e9930 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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