Crate locale_match

Crate locale_match 

Source
Expand description

A small library for selecting the best match for user’s preferred locales from available locales.

The library consists of two modules:

  • bcp47 — for matching locales in the BCP 47 format.
  • posix — for matching locales in the POSIX format.

Both modules provide the best_matching_locale function.

§Examples

§BCP 47

use locale_match::bcp47::best_matching_locale;

let available_locales = ["en-US", "ru-BY"];
let user_locales = ["ru-RU", "ru", "en-US", "en"];

let best_match = best_matching_locale(available_locales, user_locales);

assert_eq!(best_match, Some("ru-BY"));

§POSIX

use locale_match::posix::best_matching_locale;

let available_locales = ["en_US.UTF-8", "ru_BY.UTF-8"];
let user_locales = ["ru_RU.UTF-8", "ru", "en_US.UTF-8", "en"];
 
let best_match = best_matching_locale(available_locales, user_locales);
 
assert_eq!(best_match, Some("ru_BY.UTF-8"));

Modules§

bcp47
A module for matching locales in the BCP 47 format.
posix
A module for matching locales in the POSIX format.