Class: RosettAi::I18n::LocaleResolver
- Inherits:
-
Object
- Object
- RosettAi::I18n::LocaleResolver
- Defined in:
- lib/rosett_ai/i18n/locale_resolver.rb
Overview
Resolves the active locale using priority: explicit flag > config > LANG env > "en".
Provides a fallback chain for graceful degradation: nl_BE -> nl -> en, ar_EG -> ar -> en, etc.
Instance Method Summary collapse
-
#fallback_chain(locale) ⇒ Array<String>
Builds a fallback chain from a locale string (e.g. "nl_BE" -> ["nl_BE", "nl", "en"]).
-
#resolve(explicit: nil, env: ENV) ⇒ Hash{Symbol => Object}
Resolves the active locale from explicit flag, env, or default.
Instance Method Details
#fallback_chain(locale) ⇒ Array<String>
Builds a fallback chain from a locale string (e.g. "nl_BE" -> ["nl_BE", "nl", "en"]).
28 29 30 31 32 33 34 |
# File 'lib/rosett_ai/i18n/locale_resolver.rb', line 28 def fallback_chain(locale) parts = locale.split('_') chain = [locale] chain << parts.first if parts.length > 1 chain << 'en' unless chain.include?('en') chain.uniq end |
#resolve(explicit: nil, env: ENV) ⇒ Hash{Symbol => Object}
Resolves the active locale from explicit flag, env, or default.
19 20 21 22 |
# File 'lib/rosett_ai/i18n/locale_resolver.rb', line 19 def resolve(explicit: nil, env: ENV) locale = explicit || parse_lang(env['LANG']) || 'en' { locale: locale, chain: fallback_chain(locale) } end |