An idiomatic Rust crate for locale operations
MIT License
This crate provides a higher-level interface to a number of locale-related sources, in three areas:
simple_locale::codes
.simple_locale::settings
.Locale
enumeration, and a LocaleString
structure are provideduse simple_locale::LocaleString;
use simple_locale::codes::{country, currency};
let locale = LocaleString::new_strict("en".to_string())
.with_territory("US".to_string())
.with_code_set("UTF-8".to_string())
.with_modifier("collation=pinyin;currency=CNY".to_string());
println!("{}", locale);
let mexico = country::lookup_country("MEX").unwrap();
println!("{:?}", mexico);
let mexico_region = country::lookup_region(mexico.country_code).unwrap();
println!("{:?}", mexico_region);
let currencies = currency::currencies_for_country_name(mexico_region.name.as_str());
println!("{:?}", currencies);
Currently only tested on macOS, Linux and Windows to come.
The following describe two code generation steps that are executed outside the normal build process as the output is stored in Git and versioned based on external factors.
As mentioned above, this crate depends on FFI bindings to POSIX locale
functions, and there are O/S differences that make this a pain. The script
create-bindings.sh
is used to generate these bindings (using cargo bindgen) in such a way that
different O/S bindings can be built effectively.
The script create-data-modules
on the other hand is used to process files downloaded, or scraped, from
standards web sites to create data used by the library. This data is generated
as JSON files in the src/codes/data
folder and read as a part of the
build for codes
modules using the Rust include!
macro.
Currently data is generated for the following standards:
LocaleString
?codes
and settings
LC_
categories (address, identification,