rust-language-tags
Language tags can be used identify human languages, scripts e.g. Latin script, countries and other regions.
Language tags are defined in BCP47, an introduction is
"Language tags in HTML and XML" by
the W3C. They are commonly used in HTML and HTTP Content-Language
and Accept-Language
header fields.
This package currently supports parsing (fully conformant parser), formatting and comparing language tags.
Examples
Create a simple language tag representing the French language as spoken in Belgium and print it:
use LanguageTag;
let mut langtag: LanguageTag = Default default;
langtag.language = Some;
langtag.region = Some;
assert_eq!;
Parse a tag representing a special type of English specified by private agreement:
use LanguageTag;
let langtag: LanguageTag = "en-x-twain".parse.unwrap;
assert_eq!;
assert_eq!;
You can check for equality, but more often you should test if two tags match.
In this example we check if the resource in German language is suitable for
a user from Austria. While people speaking Austrian German normally understand
standard German the opposite is not always true. So the resource can be presented
to the user but if the resource was in de-AT
and a user asked for a representation
in de
the request should be rejected.
use LanguageTag;
let mut langtag1: LanguageTag = Default default;
langtag1.language = Some;
langtag1.region = Some;
let mut langtag2: LanguageTag = Default default;
langtag2.language = Some;
assert!;
There is also the langtag!
macro for creating language tags.