Locale Name to Code Page for Rust

CI (master) CI (Release) locale<em>name</em>code<em>page at crates.io locale</em>name<em>code</em>page at docs.rs Downloads (Crates.io) License (Crates.io)

This is a library that converts strings representing locale names to code pages that are used in Windows.

e.g.

Usage

First, add locale_name_code_page = "<2" to your Cargo.toml.

```toml [dependencies]

snip

localenamecode_page = "<2"

snip

```

Then, convert strings representing locales to code pages like:

```rust use localenamecodepage::getcodepage; use localenamecodepage::cptable_type::CodePage;

// IConverter has already been defined by you fn getconverterinstance(codepage: &CodePage) -> Box { // do something return Box::new(converter); }

// snip

fn main() { // snip if let Some(codepageref) = getcodepage(localestring) { let converter = getconverterinstance(codepageref); // snip } else { eprintln!("Error: {} doesn't represent a valid locale.", locale_string); std::process::exit(1); } } ```

Obtained codepage (instance of locale_name_code_page::cp_table_type::CodePage) can be used as follows:

```rust use localenamecodepage::getcodepage;

fn main() { let encp = getcodepage("en-US").unwrap(); // prints "en-US locale: 1252 (ANSI) / 437 (OEM)" println!("en-US locale: {} (ANSI) / {} (OEM)", encp.ansi, encp.oem); } ```

Source of Information

https://web.archive.org/web/20180104073254/https://www.microsoft.com/resources/msdn/goglobal/default.mspx

FAQ

How can I convert codepage to encoder/decoder?

Use the following libraries:

ANSI encodings (including CJKV languages)

Combine with codepage and encoding_rs.

OEM encodings (except for CJKV languages)

Use oem_cp.

How can I get the current locale?

Use locale_config.

I want to port this library to other languages.

You can use assets/nls_info.json in your automatic code generation script.

LICENSE

MIT