Class: Hanami::Providers::I18n Private
- Inherits:
-
Hanami::Provider::Source
- Object
- Dry::System::Provider::Source
- Hanami::Provider::Source
- Hanami::Providers::I18n
- Defined in:
- lib/hanami/providers/i18n.rb,
lib/hanami/providers/i18n/backend.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: Backend
Constant Summary collapse
- SLICE_CONFIGURED_SETTINGS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[ default_locale available_locales load_path shared_load_path fallbacks ].freeze
- DEFAULT_LOCALE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:en- DEFAULT_AVAILABLE_LOCALES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[].freeze
- DEFAULT_LOAD_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
["config/i18n/**/*.{yml,yaml,json,rb}"].freeze
- DEFAULT_SHARED_LOAD_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
["config/i18n/shared/**/*.{yml,yaml,json,rb}"].freeze
- BUNDLED_DEFAULTS_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Built-in English baseline for date/time localization. Loaded into every slice before any user translation files, so users can supply overrides if desired.
File.("i18n/locale/en.yml", __dir__).freeze
Instance Attribute Summary
Attributes inherited from Hanami::Provider::Source
Instance Method Summary collapse
- #prepare ⇒ Object private
-
#start ⇒ Object
private
rubocop:disable Metrics/AbcSize.
Methods inherited from Hanami::Provider::Source
#initialize, #target_container
Constructor Details
This class inherits a constructor from Hanami::Provider::Source
Instance Method Details
#prepare ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 33 34 35 |
# File 'lib/hanami/providers/i18n.rb', line 27 def prepare require "i18n" SLICE_CONFIGURED_SETTINGS.each do |setting| next if config.configured?(setting) config.public_send(:"#{setting}=", slice.config.i18n.public_send(setting)) end end |
#start ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/AbcSize
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hanami/providers/i18n.rb', line 38 def start backend = config.backend || ::I18n::Backend::Simple.new # Configure fallbacks if enabled (only for default backend, not custom backends) fallbacks_config = nil if config.fallbacks && !config.backend fallbacks_config = case config.fallbacks when true # Use default_locale as the only fallback fallbacks = ::I18n::Locale::Fallbacks.new fallbacks.defaults = [config.default_locale] fallbacks when Hash # Use explicit per-locale fallback mapping ::I18n::Locale::Fallbacks.new(config.fallbacks) when Array # Use the given fallbacks for all locales fallbacks = ::I18n::Locale::Fallbacks.new fallbacks.defaults = config.fallbacks fallbacks else ::I18n::Locale::Fallbacks.new(config.fallbacks) end end # Only load translation files if using the default backend. Custom backends are expected to # handle their own initialization. unless config.backend translation_files = [ BUNDLED_DEFAULTS_PATH, *resolve_load_paths(Array(config.shared_load_path), root: slice.app.root), *resolve_load_paths(Array(config.load_path), root: slice.root) ].uniq backend.load_translations(*translation_files) end register "i18n", Backend.new( backend, locale: config.default_locale, default_locale: config.default_locale, available_locales: config.available_locales, fallbacks: fallbacks_config ) end |