Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Berrysoft/language-matcher
A language matcher with CLDR.
https://github.com/Berrysoft/language-matcher
Last synced: 3 days ago
JSON representation
A language matcher with CLDR.
- Host: GitHub
- URL: https://github.com/Berrysoft/language-matcher
- Owner: Berrysoft
- Created: 2022-09-10T01:58:22.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T06:05:54.000Z (over 1 year ago)
- Last Synced: 2024-10-05T15:46:27.769Z (about 1 month ago)
- Language: Rust
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# language-matcher
There's no language matcher in [`icu4x`](https://github.com/unicode-org/icu4x).
And, if you have noticed, the language matching data in the JSON data of CLDR is broken.This is a [language matcher](https://www.unicode.org/reports/tr35/tr35.html#EnhancedLanguageMatching) based on the XML data of CLDR.
The distance value is multiplied by 10 to show the difference by paradigm locales.``` rust
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))
);
```