3 releases (breaking)
new 0.3.0 | Dec 19, 2024 |
---|---|
0.2.0 | Dec 19, 2024 |
0.1.0 | Sep 8, 2024 |
#1 in #globalization
79 downloads per month
Used in 6 crates
(2 directly)
66KB
594 lines
language-enum
language-enum
is a robust, exhaustive enum representing a wide variety of global and regional languages. It’s designed for use in applications that require internationalization (i18n), localization, and handling of multiple languages.
Features
- Exhaustive Language Support: Covers major world languages, regional languages, and some languages spoken by smaller populations.
- Serialization & Deserialization: Comes with built-in support for
serde
to easily serialize and deserialize languages. - Flexible
Other
Variant: Allows specifying languages not covered in the predefined enum through theOther(String)
variant. - No Dependencies: Apart from optional
serde
support, the crate is dependency-free.
Installation
Add language-enum
to your Cargo.toml
:
[dependencies]
language-enum = "0.2"
To enable serde support for serialization and deserialization:
[dependencies]
language-enum = { version = "0.1", features = ["serde"] }
Usage
use language_enum::Language;
fn main() {
let lang = Language::English;
println!("Selected language: {:?}", lang);
// Using the `Other` variant for an unsupported language
let other_lang = Language::Other("Klingon".to_string());
println!("Other language: {:?}", other_lang);
let random_lang = Language::random(); // this is weighted by number of speakers on earth
let uniform_random_lang = Language::uniform();
}
Enum Variants
The Language enum includes a wide range of languages such as:
Major Languages: English, Spanish, Chinese (Mandarin), Arabic, Russian, etc. Regional Languages: Breton, Hawaiian, Basque, and others. Indigenous Languages: Cherokee, Navajo, Maori, and more. It also includes an Other(String) variant to cover any languages not explicitly listed.
Features
Serialization: Serialize and deserialize the enum with serde. Exhaustive: Covers a broad range of languages for various applications. Custom Language Support: Use Language::Other(String) for languages not in the predefined set. License
Licensed under either of:
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~2.5–3.5MB
~72K SLoC