Class: Hanami::Config::I18n
- Inherits:
-
Object
- Object
- Hanami::Config::I18n
- Includes:
- Dry::Configurable
- Defined in:
- lib/hanami/config/i18n.rb
Overview
Hanami I18n config
Instance Attribute Summary collapse
-
#available_locales ⇒ Array<Symbol>
Sets or returns the array of available locales for the application.
-
#default_locale ⇒ Symbol
Sets or returns the default locale to use for translations.
-
#fallbacks ⇒ Boolean, ...
Sets or returns the locale fallbacks configuration for missing translations.
-
#load_path ⇒ Array<String>
Sets or returns the array of file path patterns for loading per-slice translation files.
-
#shared_load_path ⇒ Array<String>
Sets or returns the array of file path patterns for loading translation files that should be shared across every slice in the app.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
125 126 127 128 129 130 131 |
# File 'lib/hanami/config/i18n.rb', line 125 def method_missing(name, *args, &block) if config.respond_to?(name) config.public_send(name, *args, &block) else super end end |
Instance Attribute Details
#available_locales ⇒ Array<Symbol>
Sets or returns the array of available locales for the application.
When set, only these locales will be considered available, even if translation files exist for other locales. When empty or not set, all locales from loaded translation files are available.
Defaults to ‘[]` (all loaded locales are available).
45 |
# File 'lib/hanami/config/i18n.rb', line 45 setting :available_locales, default: Providers::I18n::DEFAULT_AVAILABLE_LOCALES |
#default_locale ⇒ Symbol
Sets or returns the default locale to use for translations.
Defaults to ‘:en`.
27 |
# File 'lib/hanami/config/i18n.rb', line 27 setting :default_locale, default: Providers::I18n::DEFAULT_LOCALE |
#fallbacks ⇒ Boolean, ...
Sets or returns the locale fallbacks configuration for missing translations.
When enabled, the i18n backend will fall back to other locales when a translation is missing in the requested locale.
This can be set to ‘true` to enable default fallbacks, a hash to configure explicit fallback chains per locale, or an array to set a default fallback locale for all locales.
Defaults to ‘nil` (fallbacks disabled).
121 |
# File 'lib/hanami/config/i18n.rb', line 121 setting :fallbacks |
#load_path ⇒ Array<String>
Sets or returns the array of file path patterns for loading per-slice translation files.
Patterns can be:
-
Relative paths/globs (resolved against the slice’s own root)
-
Absolute paths (used as-is)
Defaults to ‘[“config/i18n/*/.yml,yaml,json,rb”]`.
See #shared_load_path for common translations that should be loaded into every slice.
69 |
# File 'lib/hanami/config/i18n.rb', line 69 setting :load_path, default: Providers::I18n::DEFAULT_LOAD_PATH |
#shared_load_path ⇒ Array<String>
Sets or returns the array of file path patterns for loading translation files that should be shared across every slice in the app.
Relative patterns are resolved against the **app root**, regardless of which slice is being loaded. Absolute paths are used as-is. Files matched by these patterns are loaded into every slice’s i18n backend before that slice’s own #load_path files, so slice-specific translations override shared ones on key conflicts.
This is the recommended place for foundational translation data needed by every slice, such as the ‘date.*` and `time.*` keys used by `localize`.
Defaults to ‘[“config/i18n/shared/*/.yml,yaml,json,rb”]`.
95 |
# File 'lib/hanami/config/i18n.rb', line 95 setting :shared_load_path, default: Providers::I18n::DEFAULT_SHARED_LOAD_PATH |