Use correct default language when no Accept-Language is set
Closes #792 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -56,15 +56,18 @@ defmodule Mobilizon.Web.ErrorView do
|
||||
end
|
||||
|
||||
def render("500.html", assigns) do
|
||||
Mobilizon.Config.instance_config()
|
||||
|> Keyword.get(:default_language, "en")
|
||||
|> Gettext.put_locale()
|
||||
locale =
|
||||
Mobilizon.Config.instance_config()
|
||||
|> Keyword.get(:default_language, "en")
|
||||
|
||||
Gettext.put_locale(locale)
|
||||
|
||||
assigns =
|
||||
assigns
|
||||
|> Map.update(:details, [], & &1)
|
||||
|> Map.put(:instance, Mobilizon.Config.instance_name())
|
||||
|> Map.put(:contact, Mobilizon.Config.contact())
|
||||
|> Map.put(:locale, locale)
|
||||
|
||||
render("500_page.html", assigns)
|
||||
end
|
||||
|
||||
@@ -51,8 +51,29 @@ defmodule Mobilizon.Web.Views.Utils do
|
||||
|> String.replace("<html lang=\"en\">", "<html lang=\"#{locale}\">")
|
||||
end
|
||||
|
||||
@spec get_locale(Conn.t()) :: String.t()
|
||||
def get_locale(%{private: %{cldr_locale: nil}}), do: "en"
|
||||
def get_locale(%{private: %{cldr_locale: %{requested_locale_name: locale}}}), do: locale
|
||||
def get_locale(_), do: "en"
|
||||
@spec get_locale(Plug.Conn.t()) :: String.t()
|
||||
def get_locale(%Plug.Conn{assigns: assigns}) do
|
||||
assigns
|
||||
|> Map.get(:locale)
|
||||
|> check_locale()
|
||||
end
|
||||
|
||||
def get_locale(_), do: default_locale()
|
||||
|
||||
defp check_locale(nil) do
|
||||
default_locale()
|
||||
|> check_locale()
|
||||
end
|
||||
|
||||
defp check_locale("") do
|
||||
check_locale(nil)
|
||||
end
|
||||
|
||||
defp check_locale(locale) when is_binary(locale), do: locale
|
||||
|
||||
defp default_locale do
|
||||
Mobilizon.Config.instance_config()
|
||||
|> Keyword.get(:default_language, "en")
|
||||
|> Kernel.||("en")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user