elixir-cldr / cldr

Elixir implementation of CLDR/ICU
Other
447 stars 33 forks source link

How does it work? #152

Closed benkeil closed 3 years ago

benkeil commented 3 years ago

It don't get where you have the locales from. Why there is a en-GB and no de-DE but only a de instead?

kipcole9 commented 3 years ago

As the first paragraph of the readme notes:

ex_cldr is an Elixir library for the Unicode Consortium's Common Locale Data Repository (CLDR)

All locale data comes from CLDR which is hosted in this repo.

A CLDR locale that consists only of a language is nearly always specified as "the locale for the territory that has the largest number of native speakers of that language".

Therefore, en locale is for "US English" since the US has the largest population of native English speakers. This means that en-GB is required to localise for English as spoken in the UK. As a result of this "rule", the locale pt is actually pt-BR since Brazil has more native Portuguese speakers than Portugal.

Since Germany is the largest population of native German speakers, the locale de means "German as spoken in Germany" and that de-DE is not required.

ex_cldr does a reasonable job of resolving locales from a user request. For example:

# Request locale `de-DE`.
iex> {:ok, locale} = MyApp.Cldr.validate_locale "de-DE"
{:ok, #Cldr.LanguageTag<de-DE [validated]>}

# The territory identified with that locale is `:DE`
iex> Cldr.Locale.territory_from_locale locale          
:DE

# However from a CLDR point of view, the locale in use
# is actually `de`.
iex> locale.cldr_locale_name                           
"de"

Please post questions in the Elixir Slack or Elixir Forum where more people can answer. I prefer the issue tracker be used for bug reports and enhancement requests.