Localize.LanguageTag.Parser (Localize v0.38.0)

Copy Markdown View Source

Parses a CLDR language tag (also referred to as locale string).

The applicable specification is from CLDR which is similar based upon RFC5646 with some variations.

This module performs grammar-level parsing only. It returns a bare map with language, script, and territory as strings (no atomization). Validity checking and atomization happen in Localize.LanguageTag.parse/1, which gates atomization behind the bounded validity sets so untrusted input cannot exhaust the atom table.

Summary

Functions

Parse a locale identifier into a bare map of subtag fields.

Parse a locale identifier into a bare map, raising on error.

Functions

normalize_field(other)

parse(locale)

Parse a locale identifier into a bare map of subtag fields.

  • locale_id is a string representation of a language tag as defined by RFC5646.

Returns

  • {:ok, map} where map carries the parsed subtags. The :language, :script, and :territory values are normalised strings (not atoms); the caller is responsible for validating and atomising them.

  • {:error, exception} if the grammar parse fails.

parse!(locale)

Parse a locale identifier into a bare map, raising on error.

See parse/1 for the return shape.