= i18nutility Rizzen Yazston :icu4x: https://github.com/unicode-org/icu4x :url-unicode: https://home.unicode.org/ :BCP47LanguageTag: https://www.rfc-editor.org/rfc/bcp/bcp47.txt

Welcome to the utility crate of the Internationalisation (i18n) project.

This crate consists of two modules:

== Registry for holding ICU4X Locale objects.

This module contains the LanguageTagRegistry type, to provide a simple container that caches the {BCP47Language_Tag}[BCP 47 Language Tag] strings and the Locale type for querying language tags. The purpose of the registry is to reduce the need of parsing language tags repeatedly, by storing the result Locale for querying language tag in the registry, and uses the existing Locale for the querying language tag when requested.

The Locale type can be provided by either the icu_locid crate or the icu meta-crate. These two crates are part of the {icu4x}[ICU4X] protect developed by the {url-unicode}[Unicode Consortium].

This crate makes use of the Locale type instead of the LanguageIdentifier type due to that the Locale type supports the entire BCP 47 Language Tag specification, where as the LanguageIdentifier type excludes the extension subtags of the BCP 47 Language Tag specification.

== Language string.

This crate contains the LString type (aka LanguageString), for associating a text string (String) to a specific language (Rc<String>).

The specified language is expected to be a {BCP47Language_Tag}[BCP 47 Language Tag] string, though any identifier could be used.

== Acknowledgements

Stefano Angeleri for advice on various design aspects of implementing the library of the Internationalisation project, and also providing the Italian translation of error message strings.

== Usage

Simply include the i18n_utility-rizzen-yazston crate in the Cargo.toml to make it available to the application or library.

=== Cargo.toml

[dependencies] i18n_utility-rizzen-yazston = "0.6.1" icu_locid = "1.2.0"

=== Examples

==== LanguageTagRegistry ``` use iculocid::Locale; use std::rc::Rc; use i18nutility::registry::LanguageTagRegistry;

let mut registry = LanguageTagRegistry::new(); let result = registry.get( "en_ZA" ).expect( "Failed to parse language tag." ); let tags = registry.list().iter().count();

asserteq!( result.0.asstr(), "en-ZA", "Did not convert enZA to en-ZA BCP 47 format." ); asserteq!( tags, 1, "Supposed to be 1 entries: en-ZA." ) ```

==== LString ``` use iculocid::Locale; use std::rc::Rc; use i18nutility::LString;

let string = "This is a test string."; let tag = Rc::new( Locale::canonicalize( "en-ZA" ).expect( "Failed to canonicalise language tag." ) ); let langstring = LString::new( string, &tag ); asserteq!( langstring.asstr(), string, "String failed." ); asserteq!( langstring.language_tag(), &tag, "Language tag failed." ); ```