[][src]Module fluent_locale::accepted_languages

This function parses Accept-Language string into a list of language tags that can be later passed to language negotiation functions.

Example:

use fluent_locale::negotiate_languages;
use fluent_locale::NegotiationStrategy;
use fluent_locale::parse_accepted_languages;
use fluent_locale::convert_vec_str_to_langids_lossy;
use unic_langid::LanguageIdentifier;

let requested = parse_accepted_languages("de-AT;0.9,de-DE;0.8,de;0.7;en-US;0.5");
let available = convert_vec_str_to_langids_lossy(&["fr", "pl", "de", "en-US"]);
let default: LanguageIdentifier = "en-US".parse().expect("Failed to parse a langid.");

let supported = negotiate_languages(
  &requested,
  &available,
  Some(&default),
  NegotiationStrategy::Filtering
);

let expected = convert_vec_str_to_langids_lossy(&["de", "en-US"]);
assert_eq!(supported,
           expected.iter().map(|t| t.as_ref()).collect::<Vec<&LanguageIdentifier>>());

This function ignores the weights associated with the locales, since Fluent Locale language negotiation only uses the order of locales, not the weights.

Functions

parse