5 releases

0.1.4 Feb 28, 2023
0.1.3 Jan 4, 2023
0.1.2 Oct 2, 2022
0.1.1 Sep 10, 2022
0.1.0 Sep 10, 2022

#212 in Internationalization (i18n)

Download history 23/week @ 2024-07-27 21/week @ 2024-08-03 20/week @ 2024-08-10 15/week @ 2024-08-17 2/week @ 2024-08-24 1/week @ 2024-09-07 158/week @ 2024-09-14 1911/week @ 2024-09-21 678/week @ 2024-09-28 1768/week @ 2024-10-05 1642/week @ 2024-10-12 2170/week @ 2024-10-19 1733/week @ 2024-10-26 2049/week @ 2024-11-02 686/week @ 2024-11-09

6,955 downloads per month
Used in 2 crates (via ayaka-runtime)

MIT license

19KB
285 lines

language-matcher

There's no language matcher in icu4x. And, if you have noticed, the language matching data in the JSON data of CLDR is broken.

This is a language matcher based on the XML data of CLDR. The distance value is multiplied by 10 to show the difference by paradigm locales.

use icu_locid::langid;
use language_matcher::LanguageMatcher;

let matcher = LanguageMatcher::new();

assert_eq!(matcher.distance(langid!("zh-CN"), langid!("zh-Hans")), 0);
assert_eq!(matcher.distance(langid!("zh-HK"), langid!("zh-MO")), 40);

let accepts = [
    langid!("en"),
    langid!("ja"),
    langid!("zh-Hans"),
    langid!("zh-Hant"),
];
assert_eq!(
    matcher.matches(langid!("zh-CN"), &accepts),
    Some((&langid!("zh-Hans"), 0))
);

lib.rs:

A language matcher with CLDR.

The "sync" feature of icu_provider is enabled because we like Sync.

Dependencies

~4MB
~73K SLoC