Hi all,
my backend module looks like:
defmodule OHA.Cldr do
@moduledoc false
@gettext_module Application.compile_env(:oha, :gettext, OHA.Gettext)
use Cldr,
locales: ["en", "de"],
default_locale: "de",
gettext: @gettext_module,
data_dir: "./priv/cldr",
otp_app: :oha,
precompile_number_formats: ["¤¤#,##0.##"],
providers: [
Cldr.Number,
Cldr.List,
Cldr.Unit,
Cldr.Territory,
Cldr.DateTime,
Cldr.LocaleDisplay
],
generate_docs: false,
force_locale_download: false
end
then I have a Phoenix project that uses that backend. The conf where I set the gettext_module looks like this:
config :oha, gettext: ZdbWeb.Gettext
Then I have the plugs for both the conn and the session in my browser pipeline, as I use both dead and live views:
pipeline :browser do
plug(:accepts, ["html"])
plug(:fetch_session)
plug Cldr.Plug.PutLocale,
apps: [:cldr, :gettext],
from: [:query, :session, :path, :body, :cookie, :accept_language],
param: "l",
gettext: ZdbWeb.Gettext,
cldr: OHA.Cldr
plug Cldr.Plug.PutSession, as: :string
plug(:fetch_live_flash)
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
plug(:fetch_current_user)
end
Then I have a mount hook where I set the locale from what I have in the params or the session:
defmodule OHAWeb.RestoreLocale do
def on_mount(:default, %{"l" => locale}, _session, socket) do
# Gettext.put_locale(locale)
OHA.Cldr.put_locale(locale)
{:cont, socket}
end
def on_mount(:default, _params, %{"cldr_locale" => locale}, socket) do
# Gettext.put_locale(locale)
OHA.Cldr.put_locale(locale)
{:cont, socket}
end
def on_mount(:default, _params, _session, socket), do: {:cont, socket}
end
This code does not work, I have to manually call Gettect.put_locale(locale)
to make it work.
I am doing something wrong for sure, ideas?
Thank you
Cheers!