Class: Otto::Locale::Config

Inherits:
Object
  • Object
show all
Includes:
Core::Freezable
Defined in:
lib/otto/locale/config.rb

Overview

Locale configuration for Otto applications

This class manages locale-related settings including available locales and default locale selection.

Examples:

Basic usage

config = Otto::Locale::Config.new
config.available_locales = { 'en' => 'English', 'es' => 'Spanish' }
config.default_locale = 'en'

With initialization

config = Otto::Locale::Config.new(
  available_locales: { 'en' => 'English', 'fr' => 'French' },
  default_locale: 'en'
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Freezable

#deep_freeze!

Constructor Details

#initialize(available_locales: nil, default_locale: nil, fallback_locale: nil) ⇒ Config

Initialize locale configuration

Parameters:

  • available_locales (Hash, nil) (defaults to: nil)

    Hash of locale codes to names

  • default_locale (String, nil) (defaults to: nil)

    Default locale code

  • fallback_locale (Hash, nil) (defaults to: nil)

    Hash of locale codes to fallback chains



34
35
36
37
38
# File 'lib/otto/locale/config.rb', line 34

def initialize(available_locales: nil, default_locale: nil, fallback_locale: nil)
  @available_locales = available_locales
  @default_locale = default_locale
  @fallback_locale = fallback_locale
end

Instance Attribute Details

#available_localesObject

Returns the value of attribute available_locales.



27
28
29
# File 'lib/otto/locale/config.rb', line 27

def available_locales
  @available_locales
end

#default_localeObject

Returns the value of attribute default_locale.



27
28
29
# File 'lib/otto/locale/config.rb', line 27

def default_locale
  @default_locale
end

#fallback_localeObject

Returns the value of attribute fallback_locale.



27
28
29
# File 'lib/otto/locale/config.rb', line 27

def fallback_locale
  @fallback_locale
end

Instance Method Details

#configured?Boolean

Check if locale configuration is present

Returns:

  • (Boolean)

    true if either available_locales or default_locale is set



54
55
56
# File 'lib/otto/locale/config.rb', line 54

def configured?
  !@available_locales.nil? || !@default_locale.nil?
end

#to_hHash

Convert to hash for compatibility with existing code

Returns:

  • (Hash)

    Hash representation of configuration



43
44
45
46
47
48
49
# File 'lib/otto/locale/config.rb', line 43

def to_h
  {
    available_locales: @available_locales,
       default_locale: @default_locale,
      fallback_locale: @fallback_locale,
  }.compact
end