What's the best way to localise login form in Ash Authentication

What’s the best approach for translating labels in default sign-in screens?

I tried the following in the AuthOverrides, but it looks like the value is set at compile time, so setting the locale has no impact:

  override Components.Password.Input do
    set :identity_input_label, gettext("Email")
    set :password_input_label, gettext("Password")
  end

I think what likely needs to happen is that we need to do this internally, using gettext ourselves. Please open an issue or a PR :slight_smile:

3 Likes

Ok - I submitted an issue.

Guess what I’ve been doing over the holiday period :laughing:

2 Likes

@mindok I couldn’t find the issue you submitted :frowning: Not sure what the status of this is?

Hi @excsm , this was the issue - it looks like it was resolved in a PR. I haven’t checked as we are still demo-ing in different languages (rather than in Prod) so we don’t need to fix up the login page just yet!

Hey @mindok

Thanks for the quick response. Seems like if you were linking to the issue but it was pruned.

In any case I was just wondering if there was something else in the works.

From the docs I already managed to get everything working (including LiveView) by doing this:

  1. Copying the gettext files to my priv dir
  2. Configuring gettext

config :sic, SicWeb.Gettext,
gettext: %{
domains: [
{“auth”, “priv/gettext/auth.pot”},
{“app”, “priv/gettext/default.pot”},
{“errors”, “priv/gettext/errors.pot”},
{“emails”, “priv/gettext/email.pot”}
]
},
locales: [“en”, “es”, “ca”, “fr”, “de”, “el”],
default_locale: “en”

  1. Hooking in a plug to set the locale in regular routes:

pipeline :browser do
plug :accepts, [“html”]
plug :fetch_session
plug SicWeb.Plugs.SetLocale
plug :fetch_live_flash
plug :put_root_layout, html: {SicWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :load_from_session
end

  1. And in the ash authentication routes:
sign_in_route register_path: "/register",
              reset_path: "/reset",
              auth_routes_prefix: "/auth",
              on_mount: [
                {SicWeb.LiveUserAuth, :live_no_user},
                {SicWeb.LiveHelpers, :set_locale}  #<==========
              ],
              overrides: [SicWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.DaisyUI],
              gettext_backend: {SicWeb.Gettext, "auth"}  #<==========

The plug just extracts the locale from the Accept-Language header.

Hope this helps someone else

Consider integrating Routex as a first party citizen as well. Most frameworks except Nuxt and their great official Nuxt i18n plugin don’t work great with something like /about /es/sobre-nosotros type of situations. Even Laravel doesn’t do that and good luck integrating Mcamara Localization Routes package with Inertia.