lang_tags v0.1.0 LangTags
The Language Tag according to the BCP47
Language tags are used to help identify languages, whether spoken, written, signed, or otherwise signaled, for the purpose of communication. This includes constructed and artificial languages but excludes languages not intended primarily for human communication, such as programming languages.
For more information, see BCP47
Summary
Functions
Shortcut for LangTags.Tag.valid?/1. Returns true if the tag is valid, false otherwise
Returns the file date for the underlying data, as a string
The opposite of subtags/1. Returns a list of codes that are not registered subtags, otherwise returns an empty array
Convenience method to get a single language type subtag. Returns a subtag map or nil
Returns a list of subtag maps representing all the language type subtags belonging to the given macrolanguage type subtag
As language/1, but with region type subtags
As language/1, but with script type subtags
Look up one or more subtags. Returns a list of subtag maps. Returns an empty list if all of the subtags are non-existent
Shortcut for LangTags.Tag.new/1
Get a subtag by type. Returns the subtag matching type as a subtag map otherwise returns nil
Look up for one or more types for the given string
Functions
Shortcut for LangTags.Tag.valid?/1. Returns true if the tag is valid, false otherwise.
For meaningful error output see errors/1.
Returns the file date for the underlying data, as a string.
Examples
iex> LangTags.date() |> String.match?(~r/\d{4}-\d{2}-\d{2}/)
true
The opposite of subtags/1. Returns a list of codes that are not registered subtags, otherwise returns an empty array.
Examples
iex> LangTags.filter(["en", "Aargh"])
["Aargh"]
Convenience method to get a single language type subtag. Returns a subtag map or nil.
Examples
iex> LangTags.language("en")
%{"Record" => %{"Added" => "2005-10-16", "Description" => ["English"],
"Subtag" => "en", "Suppress-Script" => "Latn", "Type" => "language"},
"Subtag" => "en"}
iex> LangTags.language("us")
nil
Returns a list of subtag maps representing all the language type subtags belonging to the given macrolanguage type subtag.
Throws an error if macrolanguage is not a macrolanguage.
Examples
iex> LangTags.languages("zh") |> Enum.count()
28
iex> LangTags.languages("en")
** (ArgumentError) 'en' is not a valid macrolanguage.
As language/1, but with region type subtags.
Examples
iex> LangTags.region("mt")
%{"Record" => %{"Added" => "2005-10-16", "Description" => ["Malta"],
"Subtag" => "mt", "Type" => "region"}, "Subtag" => "mt"}
iex> LangTags.region("en")
nil
As language/1, but with script type subtags.
Examples
iex> LangTags.script("aghb")
%{"Record" => %{"Added" => "2012-11-01",
"Description" => ["Caucasian Albanian"], "Subtag" => "aghb",
"Type" => "script"}, "Subtag" => "aghb"}
iex> LangTags.script("en")
nil
Look up one or more subtags. Returns a list of subtag maps. Returns an empty list if all of the subtags are non-existent.
Examples
Calling LangTags.subtags("mt") will return an array with 2 subtag maps: one
for Malta (the ‘region’ type subtag) and one for Maltese (the ‘language’ type
subtag).
iex> for subtag <- LangTags.subtags("mt"), do: subtag["Record"]["Description"]
[["Maltese"], ["Malta"]]
iex> LangTags.subtags(["mt", "ca"]) |> Enum.count()
4
iex> LangTags.subtags("bumblebee")
[]
To get or check a single subtag by type use language/1, region/1 or
type/2.
Shortcut for LangTags.Tag.new/1
Examples
iex> LangTags.tags("art-lojban") == LangTags.Tag.new("art-lojban")
true
Get a subtag by type. Returns the subtag matching type as a subtag map otherwise returns nil.
A type consists of one of the following strings: language, extlang,
script, region or variant. To get a grandfathered or redundant type
tag use tags/1.
Examples
iex> LangTags.type("zh", "language") == LangTags.language("zh")
true
iex> LangTags.type("zh", "script")
nil
Look up for one or more types for the given string.
Returns an empty list if the does not have any type or if the available types are: grandfathered or redundant.
By default, the types grandfathered or redundant are excluded from the
result. Set the all parameter to true to include them.
Examples
iex> LangTags.types("en")
["language"]
iex> LangTags.types("xml")
["extlang", "language"]
iex> LangTags.types("art-lojban")
[]
iex> LangTags.types("art-lojban", true)
["grandfathered"]