Repository navigation
A feature and bugfix release with breaking changes: two record fields changed shape, and valid?/1 changed in both directions. See Upgrading from 0.3 before you update. The bundled IANA registry moves from File-Date 2026-08-08 to 2026-11-18.
Canonicalize a tag
preferred/1 only replaces a tag that is registered as a whole, so "iw-IL" had no preferred value although iw has been he since 1989. LangTags.Tag.canonicalize/1 returns the canonical form of RFC 5646 section 4.5, repairing the subtags inside a tag as well:
iex> canonical = &(&1 |> LangTags.Tag.canonicalize() |> LangTags.Tag.format())
# Deprecated subtags are replaced by their preferred values.
iex> canonical.("iw-IL")
"he-IL"
iex> canonical.("en-BU")
"en-MM"
# A language and its extlang collapse into the extlang's preferred language.
iex> canonical.("zh-yue-HK")
"yue-HK"
# Grandfathered and redundant tags are replaced, including one that only
# appears once a subtag has been replaced: "sgn-DD" is "sgn-DE", which is "gsg".
iex> canonical.("i-klingon")
"tlh"
iex> canonical.("sgn-DD")
"gsg"
# Extensions are ordered by singleton, with private use kept last.
iex> canonical.("en-u-ca-buddhist-t-fr")
"en-t-fr-u-ca-buddhist"Deprecation is the only problem it repairs. Whatever else errors/1 reports for a tag, it reports for the canonical form too, so "canonicalize, then validate" never lets a malformed tag through:
- An extlang is collapsed only under the language the registry gives as its prefix, and only when it is the tag's one extlang.
"en-yue"and"zh-yue-cmn"are left as they are. - A script that restates the language's
Suppress-Scriptis kept:"en-Latn"stays"en-Latn". - Anything without a preferred value is left alone, so the result is not guaranteed to be valid.
Stricter well-formedness
valid?/1 returned true for several tags that are not well-formed. They are now rejected, under four new errors/1 codes:
| Tag | Code |
|---|---|
x, en-x |
:empty_private_use |
en-u |
:empty_extension |
en-a-bbb-a-ccc |
:duplicate_extension |
en_US, en-x-!!!, é |
:invalid_character |
A tag opening with an extension, such as a-bbb, is rejected as :no_language.
iex> LangTags.Tag.errors("en-u")
[%{code: :empty_extension, subtag: "u", message: "the extension 'u' is not followed by a subtag"}]Two related parsing fixes:
- Everything after
xis read as private use, where single-character subtags are allowed.LangTags.Tag.private_use("en-x-a-b")returned[]and now returns["a", "b"]. LangTags.Tag.format/1no longer recases subtags inside an extension:"en-u-ca-buddhist-nu-thai"came back as"en-u-ca-buddhist-NU-Thai".
Private-use ranges are recognized
The registry reserves qaa..qtz (language), Qaaa..Qabx (script), and QM..QZ and XA..XZ (region) with one record each, and only the range as written was recognized. Codes inside a range now resolve to that range's record, so "qaa", "en-Qaaa" and "en-XA" are valid instead of :unknown.
Registry parsing
- Folded lines were misread. A description wrapped onto a second line was cut short:
iawas described as"Interlingua (International Auxiliary Language". 13 descriptions were affected, and one wrapped comment became a bogus field onbaku1926. - Only the last
Prefixwas kept. The variant1994has five and reported one. 17 records were affected. - An unrecognized line now fails the build instead of being guessed at, and
mix lang_tags.updaterefuses to write a download that contains one.
Registry data
The bundled registry grows from 9296 to 9298 records:
- Two variant subtags for Uzbek,
1995and2026, each with the prefixesuzanduz-Latn."uz-Latn-2026"is now valid. - The region
NRgains the description"Naoero", ahead of"Nauru".
Faster search
LangTags.search/2 with a string is about 20 times faster (around 3.0 ms to 0.15 ms for search("Maltese")). Descriptions are lowercased once at compile time instead of on every call, which adds about 200 KB to the compiled registry module. Results are unchanged, and searching with a Regex is unaffected.
Upgrading from 0.3
record["Prefix"]is always a list, including when there is one prefix: the variant1996gives["de"]. Code that reads it as a string needs updating.record["Comments"]holds one string per comment, not one per line of the registry file, soLangTags.SubTag.comments/1no longer breaks a sentence where the file wrapped it.valid?/1rejects the malformed tags above and accepts codes inside the private-use ranges."en_US"reports only:invalid_character, where it reported:unknownand:no_language.LangTags.Tag.new/1lowercases ASCII letters only. Unicode lowercasing turned KELVIN SIGN (U+212A) intok, so a region written with it passed forKR.
Full changelog: https://github.com/milmazz/lang_tags/blob/main/CHANGELOG.md · Docs: https://hexdocs.pm/lang_tags/0.4.0