language-matcher

Crates.iolanguage-matcher
lib.rslanguage-matcher
version0.1.4
sourcesrc
created_at2022-09-10 01:59:49.697207
updated_at2023-02-28 06:07:06.026607
descriptionA language matcher with CLDR.
homepage
repositoryhttps://github.com/Berrysoft/language-matcher
max_upload_size
id662196
size75,280
王宇逸 (Berrysoft)

documentation

README

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))
);
Commit count: 11

cargo fmt