Introduce I18nConfig as single point of truth

It will be used in application.rb and views.
See https://github.com/openfoodfoundation/openfoodnetwork/issues/2113
This commit is contained in:
Maikel Linke
2018-03-09 16:38:41 +11:00
parent b5a8df00dd
commit 7a34c6e3f0
2 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
module OpenFoodNetwork
# Provides access to the language settings.
# Currently, language settings are read from the environment.
# See: config/application.yml
class I18nConfig
def self.selectable_locales
ENV["AVAILABLE_LOCALES"].andand.split(/[\s,]/).andand.map(&:strip) || []
end
def self.available_locales
(selectable_locales + [default_locale, 'en']).uniq
end
def self.default_locale
ENV["LOCALE"] || ENV["I18N_LOCALE"] || source_locale
end
def self.source_locale
"en"
end
end
end