Class: Hanami::Config::I18n

Inherits:
Object
  • Object
show all
Includes:
Dry::Configurable
Defined in:
lib/hanami/config/i18n.rb

Overview

Hanami I18n config

Since:

  • x.x.x

Instance Attribute Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Since:

  • x.x.x



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_localesArray<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).

Examples:

Restrict to specific locales

config.i18n.available_locales = [:en, :fr, :de]

Returns:

  • (Array<Symbol>)

Since:

  • x.x.x



45
# File 'lib/hanami/config/i18n.rb', line 45

setting :available_locales, default: Providers::I18n::DEFAULT_AVAILABLE_LOCALES

#default_localeSymbol

Sets or returns the default locale to use for translations.

Defaults to ‘:en`.

Examples:

config.i18n.default_locale = :fr

Returns:

  • (Symbol)

Since:

  • x.x.x



27
# File 'lib/hanami/config/i18n.rb', line 27

setting :default_locale, default: Providers::I18n::DEFAULT_LOCALE

#fallbacksBoolean, ...

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).

Examples:

Enable default fallbacks

config.i18n.fallbacks = true

Configure fallbacks with a hash

config.i18n.fallbacks = {de: [:de, :en], fr: [:fr, :en]}

Configure a default fallback locale

config.i18n.fallbacks = [:en]

Returns:

  • (Boolean, Hash, Array, nil)

Since:

  • x.x.x



121
# File 'lib/hanami/config/i18n.rb', line 121

setting :fallbacks

#load_pathArray<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.

Examples:

Append custom paths

config.i18n.load_path += ["config/custom_translations/**/*.yml"]

Replace default paths

config.i18n.load_path = ["translations/**/*.yml"]

Returns:

  • (Array<String>)

Since:

  • x.x.x



69
# File 'lib/hanami/config/i18n.rb', line 69

setting :load_path, default: Providers::I18n::DEFAULT_LOAD_PATH

#shared_load_pathArray<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”]`.

Examples:

Disable shared translations

config.i18n.shared_load_path = []

Add another shared source

config.i18n.shared_load_path += ["vendor/translations/**/*.yml"]

Returns:

  • (Array<String>)

Since:

  • x.x.x



95
# File 'lib/hanami/config/i18n.rb', line 95

setting :shared_load_path, default: Providers::I18n::DEFAULT_SHARED_LOAD_PATH