Module: Philiprehberger::LocaleKit::Negotiator
- Defined in:
- lib/philiprehberger/locale_kit/negotiator.rb
Overview
Content negotiation for matching requested locales against available locales.
Uses a fallback chain strategy: for each requested locale, tries the exact match first, then walks up the parent chain (e.g., en-Latn-US -> en-Latn -> en) looking for matches in the available set. Quality weights from Accept-Language parsing are respected.
Class Method Summary collapse
-
.negotiate(requested, available, default: nil) ⇒ Locale?
Finds the best matching locale from available options.
Class Method Details
.negotiate(requested, available, default: nil) ⇒ Locale?
Finds the best matching locale from available options.
17 18 19 20 21 22 23 24 25 |
# File 'lib/philiprehberger/locale_kit/negotiator.rb', line 17 def self.negotiate(requested, available, default: nil) requested_locales = normalize(requested) available_locales = normalize(available) return resolve_default(default) if requested_locales.empty? || available_locales.empty? best = find_best_match(requested_locales, available_locales) best || resolve_default(default) end |