Merge branch 'deprecate-public_endpoint' into 'develop'
[akkoma] / lib / pleroma / web / views / error_helpers.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ErrorHelpers do
6 @moduledoc """
7 Conveniences for translating and building error messages.
8 """
9
10 @doc """
11 Translates an error message using gettext.
12 """
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
22 # written simply as:
23 #
24 # dngettext "errors", "1 file", "%{count} files", count
25 # dgettext "errors", "is invalid"
26 #
27 if count = opts[:count] do
28 Gettext.dngettext(Pleroma.Web.Gettext, "errors", msg, msg, count, opts)
29 else
30 Gettext.dgettext(Pleroma.Web.Gettext, "errors", msg, opts)
31 end
32 end
33 end