[[Repository](https://github.com/tobywf/lcid-rs/)] [[Documentation](https://docs.rs/lcid/)] [[Crate Registry (crates.io)](https://crates.io/crates/lcid)]
This crate provides language code identifier parsing and information
according to the [MS-LCID] Windows Language Code Identifier (LCID) Reference and System.Globalization.CultureInfo
API.
The following information is provided:
lcid
), and lookup by LCIDname
), and lookup by nameenglish_name
)iso639_two_letter
)iso639_three_letter
)windows_three_letter
)ansi_code_page
)To use this crate, add the following to your Cargo.toml
:
toml
[dependencies]
lcid = "0.2"
Language identifiers/information can be queried by Language Code Identifier (LCID, a 32-bit unsigned integer), name (a string, i.e. supported IETF BCP 47 language tags), or by directly referring to the language identifier constant:
```rust use lcid::LanguageId; use std::convert::TryInto;
fn main() { let lang: &LanguageId = 1033.tryinto().unwrap(); println!("Lang is '{}'/{}/'{}'", lang.name, lang.lcid, lang.englishname);
let lang: &LanguageId = "en-US".try_into().unwrap();
println!("Lang is '{}'/{}/'{}'", lang.name, lang.lcid, lang.english_name);
let lang: &LanguageId = lcid::constants::LANG_EN_US;
println!("Lang is '{}'/{}/'{}'", lang.name, lang.lcid, lang.english_name);
} ```
This prints the following for each:
Lang is 'en-US'/1033/'English (United States)'
I struggle to find a good name for this. "locale-info" might be misleading (might imply some kind of POSIX locale support), or "culture-info" implying more than the project offers (like calendar information). In the end, I chose "lcid-rs", because "lcid" is ambiguous/hard to search for, although I named the crate itself "lcid" because in the context of Rust, "lcid" is not ambiguous. It'd be nice if this project was referred to as "lcid-rs" in ambiguous contexts (linking to the repo, blog posts, etc), and "lcid" only in Rust code/configuration.
The maintenance status is "as-is". I'm happy to accept pull requests for corrections (as long as they align with MS-LCID and the Windows API), pull requests for new features, and pull requests for new MS-LCID protocol revisions in the future.
This library currently tracks the 14.1
/2021-07-04 protocol revision. Future
protocol revisions will may only trigger a minor version bump, so if you need
lookup behaviour of a specific revision, pin this crate accordingly.
14.1
/2021-07-04 protocol revisionLanguageId
constants to a module, to avoid cluttering the crate
namespace (breaking change)0x1000
ones)First, information was extracted from the MS-LCID PDF, and from both HTML tables of the associated LCIDs ("numbered") and the unassociated LCIDs ("named"). This was then manually cleaned, converted to JSON, and compared.
Then, the GetCultureInfo.ps1
script was run on a Windows Server 2019 machine
(Build 17763) to gather further information from the
System.Globalization.CultureInfo
API. The values returned by the API do not
always match the information in MS-LCID, so some fix-up were applied. For
details, please see the script.
Finally, the lcid-gen
crate generates code for the lcid
crate
(src/gen.rs
). This is done to avoid having a build-time dependency on the
JSON files.
14.1
/2021-07-040x5C0A
in the "Language ID" table, and
once in the "Locale Names without LCIDs" table as 0x1000
. The former LCID
was used.Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.