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

added(subtag)
added(map) :: String.t | nil

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"
collection?(subtag)
collection?(String.t) :: boolean

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
comments(subtag)
comments(map) :: [String.t] | []

Returns an list of comments, if any, otherwise returns an empty list.

Examples

iex> LangTags.language("nmf") |> LangTags.SubTag.comments()
["see ntx"]
deprecated(subtag)
deprecated(map) :: String.t | nil

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"
descriptions(subtag)
descriptions(map) :: String.t | nil

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"]
extlang?(subtag)
extlang?(String.t) :: boolean

Returns true if subtag is of “extlang” type, false otherwise.

Examples

iex> LangTags.SubTag.extlang?("acm")
true
find(subtag, type)
find(String.t, String.t) :: map | nil

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
format(subtag)
format(map) :: String.t

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: mn for Mongolian
  • script codes are made lowercase with the initial letter capitalized, for example: Cyrl for Cyrillic
  • country codes are capitalized, for example: MN for 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"
language?(subtag)
language?(String.t) :: boolean

Returns true if subtag is of “language” type, false otherwise.

Examples

iex> LangTags.SubTag.language?("af")
true
macrolanguage?(subtag)
macrolanguage?(String.t) :: boolean

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
new(subtag, type)
new(String.t, String.t) :: map

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'.
preferred(subtag)
preferred(map) :: map | nil

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"}
private_use?(subtag)
private_use?(String.t) :: boolean

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
region?(subtag)
region?(String.t) :: boolean

Returns true if subtag is of “region” type, false otherwise.

Examples

iex> LangTags.SubTag.region?("ad")
true
iex> LangTags.SubTag.region?("en")
false
scope(subtag)
scope(map) :: String.t

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"
script(subtag)
script(map) :: map | nil

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
script?(subtag)
script?(String.t) :: boolean

Returns true if subtag is of “script” type, false otherwise.

Examples

iex> LangTags.SubTag.script?("aghb")
true
special?(subtag)
special?(String.t) :: boolean

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
type(subtag)
type(map) :: String.t | nil

Get the subtag type

See RFC 5646 section 2.2 for type definitions.

Examples

iex> LangTags.language("af") |> LangTags.SubTag.type() == "language"
true
variant?(subtag)
variant?(String.t) :: boolean

Returns true if subtag is of “variant” type, false otherwise.

Examples

iex> LangTags.SubTag.variant?("1901")
true