Crates.io | simple-locale |
lib.rs | simple-locale |
version | 0.2.0 |
source | src |
created_at | 2019-08-21 17:29:22.088255 |
updated_at | 2019-08-24 17:39:14.800802 |
description | An interface to all manner of locale-related information. |
homepage | |
repository | https://github.com/johnstonskj/simple-locale.git |
max_upload_size | |
id | 158686 |
size | 2,555,924 |
An idiomatic Rust crate for locale, and locale-like, operations.
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 provided
that may be used to parse and construct locale identifiers in
a standards-conformant manner.use 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
modules.
LC_
categories (address, identification,
measurement, name, paper, telephone).