5 unstable releases

0.13.0 May 6, 2020
0.12.1 Jan 29, 2020
0.12.0 Jan 28, 2020
0.11.1 Nov 19, 2019
0.11.0 Nov 7, 2019

#355 in Internationalization (i18n)

Download history 20777/week @ 2023-07-19 22747/week @ 2023-07-26 19940/week @ 2023-08-02 18583/week @ 2023-08-09 19954/week @ 2023-08-16 23397/week @ 2023-08-23 21237/week @ 2023-08-30 21027/week @ 2023-09-06 21711/week @ 2023-09-13 25220/week @ 2023-09-20 24227/week @ 2023-09-27 24643/week @ 2023-10-04 25521/week @ 2023-10-11 24948/week @ 2023-10-18 22605/week @ 2023-10-25 22729/week @ 2023-11-01

99,833 downloads per month
Used in 160 crates (16 directly)


158 lines

Fluent LangNeg

Fluent LangNeg is a library for language and locale identifier negotiation.

crates.io Build Status Coverage Status


This is a Rust implementation of fluent-langneg library which is a part of Project Fluent.

The library uses unic-langid and unic-locale to retrieve and operate on Unicode Language and Locale Identifiers. The library provides algorithm for negotiating between lists of locales.


use fluent_langneg::negotiate_languages;
use fluent_langneg::NegotiationStrategy;
use fluent_langneg::convert_vec_str_to_langids_lossy;
use unic_langid::LanguageIdentifier

// Since langid parsing from string is fallible, we'll use a helper
// function which strips any langids that failed to parse.
let requested = convert_vec_str_to_langids_lossy(&["de-DE", "fr-FR", "en-US"]);
let available = convert_vec_str_to_langids_lossy(&["it", "fr", "de-AT", "fr-CA", "en-US"]);
let default: LanguageIdentifier = "en-US".parse().expect("Parsing langid failed.");

let supported = negotiate_languages(

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

See docs.rs for more examples.


The implementation is complete according to fluent-langneg corpus of tests, which means that it parses, serializes and negotiates as expected.

The negotiation methods can operate on lists of LanguageIdentifier or Locale.

The remaining work is on the path to 1.0 is to gain in-field experience of using it, add more tests and ensure that bad input is correctly handled.


The API is based on UTS 35 definition of Unicode Locale Identifier and is aiming to parse and serialize all locale identifiers according to that definition.

Note: Unicode Locale Identifier is similar, but different, from what BCP47 specifies under the name Language Tag. For most locale management and negotiation needs, the Unicode Locale Identifier used in this crate is likely a better choice, but in some case, like HTTP Accepted Headers, you may need the complete BCP47 Language Tag implementation which this crate does not provide.

Language negotiation algorithms are custom Project Fluent solutions, based on RFC4647.

The language negotiation strategies aim to replicate the best-effort matches with the most limited amount of data. The algorithm returns reasonable results without any database, but the results can be improved with either limited or full CLDR likely-subtags database.

The result is a balance chosen for Project Fluent and may differ from other implementations of language negotiation algorithms which may choose different tradeoffs.


Although Fluent Locale aims to stay close to W3C Accepted Languages, it does not aim to implement the full behavior and some aspects of the language negotiation strategy recommended by W3C, such as weights, are not a target right now.

For such purposes, rust-language-tags crate seems to be a better choice.


The crate is considered to be fully optimized for production.


cargo build
cargo test
cargo bench


~24K SLoC