Crate accept_language
source ·Expand description
accept-language
is a tiny library for parsing the Accept-Language header from browsers (as defined here).
It’s intended to be used in a webserver that supports some level of internationalization (i18n), but can be used anytime an Accept-Language header string is available.
In order to help facilitate better i18n, a function is provided to return the intersection of the languages the user prefers and the languages your application supports.
Example
use accept_language::{intersection, parse};
let user_languages = parse("en-US, en-GB;q=0.5");
let common_languages = intersection("en-US, en-GB;q=0.5", vec!["en-US", "de", "en-GB"]);
Functions
Compare an Accept-Language header value with your application’s supported languages to find
the common languages that could be presented to a user.
Parse a raw Accept-Language header value into an ordered list of language tags.
This should return the exact same list as
window.navigator.languages
in supported browsers.