|
|
@ -12,7 +12,6 @@ module.exports = {
|
|||
"../lib/mv_web.ex",
|
||||
"../lib/mv_web/**/*.*ex"
|
||||
],
|
||||
safelist: ['h-screen', 'px-6', 'h-screen', 'place-items-center', 'px-20', 'px-24'], // Classes that are used by AshAuthentication Sign-In Page are otherwise purged
|
||||
theme: {
|
||||
|
rafael marked this conversation as resolved
Outdated
|
||||
extend: {
|
||||
colors: {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ defmodule MvWeb.AuthOverrides do
|
|||
|
||||
# Avoid full-width for the Sign In Form
|
||||
override AshAuthentication.Phoenix.Components.SignIn do
|
||||
set :root_class, "min-w-md"
|
||||
set :root_class, "md:min-w-md"
|
||||
|
rafael marked this conversation as resolved
Outdated
rafael
commented
It seems like this makes the login form too wide on mobile screens. Maybe it should be It seems like this makes the login form too wide on mobile screens. Maybe it should be `max-w-md`?
|
||||
end
|
||||
|
||||
# Replace banner logo with text
|
||||
|
|
|
|||
|
|
@ -36,9 +36,11 @@ defmodule MvWeb.LiveUserAuth do
|
|||
end
|
||||
end
|
||||
|
||||
def on_mount(:live_no_user, _params, _session, socket) do
|
||||
Gettext.put_locale(MvWeb.Gettext, "de")
|
||||
{:cont, assign(socket, :locale, "de")}
|
||||
def on_mount(:live_no_user, _params, session, socket) do
|
||||
# Set the locale for not logged in user to set the language
|
||||
|
rafael marked this conversation as resolved
Outdated
rafael
commented
Is there a way to detect the language of the user automatically? Maybe phoenix has a feature for that. This would make sure that folks who don't speak german will get the english login page. I think it makes sense to display the login page in german as a fallback, if the browser doesn't send a preferred language. Maybe we can open an issue for that? :) Is there a way to detect the language of the user automatically? Maybe phoenix has a feature for that. This would make sure that folks who don't speak german will get the english login page. I think it makes sense to display the login page in german as a fallback, if the browser doesn't send a preferred language. Maybe we can open an issue for that? :)
carla
commented
I think adding a language switch to the login screen needs more customization than the overrides AshAuthentication provides. As I think it's not that high priority right now I added another issue, but to not spend time on it right now. Is that fine? I think adding a language switch to the login screen needs more customization than the overrides AshAuthentication provides. As I think it's not that high priority right now I added another issue, but to not spend time on it right now. Is that fine?
rafael
commented
Yes, totally fine! Yes, totally fine!
|
||||
locale = session["locale"] || "en"
|
||||
Gettext.put_locale(MvWeb.Gettext, locale)
|
||||
|
rafael marked this conversation as resolved
Outdated
rafael
commented
Do we also need to set the locale here when the router already does it? Do we also need to set the locale here when the router already does it?
carla
commented
Yes, otherwise the login scren is not translated. At least I found no other way. Yes, otherwise the login scren is not translated. At least I found no other way.
rafael
commented
Okay, could you add a comment saying that this is the reason? This will make it easier to understand if somebody stumbles upon this in the future :) Okay, could you add a comment saying that this is the reason? This will make it easier to understand if somebody stumbles upon this in the future :)
|
||||
{:cont, assign(socket, :locale, locale)}
|
||||
|
||||
if socket.assigns[:current_user] do
|
||||
{:halt, Phoenix.LiveView.redirect(socket, to: ~p"/")}
|
||||
|
|
|
|||
|
|
@ -139,8 +139,47 @@ defmodule MvWeb.Router do
|
|||
end
|
||||
|
||||
defp set_locale(conn, _opts) do
|
||||
locale = get_session(conn, :locale) || "de"
|
||||
locale =
|
||||
get_session(conn, :locale) ||
|
||||
extract_locale_from_headers(conn.req_headers)
|
||||
|
||||
Gettext.put_locale(MvWeb.Gettext, locale)
|
||||
|
||||
conn
|
||||
|> put_session(:locale, locale)
|
||||
|> assign(:locale, locale)
|
||||
end
|
||||
|
||||
# Get locale from user
|
||||
defp extract_locale_from_headers(headers) do
|
||||
|
rafael marked this conversation as resolved
Outdated
rafael
commented
This looks excellent, great that you managed to do it in such a simple way :) This looks excellent, great that you managed to do it in such a simple way :)
|
||||
headers
|
||||
|> Enum.find_value(fn
|
||||
{"accept-language", value} -> value
|
||||
_ -> nil
|
||||
end)
|
||||
|> parse_accept_language()
|
||||
|> Enum.find(&supported_locale?/1)
|
||||
|> fallback_locale()
|
||||
end
|
||||
|
||||
defp parse_accept_language(nil), do: []
|
||||
|
||||
defp parse_accept_language(header) do
|
||||
header
|
||||
|> String.split(",")
|
||||
|> Enum.map(&String.trim/1)
|
||||
|> Enum.map(fn lang ->
|
||||
lang
|
||||
# we only want the first part
|
||||
|> String.split(";")
|
||||
|> hd()
|
||||
|> String.split("-")
|
||||
|> hd()
|
||||
end)
|
||||
end
|
||||
|
||||
# Our supported languages for now are german and english, english as fallback language
|
||||
defp supported_locale?(locale), do: locale in ["en", "de"]
|
||||
defp fallback_locale(nil), do: "en"
|
||||
defp fallback_locale(locale), do: locale
|
||||
end
|
||||
|
|
|
|||
Hmm, in the line above we configure tailwind to check the ash authentication files as well:
it seems like that's not working if we need to add the classes manually to the safelist?
No you are right, that was a leftover, if we set tailwindcss as in the other comment we do not need the safelist