Crate simple-locale

travis.ci crates.io docs.rs Minimum Rust Version mit License GitHub stars

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:

  1. Locale-related codes/identifiers and any standards-based information concerning them. For example, ISO-396 language identifiers, or ISO-3166 country identifiers. These are under the module simple_locale::codes.
  2. Locale settings, usually accessed via POSIX (see ISO/IEC 15897) operating system functions. These are under the module simple_locale::settings.
  3. A Locale enumeration, and a LocaleString structure are provided that may be used to parse and construct locale identifiers in a standards-conformant manner.

Example

```rust use simplelocale::LocaleString; use simplelocale::codes::{country, currency};

let locale = LocaleString::newstrict("en".tostring()) .withterritory("US".tostring()) .withcodeset("UTF-8".tostring()) .withmodifier("collation=pinyin;currency=CNY".to_string()); println!("{}", locale);

let mexico = country::lookup_country("MEX").unwrap(); println!("{:?}", mexico);

let mexicoregion = country::lookupregion(mexico.countrycode).unwrap(); println!("{:?}", mexicoregion);

let currencies = currency::currenciesforcountryname(mexicoregion.name.as_str()); println!("{:?}", currencies); ```

Operating System Coverage

Currently only tested on macOS, Linux and Windows to come.

Pre-Build Process

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.

FFI Bindings

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.

JSON Data Files

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:

TODO