Cldr v1.5.1 Cldr.Config View Source

Provides the functions to manage the Cldr configuration.

Locales are configured for use in Cldr by either specifying them directly or by using a configured Gettext module.

Locales are configured in config.exs (or any included config). For example the following will configure English and French as the available locales. Note that only locales that are contained within the CLDR repository will be available for use. There are currently 516 locales defined in CLDR version 31.0.0.

config :ex_cldr,
  locales: ["en", "fr"]

Working with Gettext

It’s also possible to use the locales from a Gettext configuration:

config :ex_cldr,
  locales: ["en", "fr"]
  gettext: App.Gettext

In which case the combination of locales “en”, “fr” and whatever is configured for App.Gettext will be generated.

Locale wildcards

Locales can also be configured by using a regex which is most useful when dealing with locales that have many regional variants like English (over 100!) and French. For example:

config :ex_cldr,
  locales: ["fr-*", "en-[A-Z]+"]

will configure all French locales and all English locales that have alphabetic regional variants. The expansion is made using Regex.match? so any valid regex can be used.

Configuring all locales

As a special case, all locales in CLDR can be configured by using the keyword :all. For example:

config :ex_cldr,
  locales: :all

Configuring all locales is not recommended*. Doing so imposes a significant compilation load as many functions are created at compmile time for each locale.

The Cldr test configuration does configure all locales in order to ensure good test coverage. This is done at the expense of significant compile time.

Precompiling configured number formats

If your application heavily relies on one or more particular user-defined number formats then there is a performance benefit to having them precompiled when your app is compiled (up to double the performance).

To define the formats to be precompiled specify them in your config file with the key compile_number_formats.

For example:

config :ex_cldr,
  compile_number_formats: ["¤¤#,##0.##"]

Storage location for the locale definiton files

Locale files are downloaded and installed at compile time based upon the configuration. These files are only used at compile time, they contain the json representation of the locale data.

By default the locale files are stored in ./priv/cldr/locales.

The locale of the locales can be changed in the configuration with the :data_dir key. For example:

config :ex_cldr,
  locales: ["en", "fr"]
  data_dir: "/apps/data/cldr"

The directory will be created if it does not exist and an exception will be raised if the directory cannot be created.

Link to this section Summary

Functions

Returns the map of aliases for languages, scripts and regions

Returns the map of language tags for all available locales

Returns a list of all locales in the CLDR repository

Return the configured json lib

Returns the data that defines start and end of calendar epochs

Returns the calendars available for a given locale name

Returns the path of the CLDR data directory for the ex_cldr app

Return the root path of the cldr application

Return the path name of the CLDR data directory for a client application

Returns the directory where the CLDR locales files are located

Returns a list of all locales configured in the config.exs file

Returns the data that defines time periods of a day for a language

Return the default locale

Returns the directory where the downloaded CLDR repository files are stored

Expands wildcards in locale names

Read the locale json, decode it and make any necessary transformations

Get the configured number formats that should be precompiled at application compilation time

Return the configured Gettext module name or nil

Returns true if a Gettext module is configured in Cldr and the Gettext module is available

Return a list of the locales defined in Gettext

Returns a list of strings representing the calendars known to Cldr

Returns a list of the currencies known in Cldr in upcased atom format

Returns a list of all locales that are configured and available in the CLDR repository

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

Returns a list of atoms representing the territories known to Cldr

Return the saved language tag for the given locale name

Returns the likely subtags map which maps a locale string to %LaguageTag{} representing the likely subtags for that locale string

Returns the filename that contains the json representation of a locale

Transforms a locale name from the Posix format to the Cldr format

Transforms a locale name from the CLDR format to the Posix format

Returns the location of the json data for a locale or nil if the locale can’t be found

Returns a list of all configured locales

Identifies the top level keys in the consolidated locale file

Return the directory where Cldr stores its source core data, This directory should not be expected to be available other than when developing Cldr since it points to a source directory

Returns a map of territory containments

Returns a map of territory info for all territories known to CLDR

Get territory info for a specific territory

Returns a list of all locales that are configured but not available in the CLDR repository

Returns the version string of the CLDR data repository

Returns the data that defines start and end of calendar weeks, weekends and years

Link to this section Types

Link to this section Functions

Returns the map of aliases for languages, scripts and regions

Returns the map of language tags for all available locales

Link to this function all_locale_names() View Source
all_locale_names() :: [Cldr.Locale.locale_name(), ...]

Returns a list of all locales in the CLDR repository.

Returns a list of the complete locales list in CLDR, irrespective of whether they are configured for use in the application.

Any configured locales that are not present in this list will raise an exception at compile time.

Return the configured json lib

Returns the data that defines start and end of calendar epochs.

Example

iex> Cldr.Config.calendar_info |> Map.get(:gregorian)
%{calendar_system: "solar", eras: %{0 => %{end: 0}, 1 => %{start: 1}}}
Link to this function calendars_for_locale(locale_name) View Source

Returns the calendars available for a given locale name

Example

iex> Cldr.Config.calendars_for_locale "en"
[:buddhist, :chinese, :coptic, :dangi, :ethiopic, :ethiopic_amete_alem,
 :generic, :gregorian, :hebrew, :indian, :islamic, :islamic_civil,
 :islamic_rgsa, :islamic_tbla, :islamic_umalqura, :japanese, :persian, :roc]

Returns the path of the CLDR data directory for the ex_cldr app

Return the root path of the cldr application

Return the path name of the CLDR data directory for a client application.

Returns the directory where the CLDR locales files are located.

Link to this function configured_locale_names() View Source
configured_locale_names() :: [Cldr.Locale.locale_name()]

Returns a list of all locales configured in the config.exs file.

In order of priority return either:

  • The list of locales configured configured in mix.exs if any

  • The default locale

If the configured locales is :all then all locales in CLDR are configured.

The locale “root” is always added to the list of configured locales since it is required to support some RBNF functions.

The use of :all is not recommended since all 523 locales take quite some time (minutes) to compile. It is however helpful for testing Cldr.

Returns the data that defines time periods of a day for a language.

Time period rules are used to define the meaning of “morning”, “evening”, “noon”, “midnight” and potentially other periods on a per-language basis.

Example

iex> Cldr.Config.day_period_info |> Map.get("fr")
%{"afternoon1" => %{"before" => [18, 0], "from" => [12, 0]},
  "evening1" => %{"before" => [24, 0], "from" => [18, 0]},
  "midnight" => %{"at" => [0, 0]},
  "morning1" => %{"before" => [12, 0], "from" => [4, 0]},
  "night1" => %{"before" => [4, 0], "from" => [0, 0]},
  "noon" => %{"at" => [12, 0]}}
Link to this function decimal_formats_for(locale) View Source

Return the default locale.

In order of priority return either:

  • The default locale specified in the mix.exs file
  • The Gettext.get_locale/1 for the current configuration
  • “en”

Returns the directory where the downloaded CLDR repository files are stored.

Link to this function expand_locale_names(locale_names) View Source
expand_locale_names([Cldr.Locale.locale_name(), ...]) :: [
  Cldr.Locale.locale_name(),
  ...
]

Expands wildcards in locale names.

Locales often have region variants (for example en-AU is one of 104 variants in CLDR). To make it easier to configure a language and all its variants, a locale can be specified as a regex which will then do a match against all CLDR locales.

For locale names that have a Script or Vairant component the base language is also configured since plural rules will fall back to the language for these locale names.

Examples

iex> Cldr.Config.expand_locale_names(["en-A+"])
["en", "en-AG", "en-AI", "en-AS", "en-AT", "en-AU"]

iex> Cldr.Config.expand_locale_names(["fr-*"])
["fr", "fr-BE", "fr-BF", "fr-BI", "fr-BJ", "fr-BL", "fr-CA", "fr-CD", "fr-CF",
 "fr-CG", "fr-CH", "fr-CI", "fr-CM", "fr-DJ", "fr-DZ", "fr-GA", "fr-GF",
 "fr-GN", "fr-GP", "fr-GQ", "fr-HT", "fr-KM", "fr-LU", "fr-MA", "fr-MC",
 "fr-MF", "fr-MG", "fr-ML", "fr-MQ", "fr-MR", "fr-MU", "fr-NC", "fr-NE",
 "fr-PF", "fr-PM", "fr-RE", "fr-RW", "fr-SC", "fr-SN", "fr-SY", "fr-TD",
 "fr-TG", "fr-TN", "fr-VU", "fr-WF", "fr-YT"]

Read the locale json, decode it and make any necessary transformations.

This is the only place that we read the locale and we only read it once. All other uses of locale data are references to this data.

Additionally the intention is that this is read only at compile time and used to construct accessor functions in other modules so that during production run there is no file access or decoding.

Link to this function get_precompile_number_formats() View Source

Get the configured number formats that should be precompiled at application compilation time.

Example

iex> Cldr.Config.get_precompile_number_formats
[]

Return the configured Gettext module name or nil.

Link to this function gettext_configured?() View Source
gettext_configured?() :: boolean()

Returns true if a Gettext module is configured in Cldr and the Gettext module is available.

Example

iex> Cldr.Config.gettext_configured?
true
Link to this function gettext_locales() View Source
gettext_locales() :: [Cldr.Locale.locale_name()]

Return a list of the locales defined in Gettext.

Return a list of locales configured in Gettext or [] if Gettext is not configured.

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

Example

iex> Cldr.Config.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]

Returns a list of the currencies known in Cldr in upcased atom format.

Example

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

Returns a list of all locales that are configured and available in the CLDR repository.

Link to this function known_number_system_types() View Source

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

Example

iex> Cldr.Config.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_name(locale_name) View Source
Link to this function known_rbnf_locale_names() View Source

Returns a list of atoms representing the territories known to Cldr.

Example

iex> Cldr.Config.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 language_tag(locale_name) View Source

Return the saved language tag for the given locale name

Returns the likely subtags map which maps a locale string to %LaguageTag{} representing the likely subtags for that locale string

Returns the filename that contains the json representation of a locale

Link to this function locale_name_from_posix(name) View Source

Transforms a locale name from the Posix format to the Cldr format

Link to this function locale_name_to_posix(name) View Source

Transforms a locale name from the CLDR format to the Posix format

Link to this function locale_path(locale) View Source
locale_path(String.t()) :: {:ok, String.t()} | {:error, :not_found}

Returns the location of the json data for a locale or nil if the locale can’t be found.

  • locale is any locale returned from Cldr.known_locale_names()
Link to this function number_systems_for(locale_name) View Source
Link to this function rbnf_rule_function(rule_name) View Source
Link to this function requested_locale_names() View Source
requested_locale_names() :: [Cldr.Locale.locale_name()]

Returns a list of all configured locales.

The list contains locales configured both in Gettext and specified in the mix.exs configuration file as well as the default locale.

Link to this function required_modules() View Source
required_modules() :: [String.t()]

Identifies the top level keys in the consolidated locale file.

These keys represent difference dimensions of content in the CLDR repository and serve three purposes:

  1. To structure the content in the locale file

  2. To provide a rudimentary way to validate that some json represents a valid locale file

  3. To all conditional inclusion of CLDR content at compile time to help manage memory footprint. This capability is not yet built into Cldr.

Return the directory where Cldr stores its source core data, This directory should not be expected to be available other than when developing Cldr since it points to a source directory.

Link to this function structure_units(content) View Source

Returns a map of territory containments

Returns a map of territory info for all territories known to CLDR.

The territory information is independent of the ex_cldr configuration.

Example

iex> Cldr.Config.territory_info[:GB]
%{
  currency: [GBP: %{from: ~D[1694-07-27]}],
  gdp: 2788000000000,
  language_population: %{
    "bn" => %{population_percent: 0.67},
    "cy" => %{
      official_status: "official_regional",
      population_percent: 0.77
    },
    "de" => %{population_percent: 6},
    "el" => %{population_percent: 0.34},
    "en" => %{official_status: "official", population_percent: 99},
    "fr" => %{population_percent: 19},
    "ga" => %{
      official_status: "official_regional",
      population_percent: 0.026
    },
    "gd" => %{
      official_status: "official_regional",
      population_percent: 0.099,
      writing_percent: 5
    },
    "it" => %{population_percent: 0.34},
    "ks" => %{population_percent: 0.19},
    "kw" => %{population_percent: 0.0031},
    "ml" => %{population_percent: 0.035},
    "pa" => %{population_percent: 0.79},
    "sco" => %{population_percent: 2.7, writing_percent: 5},
    "syl" => %{population_percent: 0.51},
    "yi" => %{population_percent: 0.049},
    "zh-Hant" => %{population_percent: 0.54}
  },
  literacy_percent: 99,
  measurement_system: "UK",
  paper_size: "A4",
  population: 64769500,
  telephone_country_code: 44,
  temperature_measurement: "metric"
}
Link to this function territory_info(territory) View Source
territory_info(String.t() | atom() | Cldr.LanguageTag.t()) ::
  %{} | {:error, {Exception.t(), String.t()}}

Get territory info for a specific territory.

  • territory is a string, atom or language_tag representation of a territory code in the list returned by Cldr.known_territories

Returns:

  • A map of the territory information or
  • {:error, reason}

Example

iex> Cldr.Config.territory_info "au"
%{
  currency: [AUD: %{from: ~D[1966-02-14]}],
  gdp: 1189000000000,
  language_population: %{
    "en" => %{
      official_status: "de_facto_official",
      population_percent: 96
    },
    "it" => %{population_percent: 1.9},
    "wbp" => %{population_percent: 0.011},
    "zh-Hant" => %{population_percent: 2.1}
  },
  literacy_percent: 99,
  measurement_system: "metric",
  paper_size: "A4",
  population: 23232400,
  telephone_country_code: 61,
  temperature_measurement: "metric"
}

iex> Cldr.Config.territory_info "abc"
{:error, {Cldr.UnknownTerritoryError, "The territory \"abc\" is unknown"}}
Link to this function unknown_locale_names() View Source
unknown_locale_names() :: [Cldr.Locale.locale_name()]

Returns a list of all locales that are configured but not available in the CLDR repository.

Returns the version string of the CLDR data repository

Returns the data that defines start and end of calendar weeks, weekends and years