View Source Bonfire.Common.Localise.Cldr.Territory (Bonfire v0.9.10-classic-beta.169)
Summary
Functions
Returns a list of available styles.
Returns the available territory subdivisions for a given locale.
Returns the available territories for a given locale.
Lists children(s) for the given territory code.
Returns {:ok, list}
if successful, otherwise {:error, reason}
.
The same as children/2
, but raises an exception if it fails.
Checks relationship between two territories, where the first argument is the parent
and second the child
.
Returns true
if successful, otherwise false
.
Returns a list of country codes.
Localized string for the given LanguageTag.t
.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
The same as from_language_tag/2
, but raises an exception if it fails.
Localized string for the given subdivision code.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
The same as from_subdivision_code/2
, but raises an exception if it fails.
Localized string for the given territory code.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
The same as from_territory_code/2
, but raises an exception if it fails.
Maps territory info for the given territory code.
Returns {:ok, map}
if successful, otherwise {:error, reason}
.
The same as info/1
, but raises an exception if it fails.
Returns a map of all known territory subdivisions in a given locale.
Returns a map of all known territories in a given locale.
Returns a list of subdivisions of a given territory.
Lists parent(s) for the given territory code.
Returns {:ok, list}
if successful, otherwise {:error, reason}
.
The same as parent/2
, but raises an exception if it fails.
Returns a map of available subdivision aliases.
A helper method to get a territory's currency code
if a territory has multiply currencies then the oldest active currency is returned.
Returns {:ok, code}
if successful, otherwise {:error, reason}
.
The same as to_currency_code/2
, but raises an exception if it fails.
A helper method to get a territory's currency codes.
Returns {:ok, list}
if successful, otherwise {:error, reason}
.
The same as to_currency_codes/2
, but raises an exception if it fails.
Unicode flag for the given territory code.
Returns {:ok, flag}
if successful, otherwise {:error, reason}
.
The same as to_unicode_flag/1
, but raises an exception if it fails.
Translate a LanguageTag.t into a localized string from one locale to another.
Returns {:ok, result}
if successful, otherwise {:error, reason}
.
The same as translate_language_tag/2
, but raises an exception if it fails.
Translate a localized string from one locale to another.
Returns {:ok, result}
if successful, otherwise {:error, reason}
.
The same as translate_subdivision/3
, but raises an exception if it fails.
Translate a localized string from one locale to another.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
The same as translate_territory/3
, but raises an exception if it fails.
Functions
@spec available_styles() :: [:short | :standard | :variant]
Returns a list of available styles.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.available_styles()
[:short, :standard, :variant]
@spec available_subdivisions(atom() | String.t() | Cldr.LanguageTag.t()) :: [atom()] | {:error, {module(), String.t()}}
Returns the available territory subdivisions for a given locale.
locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
Example
=> Bonfire.Common.Localise.Cldr.Territory.available_subdivisions("en")
[:ad02, :ad03, :ad04, :ad05, :ad06, :ad07, :ad08, ...]
iex> Bonfire.Common.Localise.Cldr.Territory.available_subdivisions()
[]
iex> Bonfire.Common.Localise.Cldr.Territory.available_subdivisions("zzz")
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
@spec available_territories(atom() | String.t() | Cldr.LanguageTag.t()) :: [atom()] | {:error, {module(), String.t()}}
Returns the available territories for a given locale.
locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
Example
=> Bonfire.Common.Localise.Cldr.Territory.available_territories()
[:"001", :"002", :"003", :"005", :"009", :"011", :"013", :"014", :"015", :"017",
:"018", :"019", :"021", :"029", :"030", :"034", :"035", :"039", :"053", :"054",
:"057", :"061", :"142", :"143", :"145", :"150", :"151", :"154", :"155", :"202",
:"419", :AC, :AD, :AE, :AF, :AG, :AI, :AL, :AM, :AO, :AQ, :AR, :AS, :AT, :AU,
:AW, :AX, :AZ, :BA, :BB, ...]
iex> Bonfire.Common.Localise.Cldr.Territory.available_territories("zzz")
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
@spec children(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, atom() | String.t() | charlist()} | {:error, {module(), String.t()}}
Lists children(s) for the given territory code.
Returns {:ok, list}
if successful, otherwise {:error, reason}
.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.children(:EU)
{:ok,
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GR, :HR, :HU, :IE,
:IT, :LT, :LU, :LV, :MT, :NL, :PL, :PT, :SE, :SI, :SK, :BG, :RO]}
iex> Bonfire.Common.Localise.Cldr.Territory.children(:ZZZ)
{:error, {Cldr.UnknownTerritoryError, "The territory :ZZZ is unknown"}}
iex> Bonfire.Common.Localise.Cldr.Territory.children(:GB)
{:error, {Cldr.UnknownParentError, "The territory :GB has no children"}}
@spec children!(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: [ atom() | String.t() | charlist() ]
The same as children/2
, but raises an exception if it fails.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.children!(:EU)
[:AT, :BE, :CY, :CZ, :DE, :DK, :EE, :ES, :FI, :FR, :GR, :HR, :HU, :IE, :IT,
:LT, :LU, :LV, :MT, :NL, :PL, :PT, :SE, :SI, :SK, :BG, :RO]
@spec contains?(atom() | Cldr.LanguageTag.t(), atom() | Cldr.LanguageTag.t()) :: boolean()
Checks relationship between two territories, where the first argument is the parent
and second the child
.
Returns true
if successful, otherwise false
.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.contains?(:EU, :DK)
true
iex> Bonfire.Common.Localise.Cldr.Territory.contains?(:DK, :EU)
false
Returns a list of country codes.
options
are:as: :atom
as: :binary
as: :charlist
Example
=> Bonfire.Common.Localise.Cldr.Territory.country_codes()
[:AD, :AE, :AF, :AG, :AI, :AL, :AM, :AO, :AR, :AS, :AT, :AU, :AW,
:AX, :AZ, :BA, :BB, :BD, :BE, :BF, :BG, :BH, :BI, :BJ, :BL, :BM,
:BN, :BO, :BQ, :BR, :BS, :BT, :BV, :BW, :BY, :BZ, :CA, :CC, :CD,
:CF, :CG, :CH, :CI, :CK, :CL, :CM, :CN, :CO, :CR, :CU, ...]
@spec from_language_tag(Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Localized string for the given LanguageTag.t
.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
options
are:style
is one of those returned byBonfire.Common.Localise.Cldr.Territory.available_styles/0
. The current styles are:short
,:standard
and:variant
. The default is:standard
Example
iex> Bonfire.Common.Localise.Cldr.Territory.from_language_tag(Cldr.get_locale())
{:ok, "world"}
iex> Bonfire.Common.Localise.Cldr.Territory.from_language_tag(Cldr.get_locale(), [style: :short])
{:error, {Cldr.UnknownStyleError, "The style :short is unknown"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_language_tag(Cldr.get_locale(), [style: :ZZZ])
{:error, {Cldr.UnknownStyleError, "The style :ZZZ is unknown"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_language_tag(Cldr.get_locale(), [style: "ZZZ"])
{:error, {Cldr.UnknownStyleError, "The style \"ZZZ\" is unknown"}}
@spec from_language_tag!(Cldr.LanguageTag.t(), Keyword.t()) :: String.t()
The same as from_language_tag/2
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.from_language_tag!(Cldr.get_locale())
"world"
from_subdivision_code(subdivision_code, options \\ [])
View Source (since 2.2.0)@spec from_subdivision_code(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Localized string for the given subdivision code.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
options
are:locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
style
is one of those returned byBonfire.Common.Localise.Cldr.Territory.available_styles/0
. The current styles are:short
,:standard
and:variant
. The default is:standard
Example
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code("gbcma", locale: "en")
{:ok, "Cumbria"}
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code("gbcma", locale: "pl")
{:ok, "Kumbria"}
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code("gbcma", locale: "bs")
{:error, {Cldr.UnknownSubdivisionError, "No subdivision translation for :gbcma could be found in locale :bs"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code("invalid", locale: "en")
{:error, {Cldr.UnknownTerritoryError, "The territory \"invalid\" is unknown"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code("gbcma", [locale: :zzz])
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code("gbcma", [locale: "zzz"])
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
from_subdivision_code!(subdivision_code, options \\ [])
View Source (since 2.2.0)@spec from_subdivision_code!(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: String.t()
The same as from_subdivision_code/2
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code!("gbcma", locale: "en")
"Cumbria"
iex> Bonfire.Common.Localise.Cldr.Territory.from_subdivision_code!("gbcma", locale: "pl")
"Kumbria"
@spec from_territory_code(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Localized string for the given territory code.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
options
are:locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
style
is one of those returned byBonfire.Common.Localise.Cldr.Territory.available_styles/0
. The current styles are:short
,:standard
and:variant
. The default is:standard
Example
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code(:GB)
{:ok, "United Kingdom"}
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code(:GB, [style: :short])
{:ok, "UK"}
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code(:GB, [style: :ZZZ])
{:error, {Cldr.UnknownStyleError, "The style :ZZZ is unknown"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code(:GB, [style: "ZZZ"])
{:error, {Cldr.UnknownStyleError, "The style \"ZZZ\" is unknown"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code(:GB, [locale: "pt"])
{:ok, "Reino Unido"}
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code(:GB, [locale: :zzz])
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code(:GB, [locale: "zzz"])
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
@spec from_territory_code!(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: String.t()
The same as from_territory_code/2
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code!(:GB)
"United Kingdom"
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code!(:GB, [style: :short])
"UK"
iex> Bonfire.Common.Localise.Cldr.Territory.from_territory_code!(:GB, [locale: "pt"])
"Reino Unido"
@spec info(atom() | Cldr.LanguageTag.t()) :: {:ok, map()} | {:error, {module(), String.t()}}
Maps territory info for the given territory code.
Returns {:ok, map}
if successful, otherwise {:error, reason}
.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.info(:GB)
{:ok,
%{
currency: [GBP: %{from: ~D[1694-07-27]}],
gdp: 2925000000000,
language_population: %{
"ar" => %{population_percent: 0.3},
"bn" => %{population_percent: 0.4},
"cy" => %{official_status: "official_regional", population_percent: 1.3},
"de" => %{population_percent: 9},
"en" => %{official_status: "official", population_percent: 98},
"es" => %{population_percent: 8},
"fr" => %{population_percent: 23},
"ga" => %{official_status: "official_regional", population_percent: 0.15},
"gd" => %{
official_status: "official_regional",
population_percent: 0.11,
writing_percent: 5
},
"gu" => %{population_percent: 2.9},
"it" => %{population_percent: 0.2},
"kw" => %{population_percent: 0.003},
"lt" => %{population_percent: 0.2},
"pa" => %{population_percent: 3.6},
"pl" => %{population_percent: 4},
"pt" => %{population_percent: 0.2},
"sco" => %{population_percent: 2.5, writing_percent: 5},
"so" => %{population_percent: 0.2},
"ta" => %{population_percent: 3.2},
"tr" => %{population_percent: 0.2},
"ur" => %{population_percent: 3.5},
"zh-Hant" => %{population_percent: 0.3},
"en-Shaw" => %{population_percent: 0}
},
literacy_percent: 99,
measurement_system: %{
default: :uksystem,
paper_size: :a4,
temperature: :uksystem
},
population: 65761100
}}
@spec info!(atom() | Cldr.LanguageTag.t()) :: map()
The same as info/1
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.info!(:GB)
%{
currency: [GBP: %{from: ~D[1694-07-27]}],
gdp: 2925000000000,
language_population: %{
"ar" => %{population_percent: 0.3},
"bn" => %{population_percent: 0.4},
"cy" => %{official_status: "official_regional", population_percent: 1.3},
"de" => %{population_percent: 9},
"en" => %{official_status: "official", population_percent: 98},
"es" => %{population_percent: 8},
"fr" => %{population_percent: 23},
"ga" => %{official_status: "official_regional", population_percent: 0.15},
"gd" => %{
official_status: "official_regional",
population_percent: 0.11,
writing_percent: 5
},
"gu" => %{population_percent: 2.9},
"it" => %{population_percent: 0.2},
"kw" => %{population_percent: 0.003},
"lt" => %{population_percent: 0.2},
"pa" => %{population_percent: 3.6},
"pl" => %{population_percent: 4},
"pt" => %{population_percent: 0.2},
"sco" => %{population_percent: 2.5, writing_percent: 5},
"so" => %{population_percent: 0.2},
"ta" => %{population_percent: 3.2},
"tr" => %{population_percent: 0.2},
"ur" => %{population_percent: 3.5},
"zh-Hant" => %{population_percent: 0.3},
"en-Shaw" => %{population_percent: 0}
},
literacy_percent: 99,
measurement_system: %{
default: :uksystem,
paper_size: :a4,
temperature: :uksystem
},
population: 65761100
}
@spec known_subdivisions(atom() | String.t() | Cldr.LanguageTag.t()) :: map() | {:error, {module(), String.t()}}
Returns a map of all known territory subdivisions in a given locale.
locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
Example
=> Bonfire.Common.Localise.Cldr.Territory.known_subdivisions("en")
%{
"ad02" => "Canillo",
"ad03" => "Encamp",
"ad04" => "La Massana",
"ad05" => "Ordino",
"ad06" => "Sant JuliΓ de LΓ²ria",
"ad07" => "Andorra la Vella",
...
iex> Bonfire.Common.Localise.Cldr.Territory.known_subdivisions()
%{}
iex> Bonfire.Common.Localise.Cldr.Territory.known_subdivisions("zzz")
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
@spec known_territories(atom() | String.t() | Cldr.LanguageTag.t()) :: map() | {:error, {module(), String.t()}}
Returns a map of all known territories in a given locale.
locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
Example
=> Bonfire.Common.Localise.Cldr.Territory.known_territories()
%{SN: %{standard: "Senegal"}, "061": %{standard: "Polynesia"},
BH: %{standard: "Bahrain"}, TM: %{standard: "Turkmenistan"},
"009": %{standard: "Oceania"}, CW: %{standard: "Curaçao"},
FR: %{standard: "France"}, TN: %{standard: "Tunisia"},
FI: %{standard: "Finland"}, BF: %{standard: "Burkina Faso"},
"155": %{standard: "Western Europe"}, GL: %{standard: "Greenland"},
VI: %{standard: "U.S. Virgin Islands"}, ZW: %{standard: "Zimbabwe"},
AR: %{standard: "Argentina"}, SG: %{standard: "Singapore"},
SZ: %{standard: "Swaziland"}, ID: %{standard: "Indonesia"},
NR: %{standard: "Nauru"}, RW: %{standard: "Rwanda"},
TR: %{standard: "Turkey"}, IS: %{standard: "Iceland"},
ME: %{standard: "Montenegro"}, AW: %{standard: "Aruba"},
PY: %{standard: "Paraguay"}, "145": %{standard: "Western Asia"},
CG: %{standard: "Congo - Brazzaville", variant: "Congo (Republic)"},
LT: %{standard: "Lithuania"}, SA: %{standard: "Saudi Arabia"},
MZ: %{standard: "Mozambique"}, NU: %{standard: "Niue"},
NG: %{standard: "Nigeria"}, CK: %{standard: "Cook Islands"},
ZM: %{standard: "Zambia"}, LK: %{standard: "Sri Lanka"},
UY: %{standard: "Uruguay"}, YE: %{standard: "Yemen"},
"011": %{standard: "Western Africa"},
CC: %{standard: "Cocos (Keeling) Islands"}, BY: %{standard: "Belarus"},
IL: %{standard: "Israel"}, KY: %{standard: "Cayman Islands"},
GN: %{standard: "Guinea"}, VN: %{standard: "Vietnam"},
PE: %{standard: "Peru"}, HU: %{standard: "Hungary"},
HN: %{standard: "Honduras"}, GI: %{standard: "Gibraltar"},
"142": %{standard: "Asia"}, "029": %{...}, ...}
=> Bonfire.Common.Localise.Cldr.Territory.known_territories("zzz")
{:error, {Cldr.InvalidLanguageError, "The language "zzz" is invalid"}}
@spec known_territory_subdivisions(atom() | String.t() | Cldr.LanguageTag.t()) :: {:ok, [String.t()] | nil} | {:error, {module(), String.t()}}
Returns a list of subdivisions of a given territory.
Example
=> Bonfire.Common.Localise.Cldr.Territory.known_territory_subdivisions(:GB)
{:ok, ["gbabc", "gbabd", "gbabe", "gbagb", "gbagy", "gband", "gbann",
"gbans", "gbbas", "gbbbd", "gbbdf", "gbbdg", "gbben", "gbbex", "gbbfs",
"gbbge", "gbbgw", "gbbir", "gbbkm", "gbbmh", "gbbne", "gbbnh", "gbbns",
"gbbol", "gbbpl", "gbbrc", "gbbrd", "gbbry", "gbbst", "gbbur", "gbcam",
"gbcay", "gbcbf", "gbccg", "gbcgn", "gbche", "gbchw", "gbcld", "gbclk",
"gbcma", "gbcmd", "gbcmn", "gbcon", "gbcov", "gbcrf", "gbcry", "gbcwy",
"gbdal", "gbdby", "gbden", ...]}
=> Bonfire.Common.Localise.Cldr.Territory.known_territory_subdivisions(:AI)
{:ok, nil}
iex> Bonfire.Common.Localise.Cldr.Territory.known_territory_subdivisions(:ZZZ)
{:error, {Cldr.UnknownTerritoryError, "The territory :ZZZ is unknown"}}
@spec parent(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, atom() | String.t() | charlist()} | {:error, {module(), String.t()}}
Lists parent(s) for the given territory code.
Returns {:ok, list}
if successful, otherwise {:error, reason}
.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.parent(:GB)
{:ok, [:"154", :UN]}
iex> Bonfire.Common.Localise.Cldr.Territory.parent(:ZZZ)
{:error, {Cldr.UnknownTerritoryError, "The territory :ZZZ is unknown"}}
iex> Bonfire.Common.Localise.Cldr.Territory.parent(Cldr.get_locale())
{:error, {Cldr.UnknownChildrenError, "The territory :\"001\" has no parent(s)"}}
@spec parent!(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: [ atom() | String.t() | charlist() ]
The same as parent/2
, but raises an exception if it fails.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.parent!(:GB)
[:"154", :UN]
@spec subdivision_aliases() :: map()
Returns a map of available subdivision aliases.
Example
iex#> Bonfire.Common.Localise.Cldr.Territory.subdivision_aliases()
%{:uspr => :PR}
to_currency_code(territory_code, options \\ [as: :atom])
View Source (since 2.0.0)@spec to_currency_code(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, atom() | String.t() | charlist()} | {:error, {module(), String.t()}}
A helper method to get a territory's currency code
if a territory has multiply currencies then the oldest active currency is returned.
Returns {:ok, code}
if successful, otherwise {:error, reason}
.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_code(:US)
{:ok, :USD}
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_code("cu")
{:ok, :CUP}
to_currency_code!(territory_code, options \\ [as: :atom])
View Source (since 2.0.0)@spec to_currency_code!(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: atom() | String.t() | charlist()
The same as to_currency_code/2
, but raises an exception if it fails.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_code!(:US)
:USD
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_code!(:US, as: :charlist)
~c"USD"
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_code!("PS")
:ILS
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_code!("PS", as: :binary)
"ILS"
to_currency_codes(territory_code, options \\ [as: :atom])
View Source (since 2.0.0)@spec to_currency_codes(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, [atom() | String.t() | charlist()]} | {:error, {module(), String.t()}}
A helper method to get a territory's currency codes.
Returns {:ok, list}
if successful, otherwise {:error, reason}
.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_codes(:US)
{:ok, [:USD]}
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_codes("ht")
{:ok, [:USD, :HTG]}
to_currency_codes!(territory_code, options \\ [as: :atom])
View Source (since 2.0.0)@spec to_currency_codes!(atom() | String.t() | Cldr.LanguageTag.t(), Keyword.t()) :: [ atom() | String.t() | charlist() ]
The same as to_currency_codes/2
, but raises an exception if it fails.
options
are:as: :atom
as: :binary
as: :charlist
Example
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_codes!(:US)
[:USD]
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_codes!(:US, as: :charlist)
[~c"USD"]
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_codes!("PS")
[:ILS, :JOD]
iex> Bonfire.Common.Localise.Cldr.Territory.to_currency_codes!("PS", as: :binary)
["ILS", "JOD"]
@spec to_unicode_flag(atom() | String.t() | Cldr.LanguageTag.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Unicode flag for the given territory code.
Returns {:ok, flag}
if successful, otherwise {:error, reason}
.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.to_unicode_flag(:US)
{:ok, "πΊπΈ"}
iex> Bonfire.Common.Localise.Cldr.Territory.to_unicode_flag(:EZ)
{:error, {Cldr.UnknownFlagError, "The territory :EZ has no flag"}}
@spec to_unicode_flag!(atom() | String.t() | Cldr.LanguageTag.t()) :: String.t()
The same as to_unicode_flag/1
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.to_unicode_flag!(:US)
"πΊπΈ"
@spec translate_language_tag(Cldr.LanguageTag.t(), Keyword.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Translate a LanguageTag.t into a localized string from one locale to another.
Returns {:ok, result}
if successful, otherwise {:error, reason}
.
options
are:locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
style
is one of those returned byBonfire.Common.Localise.Cldr.Territory.available_styles/0
. The current styles are:short
,:standard
and:variant
. The default is:standard
Example
iex> Bonfire.Common.Localise.Cldr.Territory.translate_language_tag(Cldr.get_locale())
{:ok, "world"}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_language_tag(Cldr.get_locale(), [locale: Cldr.Locale.new!("pt", TestBackend.Cldr)])
{:ok, "Mundo"}
@spec translate_language_tag!(Cldr.LanguageTag.t(), Keyword.t()) :: String.t()
The same as translate_language_tag/2
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.translate_language_tag!(Cldr.get_locale())
"world"
iex> Bonfire.Common.Localise.Cldr.Territory.translate_language_tag!(Cldr.get_locale(), [locale: Cldr.Locale.new!("pt", TestBackend.Cldr)])
"Mundo"
translate_subdivision(localized_string, from_locale, to_locale \\ Cldr.get_locale(), style \\ :standard)
View Source@spec translate_subdivision( String.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() ) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Translate a localized string from one locale to another.
Returns {:ok, result}
if successful, otherwise {:error, reason}
.
to_locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
Example
iex> Bonfire.Common.Localise.Cldr.Territory.translate_subdivision("Cumbria", "en", "pl")
{:ok, "Kumbria"}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_subdivision("Cumbria", "en", "bs")
{:error, {Cldr.UnknownSubdivisionError, "No subdivision translation for :gbcma could be found in locale :bs"}}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_subdivision("Cumbria", :zzz)
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_subdivision("Cumbria", "en", "zzz")
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
translate_subdivision!(localized_string, from_locale, to_locale \\ Cldr.get_locale(), style \\ :standard)
View Source@spec translate_subdivision!( String.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() ) :: String.t()
The same as translate_subdivision/3
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.translate_subdivision!("Cumbria", "en", "pl")
"Kumbria"
iex> Bonfire.Common.Localise.Cldr.Territory.translate_subdivision!("Kumbria", "pl", "en")
"Cumbria"
translate_territory(localized_string, from_locale, to_locale \\ Cldr.get_locale(), style \\ :standard)
View Source (since 2.0.0)@spec translate_territory( String.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() ) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Translate a localized string from one locale to another.
Returns {:ok, String.t}
if successful, otherwise {:error, reason}
.
to_locale
is any configured locale. SeeBonfire.Common.Localise.Cldr.known_locale_names/0
. The default isCldr.get_locale/0
Example
iex> Bonfire.Common.Localise.Cldr.Territory.translate_territory("Reino Unido", "pt")
{:ok, "United Kingdom"}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_territory("United Kingdom", "en", "pt")
{:ok, "Reino Unido"}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_territory("Reino Unido", :zzz)
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_territory("United Kingdom", "en", "zzz")
{:error, {Cldr.InvalidLanguageError, "The language \"zzz\" is invalid"}}
iex> Bonfire.Common.Localise.Cldr.Territory.translate_territory("Westworld", "en", "pt")
{:error, {Cldr.UnknownTerritoryError, "No territory translation for \"Westworld\" could be found in locale :en"}}
translate_territory!(localized_string, locale_from, locale_name \\ Cldr.get_locale(), style \\ :standard)
View Source (since 2.0.0)@spec translate_territory!( String.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() | String.t() | Cldr.LanguageTag.t(), atom() ) :: String.t()
The same as translate_territory/3
, but raises an exception if it fails.
Example
iex> Bonfire.Common.Localise.Cldr.Territory.translate_territory!("Reino Unido", "pt")
"United Kingdom"
iex> Bonfire.Common.Localise.Cldr.Territory.translate_territory!("United Kingdom", "en", "pt")
"Reino Unido"
#=> Bonfire.Common.Localise.Cldr.Territory.translate_territory!("Westworld", "en", "pt")
** (Cldr.UnknownTerritoryError) No territory translation for "Westworld" could be found in locale "en"