spc-pleroma/lib/pleroma/web/translation_helpers.ex

30 lines
814 B
Elixir
Raw Normal View History

2019-07-10 07:52:41 +00:00
# Pleroma: A lightweight social networking server
2020-03-03 22:44:49 +00:00
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
2019-07-10 07:52:41 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.TranslationHelpers do
defmacro render_error(
conn,
status,
msgid,
bindings \\ Macro.escape(%{}),
identifier \\ Macro.escape("")
) do
2019-07-10 07:52:41 +00:00
quote do
require Pleroma.Web.Gettext
2019-10-01 16:43:22 +00:00
error_map =
%{
error: Pleroma.Web.Gettext.dgettext("errors", unquote(msgid), unquote(bindings)),
identifier: unquote(identifier)
}
|> Enum.reject(fn {_k, v} -> v == "" end)
|> Map.new()
2019-07-10 07:52:41 +00:00
unquote(conn)
|> Plug.Conn.put_status(unquote(status))
2019-10-01 16:43:22 +00:00
|> Phoenix.Controller.json(error_map)
2019-07-10 07:52:41 +00:00
end
end
end