add translation
This commit is contained in:
parent
527657d37b
commit
4ba03821a2
9 changed files with 426 additions and 121 deletions
|
|
@ -29,13 +29,13 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
{:error, _} ->
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Session expired. Please try again."))
|
||||
|> put_flash(:error, dgettext("auth", "Session expired. Please try again."))
|
||||
|> redirect(to: ~p"/sign-in")}
|
||||
end
|
||||
else
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, gettext("Invalid session. Please try again."))
|
||||
|> put_flash(:error, dgettext("auth", "Invalid session. Please try again."))
|
||||
|> redirect(to: ~p"/sign-in")}
|
||||
end
|
||||
end
|
||||
|
|
@ -60,7 +60,7 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
# Password incorrect
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:error, gettext("Incorrect password. Please try again."))
|
||||
|> assign(:error, dgettext("auth", "Incorrect password. Please try again."))
|
||||
|> assign(:form, to_form(%{"password" => ""}))}
|
||||
end
|
||||
end
|
||||
|
|
@ -103,7 +103,8 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
socket
|
||||
|> put_flash(
|
||||
:info,
|
||||
gettext(
|
||||
dgettext(
|
||||
"auth",
|
||||
"Your OIDC account has been successfully linked! Redirecting to complete sign-in..."
|
||||
)
|
||||
)
|
||||
|
|
@ -112,7 +113,10 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
{:error, error} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:error, gettext("Failed to link account: %{error}", error: inspect(error)))
|
||||
|> assign(
|
||||
:error,
|
||||
dgettext("auth", "Failed to link account: %{error}", error: inspect(error))
|
||||
)
|
||||
|> assign(:form, to_form(%{"password" => ""}))}
|
||||
end
|
||||
end
|
||||
|
|
@ -121,10 +125,26 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
def render(assigns) do
|
||||
~H"""
|
||||
<div class="mx-auto max-w-sm mt-16">
|
||||
<%!-- Language Selector --%>
|
||||
<div class="flex justify-center mb-4">
|
||||
<form method="post" action="/set_locale" class="text-sm">
|
||||
<input type="hidden" name="_csrf_token" value={Plug.CSRFProtection.get_csrf_token()} />
|
||||
<select
|
||||
name="locale"
|
||||
onchange="this.form.submit()"
|
||||
class="select select-sm select-bordered"
|
||||
>
|
||||
<option value="de" selected={Gettext.get_locale() == "de"}>🇩🇪 Deutsch</option>
|
||||
<option value="en" selected={Gettext.get_locale() == "en"}>🇬🇧 English</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<.header class="text-center">
|
||||
{gettext("Link OIDC Account")}
|
||||
{dgettext("auth", "Link OIDC Account")}
|
||||
<:subtitle>
|
||||
{gettext(
|
||||
{dgettext(
|
||||
"auth",
|
||||
"An account with email %{email} already exists. Please enter your password to link your OIDC account.",
|
||||
email: @user.email
|
||||
)}
|
||||
|
|
@ -134,7 +154,12 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
<.form for={@form} id="link-oidc-form" phx-submit="submit" phx-change="validate" class="mt-8">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<.input field={@form[:password]} type="password" label={gettext("Password")} required />
|
||||
<.input
|
||||
field={@form[:password]}
|
||||
type="password"
|
||||
label={dgettext("auth", "Password")}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<%= if @error do %>
|
||||
|
|
@ -144,8 +169,8 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
<% end %>
|
||||
|
||||
<div>
|
||||
<.button phx-disable-with={gettext("Linking...")} class="w-full">
|
||||
{gettext("Link Account")}
|
||||
<.button phx-disable-with={dgettext("auth", "Linking...")} class="w-full">
|
||||
{dgettext("auth", "Link Account")}
|
||||
</.button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -153,7 +178,7 @@ defmodule MvWeb.LinkOidcAccountLive do
|
|||
|
||||
<div class="mt-4 text-center text-sm">
|
||||
<.link navigate={~p"/sign-in"} class="text-brand hover:underline">
|
||||
{gettext("Cancel")}
|
||||
{dgettext("auth", "Cancel")}
|
||||
</.link>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ defmodule MvWeb.LocaleController do
|
|||
def set_locale(conn, %{"locale" => locale}) do
|
||||
conn
|
||||
|> put_session(:locale, locale)
|
||||
# Store locale in a cookie that persists beyond the session
|
||||
|> put_resp_cookie("locale", locale, max_age: 365 * 24 * 60 * 60, same_site: "Lax")
|
||||
|> redirect(to: get_referer(conn) || "/")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ defmodule MvWeb.Router do
|
|||
defp set_locale(conn, _opts) do
|
||||
locale =
|
||||
get_session(conn, :locale) ||
|
||||
get_locale_from_cookie(conn) ||
|
||||
extract_locale_from_headers(conn.req_headers)
|
||||
|
||||
Gettext.put_locale(MvWeb.Gettext, locale)
|
||||
|
|
@ -153,6 +154,13 @@ defmodule MvWeb.Router do
|
|||
|> assign(:locale, locale)
|
||||
end
|
||||
|
||||
defp get_locale_from_cookie(conn) do
|
||||
case conn.req_cookies do
|
||||
%{"locale" => locale} when locale in ["en", "de"] -> locale
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
# Get locale from user
|
||||
defp extract_locale_from_headers(headers) do
|
||||
headers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue