Skip to main content

resolve_accept_language

Function resolve_accept_language 

Source
pub fn resolve_accept_language<'a>(
    header: &str,
    supported_locales: &[&'a str],
    default_locale: &'a str,
) -> &'a str
Expand description

Resolves an Accept-Language header against a supported locale list.

The function prefers higher q values, then exact locale matches, then primary-language matches such as es-ES -> es. If no supported locale matches the header, default_locale is returned.

Matching is ASCII case-insensitive and supports locale identifiers that use either - or _ separators.

ยงExamples

use lang_lib::resolve_accept_language;

let locale = resolve_accept_language(
    "es-ES,es;q=0.9,en;q=0.8",
    &["en", "es"],
    "en",
);

assert_eq!(locale, "es");