Debian Codegraph @

third_party/rust/unic-langid/README.md

raw
1 # unic-langid [![Build Status](https://travis-ci.org/zbraniecki/unic-locale.svg?branch=master)](https://travis-ci.org/zbraniecki/unic-locale) [![Coverage Status](https://coveralls.io/repos/github/zbraniecki/unic-locale/badge.svg?branch=master)](https://coveralls.io/github/zbraniecki/unic-locale?branch=master)
2
3 `unic-langid` is an API for managing [Unicode Language Identifiers](http://unicode.org/reports/tr35/#Unicode_language_identifier).
4
5 The crate provides a way to create a struct from a string, manipulate its fields, canonicalize it, and serialize into a string.
6
7 Usage
8 -----
9
10 ```rust
11 use unic_langid::LanguageIdentifier;
12
13 let loc: LanguageIdentifier = "en-US".parse().expect("Parsing failed.");
14
15 assert_eq!(loc.language(), "en");
16 assert_eq!(loc.script(), None);
17 assert_eq!(loc.region(), Some("US"));
18
19 loc.set_script(Some("latn"));
20
21 assert_eq!(&loc.to_string(), "en-Latn-US");
22 ```
23
24 ```rust
25 use unic_langid::LanguageIdentifier;
26
27 let langid = LanguageIdentifier::from_parts(
28 Some("en"),
29 None,
30 None,
31 Some(&["nedis", "macos"])
32 ).expect("Parsing failed.");
33
34 assert_eq!(&langid.to_string(), "en-macos-nedis")
35 ```
36
37 Macros
38 ------
39
40 `unic-langid` can be also compiled with `features = ["macros"]` which enables `langid!` macro:
41
42 ```rust
43 use unic_langid::langid;
44
45 // The `const` assignment will currently work only
46 // if the langid doesn't contain any variants.
47 const EN_US: LanguageIdentifier = langid!("en-US");
48
49 fn main() {
50 let de_at = langid!("de-AT");
51
52 assert_eq!(&de_at.to_string(), "de-AT")
53 assert_eq!(&EN_US.to_string(), "en-US")
54 }
55 ```
56
57 The macro allows for compile-time parsing and validation of literal language identifiers.
58
59 Status
60 ------
61
62 The crate is mostly complete on the `well-formed` level. The next batch of work will go into
63 API maturity.
64
65 Get Involved
66 ------------
67
68 `unic-langid` is open-source, licensed under the Apache License, Version 2.0. We
69 encourage everyone to take a look at our code and we'll listen to your
70 feedback.