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
Class Method Summary collapse
Class Method Details
.configure_i18n(i18n_config: nil, additional_components: []) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/worldwide/config.rb', line 22 def configure_i18n(i18n_config: nil, additional_components: []) 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) add_other_data(i18n_config) i18n_config end |
.exception_handler ⇒ Object
51 52 53 |
# File 'lib/worldwide/config.rb', line 51 def exception_handler Worldwide::I18nExceptionHandler.new end |