I’m trying to setup Cldr for a project, and I want to set Cldr locales as the locales we have for Gettext. So I am doing this
defmodule MyApp.Cldr do
use Cldr,
default_locale: "en",
locales: Gettext.known_locales(MyApp.Gettext) ,
gettext: MyApp.Gettext,
end
but then Cldr complains with
note: The locale "pt_BR" is configured in the MyApp.Gettext gettext backend but is unknown to CLDR. It will not be used to configure CLDR but it will still be used to match CLDR locales to Gettext locales at runtime.
== Compilation error in file lib/my_app/cldr.ex ==
** (Cldr.UnknownLocaleError) Failed to install the locale named :pt_BR. The locale name is not known.
(ex_cldr 2.40.1) lib/cldr/install.ex:93: Cldr.Install.do_install_locale_name/3
(elixir 1.17.2) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
(ex_cldr 2.40.1) lib/cldr/install.ex:29: Cldr.Install.install_known_locale_names/1
(ex_cldr 2.40.1) lib/cldr.ex:102: Cldr.install_locales/1
(ex_cldr 2.40.1) expanding macro: Cldr.Backend.Compiler.__before_compile__/1
lib/my_app/cldr.ex:1: MyApp.Cldr (module)
So it just raises because of pt_BR
, which is not an available locale in Cldr as far as I understand, also this answer helped understand it better. Also these are the available locales in ex_cldr
.
However, this is handled in code when you want to validate the locale pt-BR
or pt_BR
.
iex(9)> MyApp.Cldr.validate_locale "pt_BR"
{:ok, MyApp.Cldr.Locale.new!("pt-BR")}
- Should this also be handled by
ex_cldr
when downloading locales? - So in this case, should I just be doing something like
defmodule MyApp.Cldr do
use Cldr,
default_locale: "en",
# Though I think this wouldn't work if I didn't have both `pt.po` and `pt_BR.po`
# i.e. `pt` wouldn't be in known locales
locales: Gettext.known_locales(MyApp.Gettext) -- ["pt_BR"] ,
gettext: MyApp.Gettext,
end
- or is there a better way to handle this? Well, another way is to basically just rename the translation file I guess.
Edit: Seems like you don’t even need to mention locales
when you pass gettext
backend. (source)
:gettext
: specifies the name of a Gettext module that informsex_cldr
to use that module as an additional source of locales you want to configure.