3981b270d3b842beafa94c3fb208d3352fdead45
[akkoma] / lib / pleroma / web / views / error_helpers.ex
1 defmodule Pleroma.Web.ErrorHelpers do
2 @moduledoc """
3 Conveniences for translating and building error messages.
4 """
5
6 @doc """
7 Translates an error message using gettext.
8 """
9 def translate_error({msg, opts}) do
10 # Because error messages were defined within Ecto, we must
11 # call the Gettext module passing our Gettext backend. We
12 # also use the "errors" domain as translations are placed
13 # in the errors.po file.
14 # Ecto will pass the :count keyword if the error message is
15 # meant to be pluralized.
16 # On your own code and templates, depending on whether you
17 # need the message to be pluralized or not, this could be
18 # written simply as:
19 #
20 # dngettext "errors", "1 file", "%{count} files", count
21 # dgettext "errors", "is invalid"
22 #
23 if count = opts[:count] do
24 Gettext.dngettext(Pleroma.Web.Gettext, "errors", msg, msg, count, opts)
25 else
26 Gettext.dgettext(Pleroma.Web.Gettext, "errors", msg, opts)
27 end
28 end
29 end