I did search on the forums here to see if there was a previous answer and didn’t come up with a clear match.
I’m working on a Phoenix app that is using gettext for text translations. I user will have a preferred language, so we’ll be serving up pages using that. However, for unauthenticated pages, we’ll need to read and respond to the Accept-Language
headers.
I’ve been evaluating using the Plug from ex_cldr_plug
and it’s remarkably robust. However it seems like the locale naming for Gettext isn’t aligned with those in CLDR.
ling 893 files (.ex)
warning: The locales ["de-DE", "en-US"] are configured in the Elixir.MyPhoenixApp.Gettext gettext backend but are unknown to CLDR. They will be ignored by CLDR.
Generating MyPhoenixApp.Cldr for 3 locales named [:de, :en, :und] with a default locale named :en
config/config.ex
# Configure for Internationalization (i18n)
config :myphxapp, MyPhoenixApp.Gettext,
default_locale: "en_US",
locales: ["en_US", "de_DE"]
config :ex_cldr,
default_locale: "en",
default_backend: MyPhoenixApp.Cldr,
json_library: Jason
lib/myphxapp/cldr.ex
defmodule MyPhoenixApp.Cldr do
use Cldr,
locales: ["en", "de"],
default_locale: "en",
add_fallback_locales: false,
gettext: MyPhoenixApp.Gettext,
data_dir: "./priv/cldr",
otp_app: :myphxapp,
precompile_number_formats: ["¤¤#,##0.##"],
precompile_transliterations: [{:latn, :arab}, {:thai, :latn}],
# we could include providers for Numbers, etc. For now: empty
providers: [],
generate_docs: true,
force_locale_download: false
end
lib/myphxapp/gettext.ex
defmodule MyPhoenixApp.Gettext do
use Gettext, otp_app: :myphxapp
end
I believe that Gettext is using POSIX locale name from what I can see in an earlier version of the ex_cldr
readme:
Since
Gettext
uses the Posix locale name format (locales with an ‘_‘ in them) andCldr
uses the Unicode format (a ‘-‘ as the subtag separator),Cldr
will transliterate locale names fromGettext
into theCldr
canonical form.
I imagine the warning is hinting at this being more than just a format definition though (so not just underscore _
vs dash -
).
I realize that de_DE
is not populated in CLDR from Kip’s response here:
Is there a way to address the warning and allow Gettext
’s locales to coexist with CLDR’s definitions?
Or, I’m not sure if the correct move to is change from en_US
& de_DE
to simply en
and de
?
I know that the application will need to support en_GB
and en_CA
soon, so that’s why I was attempting so use the format for language-code / country code.
Hopefully I’ve provided enough configuration details (and not too much).
Thanks in advance