Send emails i18n'd using backend-stored user language

This commit is contained in:
Tusooa Zhu 2022-03-01 21:24:17 -05:00
commit 0149ea4538
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
11 changed files with 1760 additions and 273 deletions

View file

@ -34,4 +34,26 @@ defmodule Pleroma.Web.Gettext do
Gettext.get_locale()
|> String.replace("_", "-", global: true)
end
def supports_locale?(locale) do
Pleroma.Web.Gettext
|> Gettext.known_locales()
|> Enum.member?(locale)
end
def locale_or_default(locale) do
if supports_locale?(locale) do
locale
else
Gettext.get_locale()
end
end
defmacro with_locale_or_default(locale, do: fun) do
quote do
Gettext.with_locale(Pleroma.Web.Gettext.locale_or_default(unquote(locale)), fn ->
unquote(fun)
end)
end
end
end

View file

@ -64,9 +64,7 @@ defmodule Pleroma.Web.Plugs.SetLocalePlug do
end
defp supported_locale?(locale) do
Pleroma.Web.Gettext
|> Gettext.known_locales()
|> Enum.member?(locale)
Pleroma.Web.Gettext.supports_locale?(locale)
end
defp parse_language_option(string) do