logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

error_helpers.ex (1160B)


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