Allow to access to a language directly though instance.tld/:lang
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -18,11 +18,13 @@ defmodule Mobilizon.Web.Plugs.SetLocalePlug do
|
||||
def call(conn, _) do
|
||||
locale =
|
||||
[
|
||||
eventual_path_locale(conn.path_info),
|
||||
conn.assigns[:user_locale],
|
||||
conn.assigns[:detected_locale],
|
||||
default_locale(),
|
||||
"en"
|
||||
]
|
||||
|> Enum.filter(& &1)
|
||||
|> Enum.map(&determine_best_locale/1)
|
||||
|> Enum.filter(&supported_locale?/1)
|
||||
|> hd()
|
||||
@@ -31,6 +33,15 @@ defmodule Mobilizon.Web.Plugs.SetLocalePlug do
|
||||
assign(conn, :locale, locale)
|
||||
end
|
||||
|
||||
defp eventual_path_locale(path_info) do
|
||||
with [locale] <- path_info,
|
||||
true <- supported_locale?(locale) do
|
||||
locale
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
@spec supported_locale?(String.t()) :: boolean()
|
||||
defp supported_locale?(locale) do
|
||||
GettextBackend
|
||||
|
||||
@@ -50,8 +50,8 @@ defmodule Mobilizon.Web.Views.Utils do
|
||||
index_content
|
||||
|> replace_meta(tags)
|
||||
|> String.replace(
|
||||
"<html lang=\"en\" dir=\"auto\">",
|
||||
"<html lang=\"#{locale}\" dir=\"#{get_language_direction(locale)}\">"
|
||||
~s(<html lang="en" dir="auto">),
|
||||
~s(<html lang="#{locale}" dir="#{get_language_direction(locale)}">)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user