There are still some unresolved questions around more complex locales, but the base case of en_US.utf8
seems to work correctly.
T6JEWQJ7KI4SQFGIZNRKCWD5DEUVTIPEWXU7AX6WM7IU4DBSQZRQC
pub fn icu_locale(&self) -> Result<Locale, icu_locid::ParserError> {
let language = subtags::Language::try_from_bytes(self.language.as_bytes())?;
let region = if let Some(territory) = self.territory {
Some(subtags::Region::try_from_bytes(territory.as_bytes())?)
} else {
None
};
// TODO: should script/variants always be empty?
let language_id = LanguageIdentifier {
language,
script: None,
region,
variants: Variants::new(),
};
// TODO: should attributes always be empty?
let unicode_extensions = Unicode {
keywords: POSIX_KEYWORD,
attributes: Attributes::new(),
};
let extensions = Extensions::from_unicode(unicode_extensions);
Ok(Locale {
id: language_id,
extensions,
})
}