Cldr v0.10.0 Cldr View Source

Cldr provides the core functions to retrieve and manage the CLDR data that supports formatting and localisation.

Cldr functionality is packaged into a several packages that each depend on this one. These additional modules provide:

  • Cldr.Number.to_string/2 for formatting numbers and Cldr.Currency.to_string/2 for formatting currencies. These functions are contained in the hex package ex_cldr_numbers.

  • Cldr.List.to_string/2 for formatting lists. These function is contained in the hex package ex_cldr_lists.

  • Cldr.Unit.to_string/2 for formatting SI units. These function is contained in the hex package ex_cldr_units.

  • Cldr.DateTime.to_string/2 for formatting of dates, times and datetimes. This function is contained in the hex package ex_cldr_dates_times.

Link to this section Summary

Functions

Returns a list of all the locale names defined in the CLDR repository

Returns a boolean indicating if the specified locale is available in CLDR

Returns the directory path name where the CLDR json data is kept

Returns the default locale

Returns the default region when a locale does not specify one and none can be inferred

Return the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied

Returns a list of strings representing the calendars known to Cldr

Returns a list of strings representing the currencies known to Cldr

Returns either the locale_name or false based upon whether the locale name is configured in Cldr

Returns a boolean indicating if the specified locale name is configured and available in Cldr

Returns a list of the known locale names

Returns a list of strings representing the number systems known to Cldr

Returns either the locale name or nil based upon whether the locale name is configured in Cldr

Returns a boolean indicating if the specified locale name is configured and available in Cldr and supports rules based number formats (RBNF)

Returns a list of locale names which have rules based number formats (RBNF)

Returns a list of the territories known to Cldr

Returns a list of all requested locale names

Set the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied

Returns a list of the locales names that are configured, but not known in CLDR

Returns an {:ok, locale} or {:error, {exception, message}} tuple depending on whether the locale is valid and known in the current configuration

Normalise and validate a territory code

Returns the version of the CLDR repository as a tuple

Link to this section Functions

Link to this function all_locales() View Source
all_locales() :: [Cldr.Locale.name(), ...]

Returns a list of all the locale names defined in the CLDR repository.

Note that not necessarily all of these locales are available since functions are only generated for configured locales which is most cases will be a subset of locales defined in CLDR.

See also: requested_locales/0 and known_locales/0

Link to this function available_locale?(locale) View Source
available_locale?(Cldr.Locale.name() | Cldr.LanguageTag.t()) :: boolean()

Returns a boolean indicating if the specified locale is available in CLDR.

The return value depends on whether the locale is defined in the CLDR repository. It does not necessarily mean the locale is configured for Cldr. See also Cldr.known_locale?/1.

Examples

iex> Cldr.available_locale? "en-AU"
true

iex> Cldr.available_locale? "en-SA"
false

Returns the directory path name where the CLDR json data is kept.

Link to this function default_locale() View Source
default_locale() :: Cldr.LanguageTag.t()

Returns the default locale.

Example

iex> Cldr.default_locale()
%Cldr.LanguageTag{canonical_locale_name: "en-Latn-001",
  cldr_locale_name: "en-001", extensions: %{}, language: "en",
  locale: %{}, private_use: [], rbnf_locale_name: "en", region: "001",
  requested_locale_name: "en-001", script: "Latn", transform: %{},
  variant: nil}
Link to this function default_region() View Source
default_region() :: String.t()

Returns the default region when a locale does not specify one and none can be inferred.

Example

iex> Cldr.default_region()
"001"
Link to this function get_current_locale() View Source
get_current_locale() :: Cldr.LanguageTag.t()

Return the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied.

Example

iex> Cldr.set_current_locale("pl")
iex> Cldr.get_current_locale
%Cldr.LanguageTag{
   canonical_locale_name: "pl-Latn-PL",
   cldr_locale_name: "pl",
   extensions: %{},
   language: "pl",
   locale: %{},
   private_use: [],
   rbnf_locale_name: "pl",
   region: "PL",
   requested_locale_name: "pl",
   script: "Latn",
   transform: %{},
   variant: nil
 }
Link to this function known_calendars() View Source
known_calendars() :: [String.t(), ...] | []

Returns a list of strings representing the calendars known to Cldr.

Example

iex> Cldr.known_calendars
["buddhist", "chinese", "coptic", "dangi", "ethiopic", "ethiopic_amete_alem",
 "gregorian", "hebrew", "indian", "islamic", "islamic_civil", "islamic_rgsa",
 "islamic_tbla", "islamic_umalqura", "japanese", "persian", "roc"]
Link to this function known_currencies() View Source
known_currencies() :: [String.t(), ...] | []

Returns a list of strings representing the currencies known to Cldr.

Example

iex> Cldr.known_currencies
["ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON",
 "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "AWG", "AZM", "AZN",
 "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN",
 "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC",
 "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYN",
 "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNH",
 "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP",
 "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP",
 "ERN", "ESA", "ESB", "ESP", "ETB", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP",
 "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ",
 "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP",
 "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD",
 "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD",
 "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LTT", "LUC", "LUF", "LUL",
 "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD",
 "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR",
 "MWK", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC",
 "NIO", "NLG", "NOK", "NPR", "NZD", "OMR", "PAB", "PEI", "PEN", "PES", "PGK",
 "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD",
 "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD",
 "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "STN", "SUR",
 "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE",
 "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN",
 "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST",
 "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO",
 "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD",
 "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ",
 "ZWD", "ZWL", "ZWR"]
Link to this function known_locale(locale_name) View Source
known_locale(Cldr.Locale.name()) :: String.t() | false

Returns either the locale_name or false based upon whether the locale name is configured in Cldr.

Examples

iex> Cldr.known_locale "en-AU"
"en-AU"

iex> Cldr.known_locale "en-SA"
false
Link to this function known_locale?(locale_name) View Source
known_locale?(Cldr.Locale.name()) :: boolean()

Returns a boolean indicating if the specified locale name is configured and available in Cldr.

Examples

iex> Cldr.known_locale?("en")
true

iex> Cldr.known_locale?("!!")
false
Link to this function known_locales() View Source
known_locales() :: [Cldr.Locale.name(), ...] | []

Returns a list of the known locale names.

Known locales are those locales which are the subset of all CLDR locales that have been configured for use either directly in the config.exs file or in Gettext.

Link to this function known_number_systems() View Source
known_number_systems() :: [String.t(), ...] | []

Returns a list of strings representing the number systems known to Cldr.

Example

iex> Cldr.known_number_systems
["adlm", "ahom", "arab", "arabext", "armn", "armnlow", "bali", "beng", "bhks",
 "brah", "cakm", "cham", "cyrl", "deva", "ethi", "fullwide", "geor", "gonm",
 "grek", "greklow", "gujr", "guru", "hanidays", "hanidec", "hans", "hansfin",
 "hant", "hantfin", "hebr", "hmng", "java", "jpan", "jpanfin", "kali", "khmr",
 "knda", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold",
 "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo",
 "mtei", "mymr", "mymrshan", "mymrtlng", "newa", "nkoo", "olck", "orya", "osma",
 "roman", "romanlow", "saur", "shrd", "sind", "sinh", "sora", "sund", "takr",
 "talu", "taml", "tamldec", "telu", "thai", "tibt", "tirh", "vaii", "wara"]
Link to this function known_rbnf_locale(locale_name) View Source
known_rbnf_locale(Cldr.Locale.name()) :: String.t() | false

Returns either the locale name or nil based upon whether the locale name is configured in Cldr.

Examples

iex> Cldr.known_locale "en-AU"
"en-AU"

iex> Cldr.known_locale "en-SA"
false
Link to this function known_rbnf_locale?(locale_name) View Source
known_rbnf_locale?(Cldr.Locale.name()) :: boolean()

Returns a boolean indicating if the specified locale name is configured and available in Cldr and supports rules based number formats (RBNF).

Examples

iex> Cldr.known_rbnf_locale?("en")
true

iex> Cldr.known_rbnf_locale?("!!")
false
Link to this function known_rbnf_locales() View Source
known_rbnf_locales() :: [Cldr.Locale.name(), ...] | []

Returns a list of locale names which have rules based number formats (RBNF).

Link to this function known_territories() View Source
known_territories() :: [Atom.t(), ...]

Returns a list of the territories known to Cldr.

Example

iex> Cldr.known_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, :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, :CP, :CR, :CU, :CV, :CW, :CX, :CY, :CZ, :DE, :DG, :DJ, :DK,
 :DM, :DO, :DZ, :EA, :EC, :EE, :EG, :EH, :ER, :ES, :ET, :EU, :EZ, :FI, :FJ, :FK,
 :FM, :FO, :FR, :GA, :GB, :GD, :GE, :GF, :GG, :GH, :GI, :GL, :GM, :GN, :GP, :GQ,
 :GR, :GS, :GT, :GU, :GW, :GY, :HK, :HM, :HN, :HR, :HT, :HU, :IC, :ID, :IE, :IL,
 :IM, :IN, :IO, :IQ, :IR, :IS, :IT, :JE, :JM, :JO, :JP, :KE, :KG, :KH, :KI, :KM,
 :KN, :KP, :KR, :KW, :KY, :KZ, :LA, :LB, :LC, :LI, :LK, :LR, :LS, :LT, :LU, :LV,
 :LY, :MA, :MC, :MD, :ME, :MF, :MG, :MH, :MK, :ML, :MM, :MN, :MO, :MP, :MQ, :MR,
 :MS, :MT, :MU, :MV, :MW, :MX, :MY, :MZ, :NA, :NC, :NE, :NF, :NG, :NI, :NL, :NO,
 :NP, :NR, :NU, :NZ, :OM, :PA, :PE, :PF, :PG, :PH, :PK, :PL, :PM, :PN, :PR, :PS,
 :PT, :PW, :PY, :QA, :QO, :RE, :RO, :RS, :RU, :RW, :SA, :SB, :SC, :SD, :SE, :SG,
 :SH, :SI, :SJ, :SK, :SL, :SM, :SN, :SO, :SR, :SS, :ST, :SV, :SX, :SY, :SZ, :TA,
 :TC, :TD, :TF, :TG, :TH, :TJ, :TK, :TL, :TM, :TN, :TO, :TR, :TT, :TV, :TW, :TZ,
 :UA, :UG, :UM, :UN, :US, :UY, :UZ, :VA, :VC, :VE, :VG, :VI, :VN, :VU, :WF, :WS,
 :XK, :YE, :YT, :ZA, :ZM, :ZW]
Link to this function requested_locales() View Source
requested_locales() :: [Cldr.Locale.name(), ...] | []

Returns a list of all requested locale names.

The list is the combination of configured locales, Gettext locales and the default locale.

See also known_locales/0 and all_locales/0

Link to this function set_current_locale(locale) View Source
set_current_locale(String.t() | Cldr.LanguageTag.t()) :: Cldr.LanguageTag.t()

Set the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied.

See rfc5646 for the specification of a language tag and consult ./priv/cldr/rfc5646.abnf for the specification as implemented that includes the CLDR extensions for “u” (locales) and “t” (transforms).

Examples

iex> Cldr.set_current_locale("en")
{
  :ok,
  %Cldr.LanguageTag{
    canonical_locale_name: "en-Latn-US",
    cldr_locale_name: "en",
    extensions: %{},
    language: "en",
    locale: %{},
    private_use: [],
    rbnf_locale_name: "en",
    region: "US",
    requested_locale_name: "en",
    script: "Latn",
    transform: %{},
    variant: nil
  }
}

iex> Cldr.set_current_locale("zzz")
{:error, {Cldr.UnknownLocaleError, "The locale \"zzz\" is not known."}}
Link to this function unknown_locales() View Source
unknown_locales() :: [Cldr.Locale.name(), ...] | []

Returns a list of the locales names that are configured, but not known in CLDR.

Since there is a compile-time exception raise if there are any unknown locales this function should always return an empty list.

Link to this function validate_locale(locale_name) View Source
validate_locale(Cldr.Locale.name() | Cldr.LanguageTag.t()) ::
  {:ok, String.t()} |
  {:error, {Exception.t(), String.t()}}

Returns an {:ok, locale} or {:error, {exception, message}} tuple depending on whether the locale is valid and known in the current configuration.

Examples

iex> Cldr.validate_locale "en"
{:ok,
 %Cldr.LanguageTag{canonical_locale_name: "en-Latn-US", cldr_locale_name: "en",
  extensions: %{}, language: "en", locale: %{}, private_use: [],
  rbnf_locale_name: "en", region: "US", requested_locale_name: "en",
  script: "Latn", transform: %{}, variant: nil}}

iex> Cldr.validate_locale Cldr.default_locale
{:ok,
 %Cldr.LanguageTag{canonical_locale_name: "en-Latn-001",
  cldr_locale_name: "en-001", extensions: %{}, language: "en", locale: %{},
  private_use: [], rbnf_locale_name: "en", region: "001",
  requested_locale_name: "en-001", script: "Latn", transform: %{},
  variant: nil}}

iex> Cldr.validate_locale "zzz"
{:error, {Cldr.UnknownLocaleError, "The locale \"zzz\" is not known."}}
Link to this function validate_territory(territory) View Source
validate_territory(Atom.t() | String.t()) ::
  {:ok, Atom.t()} |
  {:error, {Exception.t(), String.t()}}

Normalise and validate a territory code.

  • territory is either a string, atom or %LanguageTag{} representing a territory code

Returns:

  • {:ok, normalized_territory_code} or
  • {:error, {exception, message}}

Examples

iex> Cldr.validate_territory "en"
{:error, {Cldr.UnknownTerritoryError, "The territory \"en\" is unknown"}}

iex> Cldr.validate_territory "gb"
{:ok, :GB}

iex> Cldr.validate_territory "001"
{:ok, :"001"}

iex> Cldr.validate_territory Cldr.Locale.new("en")
{:ok, :US}

iex> Cldr.validate_territory %{}
{:error, {Cldr.UnknownTerritoryError, "The territory %{} is invalid"}}
Link to this function version() View Source
version() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}

Returns the version of the CLDR repository as a tuple

Example

iex> Cldr.version
{32, 0, 0}