Module: Worldwide::Config
- Defined in:
- lib/worldwide/config.rb
Constant Summary collapse
- REQUIRED_CLDR_DATA =
The list of CLDR data components needed by this gem Users can add more data components to this list if they want to use them
[ "calendars", "context_transforms", "currencies", "languages", "layout", "lists", "numbers", "plurals", "subdivisions", "territories", "units", ].freeze
- CLDR_LOCALE_PATH_REGEX =
/locales#{File::SEPARATOR}(?<locale>[\w-]+)#{File::SEPARATOR}(?<component>\w+)\.(?:yml|rb)/- OTHER_LOCALE_PATH_REGEX =
/#{File::SEPARATOR}(?<locale>[\w-]+)\.(?:yml|rb)/- REGIONS_LOCALE_PATH_REGEX =
/#{File::SEPARATOR}(?<locale>[\w-]+)\.yml/
Class Method Summary collapse
- .configure_i18n(i18n_config: nil, additional_components: [], ignore_precomputed_paths: false) ⇒ Object
- .exception_handler ⇒ Object
Class Method Details
.configure_i18n(i18n_config: nil, additional_components: [], ignore_precomputed_paths: false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/worldwide/config.rb', line 26 def configure_i18n(i18n_config: nil, additional_components: [], ignore_precomputed_paths: false) i18n_config ||= I18n.config I18n::Backend::Simple.include( I18n::Backend::Fallbacks, I18n::Backend::Pluralization, ) # Setting enforce_available_locales to true means that we'll get I18n::InvalidLocale exceptions # when trying to do anything in a locale that's not part of the configured I18n.available_locales. # We default to setting this because we'd rather raise an exception than have API calls silently # return nonsensical results. # # A quirk of ruby-i18n/i18n is that @@enforce_available_locales is always set to true: # https://github.com/ruby-i18n/i18n/blob/5eeaad7fb35f9a30f654e3bdeb6933daa7fd421d/lib/i18n/config.rb#L140 # set_unless_explicitly_set(i18n_config, :enforce_available_locales, true) set_unless_explicitly_set(i18n_config, :default_locale, :en) set_unless_explicitly_set(i18n_config, :exception_handler, exception_handler) i18n_config.available_locales = (i18n_config) add_cldr_data(i18n_config, additional_components: additional_components, ignore_precomputed_paths: ignore_precomputed_paths) add_other_data(i18n_config, ignore_precomputed_paths: ignore_precomputed_paths) i18n_config end |
.exception_handler ⇒ Object
55 56 57 |
# File 'lib/worldwide/config.rb', line 55 def exception_handler Worldwide::I18nExceptionHandler.new end |