Crate lang_id

Source
Expand description

This library provides a series of const lang-ids (language identifiers) which can be found in the consts module. Additionally, it provides some handy maps.

§Examples

Using the result of a const fn as a value:

use lang_id::LangID;

// Compile-time verified language ID
const DEFAULT_LANG: LangID = lang_id::consts::lang_id_en();

Description-data Lookup (requires map feature)

let map = lang_id::maps::description::map();
let gsw_fr = map.get("gsw-FR");
assert_eq!(gsw_fr, Some(&"Schwiizertüütsch, Latiinisch, Frankriich"));

let zh = map.get("zh");
assert_eq!(zh, Some(&"简体中文, 中国"));

let ja = map.get("ja");
assert_eq!(ja, Some(&"日本語, 日本語の文字, 日本"));

§Features

FeatureDependenciesDescription
stdNoneEnables stdlib integrations
mapphf, tinystrAdds precomputed static maps:
- Perfect hash maps for O(1) lookups
- Compact string storage with TinyStr
sys-localesys-locale, stdSystem locale detection:
- Cross-platform locale querying
- Integration with OS settings
matchNoneMatch the value or function name in consts using bytes, for example, b“en-001“ => lang_id_en_001().
serdeunic-langid/serdeSerialization/deserialization support
constsNoneProvides const language ids

Re-exports§

pub use error::LangidResult as Result;

Modules§

common
constsconsts
error
mapsmap
matchesmatch
nostd_sys_localenostd-sys-locale
sys_localesys-locale
The sys-locale module is used to get the current system’s locale and convert it into LangID.

Structs§

LangID
LanguageIdentifier is a core struct representing a Unicode Language Identifier.
RawID
RawID