lang_tags v0.1.0 LangTags.SubTag
Subtags according to the BCP47
This module contains the subtags defined in the BCP47, the allowed types for a subtag are: “language”, “extlang”, “script”, “region”, or variant.
Summary
Functions
Returns a date string reflecting the date the subtag was added to the registry
Indicates if the given string is a subtag that represents a collection of languages
Returns an list of comments, if any, otherwise returns an empty list
Returns a date string reflecting the deprecation date if the subtag is deprecated, otherwise returns nil
Returns the list of description strings (a subtag may have more than one description)
Returns true if subtag is of “extlang” type, false otherwise
If found, returns a map for the given subtag, nil otherwise
Return the subtag code formatted according to the case conventions defined in RFC 5646 section 2.1.1
Returns true if subtag is of “language” type, false otherwise
Indicates if the given string is a macrolanguage as defined by ISO 639-3
Creates a new subtag as a map
Returns a preferred subtag as a map if the subtag is deprecated
Indicates if the given string represents a code reserved for private use in the ISO 639 standard
Returns true if subtag is of “region” type, false otherwise
Returns the subtag scope as a string, or “individual” if the subtag has no scope
Returns a Subtag map representing the language’s default script
Returns true if subtag is of “script” type, false otherwise
Indicates if the given string represents a special language code
Get the subtag type
Returns true if subtag is of “variant” type, false otherwise
Functions
Returns a date string reflecting the date the subtag was added to the registry.
Examples
iex> LangTags.language("ja") |> LangTags.SubTag.added()
"2005-10-16"
Indicates if the given string is a subtag that represents a collection of languages
A collection is typically related by some type of historical, geographical, or linguistic association.
Unlike a macrolanguage, a collection can contain languages that are only loosely related and a collection cannot be used interchangeably with languages that belong to it.
Examples
iex> LangTags.SubTag.collection?("cdd")
true
Returns an list of comments, if any, otherwise returns an empty list.
Examples
iex> LangTags.language("nmf") |> LangTags.SubTag.comments()
["see ntx"]
Returns a date string reflecting the deprecation date if the subtag is deprecated, otherwise returns nil.
Examples
iex> LangTags.language("in") |> LangTags.SubTag.deprecated()
"1989-01-01"
Returns the list of description strings (a subtag may have more than one description)
Examples
iex> LangTags.language("ro") |> LangTags.SubTag.descriptions()
["Romanian", "Moldavian", "Moldovan"]
Returns true if subtag is of “extlang” type, false otherwise.
Examples
iex> LangTags.SubTag.extlang?("acm")
true
If found, returns a map for the given subtag, nil otherwise.
Examples
iex> LangTags.SubTag.find("tlh", "language")
%{"Record" => %{"Added" => "2005-10-16",
"Description" => ["Klingon", "tlhIngan-Hol"], "Subtag" => "tlh",
"Type" => "language"}, "Subtag" => "tlh"}
iex> LangTags.SubTag.find("ef", "script")
nil
Return the subtag code formatted according to the case conventions defined in RFC 5646 section 2.1.1.
- language codes are made lowercase, for example:
mnfor Mongolian - script codes are made lowercase with the initial letter capitalized, for example:
Cyrlfor Cyrillic - country codes are capitalized, for example:
MNfor Mongolia
Examples
iex> LangTags.language("mn") |> LangTags.SubTag.format()
"mn"
iex> LangTags.script("cyrl") |> LangTags.SubTag.format()
"Cyrl"
iex> LangTags.region("mn") |> LangTags.SubTag.format()
"MN"
Returns true if subtag is of “language” type, false otherwise.
Examples
iex> LangTags.SubTag.language?("af")
true
Indicates if the given string is a macrolanguage as defined by ISO 639-3.
A macrolanguage is a cluster of closely related languages that are sometimes considered to be a single language.
Examples
iex> LangTags.SubTag.macrolanguage?("kpe")
true
Creates a new subtag as a map
Examples
iex> LangTags.SubTag.new("es", "language")
LangTags.SubTag.new("es", "language")
iex> LangTags.SubTag.new("es", "script")
** (ArgumentError) non-existent subtag 'es' of type 'script'.
Returns a preferred subtag as a map if the subtag is deprecated.
Examples
# `ro` is preferred over deprecated `mo`.
iex> LangTags.language("mo") |> LangTags.SubTag.preferred()
%{"Record" => %{"Added" => "2005-10-16",
"Description" => ["Romanian", "Moldavian", "Moldovan"], "Subtag" => "ro",
"Suppress-Script" => "Latn", "Type" => "language"}, "Subtag" => "ro"}
Indicates if the given string represents a code reserved for private use in the ISO 639 standard.
Subtags with this scope can be used to indicate a primary language for which no ISO 639 or registered assignment exists.
Examples
iex> LangTags.SubTag.private_use?("qaa..qtz")
true
Returns true if subtag is of “region” type, false otherwise.
Examples
iex> LangTags.SubTag.region?("ad")
true
iex> LangTags.SubTag.region?("en")
false
Returns the subtag scope as a string, or “individual” if the subtag has no scope.
Examples
iex> LangTags.language("zh") |> LangTags.SubTag.scope()
"macrolanguage"
iex> LangTags.language("nah") |> LangTags.SubTag.scope()
"collection"
Returns a Subtag map representing the language’s default script.
For subtags of type language or extlang, returns a Subtag map
representing the language’s default script. See RFC 5646 section 3.1.9
for a definition of Suppress-Script.
Examples
iex> LangTags.language("af") |> LangTags.SubTag.script() == LangTags.SubTag.new("Latn", "script")
true
iex> LangTags.language("ae") |> LangTags.SubTag.script()
nil
Returns true if subtag is of “script” type, false otherwise.
Examples
iex> LangTags.SubTag.script?("aghb")
true
Indicates if the given string represents a special language code.
These are subtags used for identifying linguistic attributes not particularly associated with a concrete language. These include codes for when the language is undetermined or for non-linguistic content.
Examples
iex> LangTags.SubTag.special?("zxx")
true
Get the subtag type
See RFC 5646 section 2.2 for type definitions.
Examples
iex> LangTags.language("af") |> LangTags.SubTag.type() == "language"
true