lang_tags v0.1.0 LangTags.Tag

Tags registered according to the rules in RFC3066

Please note that this tags appears in records whose type is either ‘grandfathered’ or ‘redundant’ and contains a tag registered under RFC3066.

For more information, see section 2.2.8

Summary

Functions

For grandfathered or redundant tags, returns a date string reflecting the date the tag was added to the registry

For grandfathered or redundant tags, returns a date string reflecting the deprecation date if the tag is deprecated

Returns a list of tag descriptions for grandfathered or redundant tags, otherwise returns an empty list

Find a subtag of the given type from those making up the tag

Format a tag according to the case conventions defined in RFC 5646 section 2.1.1

Returns true if the tag is grandfathered, otherwise returns false

Shortcut for find/2 with a language filter

Creates a new tag as a map

If the tag is listed as deprecated or redundant it might have a preferred value. This method returns a tag as a map if so

Returns true if the tag is redundant, otherwise returns false

Shortcut for find/2 with a region filter

Shortcut for find/2 with a script filter

Returns a list of subtags making up the tag, as Subtag maps

Returns “grandfathered” if the tag is grandfathered, “redundant” if the tag is redundant, and “tag” if neither

Returns true if the tag is valid, false otherwise

Functions

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

For grandfathered or redundant tags, returns a date string reflecting the date the tag was added to the registry.

Examples

iex> LangTags.Tag.added("cel-gaulish")
"2001-05-25"
deprecated(tag)
deprecated(map | String.t) :: String.t | nil

For grandfathered or redundant tags, returns a date string reflecting the deprecation date if the tag is deprecated.

Examples

iex> LangTags.Tag.deprecated("art-lojban")
"2003-09-02"
iex> "zh-cmn-Hant" |> LangTags.Tag.new() |> LangTags.Tag.deprecated()
"2009-07-29"
descriptions(tag)
descriptions(map | String.t) :: String.t | []

Returns a list of tag descriptions for grandfathered or redundant tags, otherwise returns an empty list.

Examples

iex> LangTags.Tag.descriptions("art-lojban")
["Lojban"]
errors(tag)
find(tag, filter)
find(map | String.t, String.t) :: map

Find a subtag of the given type from those making up the tag.

Examples

iex> LangTags.Tag.find("az-arab", "script")
%{"Record" => %{"Added" => "2005-10-16", "Description" => ["Arabic"],
  "Subtag" => "arab", "Type" => "script"}, "Subtag" => "arab"}
format(tag)
format(map | String.t) :: String.t

Format a tag according to the case conventions defined in RFC 5646 section 2.1.1.

Examples

iex> LangTags.Tag.format("en-gb-oed")
"en-GB-oed"
iex> "en-gb" |> LangTags.Tag.new() |> LangTags.Tag.format()
"en-GB"
grandfathered?(tag)
grandfathered?(String.t) :: boolean

Returns true if the tag is grandfathered, otherwise returns false

Examples

iex> LangTags.Tag.grandfathered?("zh-xiang")
true
iex> LangTags.Tag.grandfathered?("az-Arab")
false
language(tag)
language(map | String.t) :: map

Shortcut for find/2 with a language filter

Examples

iex> LangTags.Tag.language("az-arab")
%{"Record" => %{"Added" => "2005-10-16", "Description" => ["Azerbaijani"],
  "Scope" => "macrolanguage", "Subtag" => "az", "Type" => "language"},
  "Subtag" => "az"}
new(tag)
new(String.t) :: map

Creates a new tag as a map

Examples

iex> LangTags.Tag.new("en-gb-oed")
%{"Record" => %{"Added" => "2003-07-09", "Deprecated" => "2015-04-17",
    "Description" => ["English, Oxford English Dictionary spelling"],
    "Preferred-Value" => "en-GB-oxendict", "Tag" => "en-gb-oed",
    "Type" => "grandfathered"}, "Tag" => "en-gb-oed"}
preferred(tag)
preferred(map | String.t) :: map | nil

If the tag is listed as deprecated or redundant it might have a preferred value. This method returns a tag as a map if so.

Examples

iex> LangTags.Tag.preferred("i-klingon")
%{"Tag" => "tlh"}
iex> "zh-cmn-Hant" |> LangTags.Tag.new() |> LangTags.Tag.preferred()
%{"Tag" => "cmn-hant"}
redundant?(tag)
redundant?(String.t) :: boolean

Returns true if the tag is redundant, otherwise returns false

Examples

iex> LangTags.Tag.redundant?("az-Arab")
true
iex> LangTags.Tag.redundant?("zh-xiang")
false
region(tag)
region(map | String.t) :: map

Shortcut for find/2 with a region filter

Examples

iex> LangTags.Tag.region("en-gb-oeb")["Record"]["Description"] == ["United Kingdom"]
true
script(tag)
script(map | String.t) :: map

Shortcut for find/2 with a script filter

Examples

iex> LangTags.Tag.script("az-arab")
%{"Record" => %{"Added" => "2005-10-16", "Description" => ["Arabic"],
  "Subtag" => "arab", "Type" => "script"}, "Subtag" => "arab"}
subtags(tag)
subtags(map | String.t) :: [map] | []

Returns a list of subtags making up the tag, as Subtag maps.

Note that if the tag is grandfathered the result will be an empty list

Examples

iex> LangTags.Tag.subtags("en-gb-oed")
[]
iex> LangTags.Tag.subtags("az-arab")
LangTags.Tag.subtags("az-arab")
type(tag)
type(map | String.t) :: String.t

Returns “grandfathered” if the tag is grandfathered, “redundant” if the tag is redundant, and “tag” if neither.

For a definition of grandfathered and redundant tags, see RFC 5646 section 2.2.8.

Examples

iex> LangTags.Tag.type("art-lojban")
"grandfathered"
iex> LangTags.Tag.type("az-Arab")
"redundant"
valid?(tag)
valid?(map | String.t) :: boolean

Returns true if the tag is valid, false otherwise.