Locales configuration in Cldr

As a followup from How does it work? · Issue #152 · elixir-cldr/cldr · GitHub

The repo has files like de_DE, de_IT, de_AT. Why these are not valid during configuration? If the goal of all that sub packages is, to save space, then it should also be possible to just download e.g. de_AT.

defmodule WidgetWeb.Cldr do
  use Cldr,
      default_locale: "en-GB",
      locales: ["en-GB", "de-DE", "th"],
      add_fallback_locales: false,
      otp_app: :widget_web,
      providers: [Cldr.Number, Cldr.Message],
      precompile_number_formats: ["¤¤#,##0.##"],
      precompile_transliterations: [{:latn, :arab}, {:thai, :latn}],
      generate_docs: true,
      force_locale_download: false
end
== Compilation error in file lib/widget_web/services/cldr.ex ==
** (Cldr.UnknownLocaleError) Failed to install the locale named "de_DE". The locale name is not known.
    (ex_cldr 2.23.0) lib/cldr/install.ex:84: Cldr.Install.do_install_locale_name/3
    (elixir 1.12.2) lib/enum.ex:930: Enum."-each/2-lists^foreach/1-0-"/2
    (ex_cldr 2.23.0) lib/cldr/install.ex:28: Cldr.Install.install_known_locale_names/1
    (ex_cldr 2.23.0) lib/cldr.ex:81: Cldr.install_locales/1
    (ex_cldr 2.23.0) expanding macro: Cldr.Backend.Compiler.__before_compile__/1
    lib/widget_web/services/cldr.ex:1: WidgetWeb.Cldr (module)
    (elixir 1.12.2) lib/kernel/parallel_compiler.ex:319: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

As the message says:

== Compilation error in file lib/widget_web/services/cldr.ex ==
** (Cldr.UnknownLocaleError) Failed to install the locale named “de_DE”. The locale name is not known.
(ex_cldr 2.23.0) lib/cldr/install.ex:84: Cldr.Install.do_install_locale_name/3

There is no CLDR locale “de-DE” so an exception is raised during compilation. Replace “de-DE” with “de” and you should be good to go. In fact a backend configuration can be reduced to the following given the various defaults:

defmodule WidgetWeb.Cldr do
  use Cldr,
      default_locale: "en-GB",
      locales: ["en-GB", "de-DE", "th"],
      otp_app: :widget_web,
      providers: [Cldr.Number, Cldr.Message],

      # These two only required if you need them
      # In most cases you probably don't
      precompile_number_formats: ["¤¤#,##0.##"],
      precompile_transliterations: [{:latn, :arab}, {:thai, :latn}],
end

I still don’t get it, in this repo: cldr/common/main at master · unicode-org/cldr · GitHub is a file de_DE, which is a CLDR locale, or not?

The locales available to ex_cldr are those in the available_locales.json file in the ex_cldr repository. Or you can see the local files in json format in the priv/cldr/locales directory.

You can also see the available locales as follows:

iex> Cldr.Config.all_locale_names()
["af", "af-NA", "agq", "ak", "am", "ar", "ar-AE", "ar-BH", "ar-DJ", "ar-DZ",
 "ar-EG", "ar-EH", "ar-ER", "ar-IL", "ar-IQ", "ar-JO", "ar-KM", "ar-KW",
 "ar-LB", "ar-LY", "ar-MA", "ar-MR", "ar-OM", "ar-PS", "ar-QA", "ar-SA",
 "ar-SD", "ar-SO", "ar-SS", "ar-SY", "ar-TD", "ar-TN", "ar-YE", "as", "asa",
 "ast", "az", "az-Cyrl", "az-Latn", "bas", "be", "be-tarask", "bem", "bez",
 "bg", "bm", "bn", "bn-IN", "bo", "bo-IN", ...]

If you look inside the CLDR repo in common/main/de_DE.xml file you’ll see it actually has no locale content and therefore not an available locale. As noted in the issue you raised, the locale de is already “German as spoke in Germany” and therefore de-DE isn’t populated. The same is true for en-US - in CLDR its an empty locale file because en is already “English as spoken in the US”.

Jesus, now I got you. But I still belief it would be nice to allow de-DE. I guess a lot of people fall about this and the locale for Germany is will de-DE. It clearer.
Like cldr/de_DE.xml at master · unicode-org/cldr · GitHub is an alias to cldr/de.xml at master · unicode-org/cldr · GitHub it should be allowed in the code to use it.

A user can still specify de-DE if they want, ex_cldr will resolve to the nearest available locale which will be de if it is configured.

The thing is nobody understand that you should use de for de-DE but de-AT for Austrian.

You can also use de-DE from a user experience point of view. It is only configuration of a backend that has this consideration.

1 Like