1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ErrorHelpers do
7 Conveniences for translating and building error messages.
11 Translates an error message using gettext.
13 def translate_error({msg, opts}) do
14 # Because error messages were defined within Ecto, we must
15 # call the Gettext module passing our Gettext backend. We
16 # also use the "errors" domain as translations are placed
17 # in the errors.po file.
18 # Ecto will pass the :count keyword if the error message is
19 # meant to be pluralized.
20 # On your own code and templates, depending on whether you
21 # need the message to be pluralized or not, this could be
24 # dngettext "errors", "1 file", "%{count} files", count
25 # dgettext "errors", "is invalid"
27 if count = opts[:count] do
28 Gettext.dngettext(Pleroma.Web.Gettext, "errors", msg, msg, count, opts)
30 Gettext.dgettext(Pleroma.Web.Gettext, "errors", msg, opts)