WIP feat:translation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Moritz 2025-07-04 00:48:15 +02:00
parent c251e1dba3
commit 59f18e1fd2
Signed by: moritz
GPG key ID: 1020A035E5DD0824
12 changed files with 1163 additions and 6 deletions

View file

@ -443,6 +443,7 @@ defmodule MvWeb.CoreComponents do
Translates an error message using gettext.
"""
def translate_error({msg, opts}) do
IO.puts("DEBUG: translate_error called with msg: #{inspect(msg)}, opts: #{inspect(opts)}")
# When using gettext, we typically pass the strings we want
# to translate as a static argument:
#
@ -453,11 +454,15 @@ defmodule MvWeb.CoreComponents do
# dynamically, so we need to translate them by calling Gettext
# with our gettext backend as first argument. Translations are
# available in the errors.po file (as we use the "errors" domain).
if count = opts[:count] do
Gettext.dngettext(MvWeb.Gettext, "errors", msg, msg, count, opts)
else
Gettext.dgettext(MvWeb.Gettext, "errors", msg, opts)
end
result =
if count = opts[:count] do
Gettext.dngettext(MvWeb.Gettext, "errors", msg, msg, count, opts)
else
Gettext.dgettext(MvWeb.Gettext, "errors", msg, opts)
end
IO.puts("DEBUG: translate_error result: #{inspect(result)}")
result
end
@doc """
@ -466,4 +471,22 @@ defmodule MvWeb.CoreComponents do
def translate_errors(errors, field) when is_list(errors) do
for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts})
end
@doc """
Translates Backpex strings using gettext.
"""
def translate_backpex({msg, opts}) do
IO.puts("DEBUG: translate_backpex called with msg: #{inspect(msg)}, opts: #{inspect(opts)}")
# Use our custom translation module
result =
if count = opts[:count] do
Gettext.dngettext(MvWeb.Gettext, "backpex", msg, msg, count, opts)
else
Gettext.dgettext(MvWeb.Gettext, "backpex", msg, opts)
end
IO.puts("DEBUG: translate_backpex result: #{inspect(result)}")
result
end
end