Skip to main content

Crate use_locale_tag

Crate use_locale_tag 

Source
Expand description

§use-locale-tag

Small BCP 47 / Unicode-style locale tag parsing and normalization primitives for RustUse.

§Example

use use_locale_tag::{normalize_locale_tag, parse_locale_tag};

let tag = parse_locale_tag("zh-hant-tw").unwrap();

assert_eq!(tag.as_str(), "zh-Hant-TW");
assert_eq!(normalize_locale_tag("en-us"), Some("en-US".to_string()));

§Scope

  • Parse locale tags with language, optional script, optional region, and supported suffixes.
  • Normalize language subtags to lowercase.
  • Normalize script subtags to title case.
  • Normalize alphabetic region subtags to uppercase.
  • Preserve supported variants, extensions, and private-use suffixes without database canonicalization.

§Non-goals

  • Full CLDR canonicalization.
  • ICU replacement behavior.
  • Translation catalogs.
  • Message formatting.
  • Locale data loading.

§License

Licensed under either of the following, at your option:

  • Apache License, Version 2.0
  • MIT license

Structs§

LocaleTag
A normalized locale tag.
LocaleTagParts
Parsed locale tag components.

Functions§

is_locale_tag
Returns true when the input is a supported locale tag shape.
normalize_locale_tag
Normalizes a locale tag when it is syntactically valid for this crate’s subset.
parse_locale_tag
Parses a locale tag and normalizes its core language, script, and region subtags.
parse_locale_tag_parts
Parses a locale tag into normalized parts.