1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-11-18 10:59:17 +00:00
akkoma/lib/pleroma/web/translation_helpers.ex

30 lines
814 B
Elixir
Raw Normal View History

2019-07-10 08:52:41 +01:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# 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 08:52:41 +01:00
quote do
require Pleroma.Web.Gettext
2019-10-01 17:43:22 +01: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 08:52:41 +01:00
unquote(conn)
|> Plug.Conn.put_status(unquote(status))
2019-10-01 17:43:22 +01:00
|> Phoenix.Controller.json(error_map)
2019-07-10 08:52:41 +01:00
end
end
end