Skip to main content

LocaleResolver

Trait LocaleResolver 

Source
pub trait LocaleResolver: Send + Sync {
    // Required method
    fn resolve(&self, parts: &Parts) -> Option<String>;
}
Expand description

Trait for extracting the active locale from a request.

Implementations are tried in order within the locale chain built by the i18n module. The first resolver that returns Some wins; if all resolvers return None, I18nConfig::default_locale is used.

§Empty-allowlist semantics

Built-in resolvers disagree on what an empty available_locales slice means, so pick the constructor inputs deliberately:

  • QueryParamResolver and CookieResolver treat an empty allowlist as “accept any value” — whatever the caller supplied is returned verbatim.
  • AcceptLanguageResolver treats an empty allowlist as “match nothing” because it can only return locales that appear in the list.

The default chain built by I18n::new hands every resolver the same available_locales, so the asymmetry only surfaces when wiring resolvers manually.

Required Methods§

Source

fn resolve(&self, parts: &Parts) -> Option<String>

Returns a locale string (e.g. "en", "uk") if this resolver can determine the locale from the request, or None to fall through to the next resolver.

Implementors§