LCID-rs: A Rust library for Windows Language Code Identifiers and other language/culture information

crates.io docs.rs GitHub CI

[[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:

To use this crate, add the following to your Cargo.toml:

toml [dependencies] lcid = "0.3"

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)'

Project name and status

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.

MS-LCID protocol revision

This library currently tracks the 15.0/2021-06-25 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.

Changelog

[0.3.0] - 2023-06-15

[0.2.1] - 2023-06-10

[0.2.0] - 2021-06-08

[0.1.0] - 2021-06-06

How the information was generated

First, information was extracted from the MS-LCID PDF corresponding to the tracked protocol revision, and from the HTML table of the associated LCIDs. This was then manually cleaned, converted to JSON, and compared.

The GetCultureInfo.ps1 script was run on a Windows Server 2022 machine (Build 20348, locale "en-us") and a Windows 10 (Build 19045, locale "en-us") to gather further information from the System.Globalization.CultureInfo API, based on the language IDs in MS-LCID. 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 lcid_gen. Since there were differences between the output on Windows Server 2022 and Windows 10, additional fix-ups were applied so that the information matches. Many of these are listed in the errata section.

Finally, the lcid_gen crate was invoked to generate code for the lcid crate. The generated code is committed to the repository. This is done to avoid having a build-time dependency on the JSON files.

MS-LCID/CultureInfo errata

Protocol revision 15.0/2021-06-25

Protocol revision 14.1/2021-04-07

License

Licensed under either of

at your option.

Contribution

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.