2 unstable releases
0.2.0 | Aug 24, 2019 |
---|---|
0.1.0 | Aug 21, 2019 |
#131 in Internationalization (i18n)
310KB
6K
SLoC
Crate simple-locale
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:
- 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
. - Locale settings, usually accessed via POSIX (see
ISO/IEC 15897) operating system
functions. These are under the module
simple_locale::settings
. - A
Locale
enumeration, and aLocaleString
structure are provided that may be used to parse and construct locale identifiers in a standards-conformant manner.
Example
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);
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:
- ISO 639 Codes for the representation of names of languages; Parts 1-4, 2-character and 3-character codes supported.
- ISO 3166 Codes for the representation of names of countries and their subdivisions; Part 1, 2-character codes, only.
- ISO 4217 Codes for the representation of currencies; alphabetic and numeric codes supported.
- ISO 15924 Codes for the representation of names of scripts; alphabetic and numeric codes supported.
TODO
- Should strict be the default for
LocaleString
? - Determine naming convention between the names in the
codes
andsettings
modules.- Expect that the names in code modules will be changed to reflect those in the settings.
- Build and test for Linux.
- How to deal with extended
LC_
categories (address, identification, measurement, name, paper, telephone).
- How to deal with extended
- Build and test for Windows.
Dependencies
~3–5MB
~91K SLoC