Skip to main content

Locale.from_language_tag

Locale.from_language_tagtag

Documentation

Returns the locale specified by the provided IETF BCP47 language tag string.

Examples

Creating the locale en_US.

      import Standard.Base.Data.Locale.Locale

example_from_tag = Locale.from_language_tag "en_US"

Remarks

Language Tag Syntax

If the specified language tag contains any ill-formed subtags, the first such subtag and all following subtags are ignored.

The following conversions are performed:

  • The language code "und" is mapped to language "".
  • The language codes "he", "yi", and "id" are mapped to "iw", "ji", and "in" respectively.
  • The portion of a private use subtag prefixed by "lvariant", if any, is removed and appended to the variant field in the result locale (without case normalization).
  • When the languageTag argument contains an extlang subtag, the first such subtag is used as the language, and the primary language subtag and other extlang subtags are ignored.
  • Case is normalized except for variant tags, which are left unchanged. Language is normalized to lower case, script to title case, country to upper case, and extensions to lower case.
  • If, after processing, the locale would exactly match either ja_JP_JP or th_TH_TH with no extensions, the appropriate extensions are added.

This implements the 'Language-Tag' production of BCP47, and so supports grandfathered (regular and irregular) as well as private use language tags.