mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
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:
22
lib/open_food_network/i18n_config.rb
Normal file
22
lib/open_food_network/i18n_config.rb
Normal 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
|
||||
Reference in New Issue
Block a user