From: Egor Kislitsyn Date: Wed, 10 Jul 2019 07:52:41 +0000 (+0700) Subject: Add translation helpers X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=26a6871609036c3f3dae53f38effa262af0b10dd;p=akkoma Add translation helpers --- diff --git a/lib/pleroma/web/translation_helpers.ex b/lib/pleroma/web/translation_helpers.ex new file mode 100644 index 000000000..8f5a43bf6 --- /dev/null +++ b/lib/pleroma/web/translation_helpers.ex @@ -0,0 +1,17 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.TranslationHelpers do + defmacro render_error(conn, status, msgid, bindings \\ Macro.escape(%{})) do + quote do + require Pleroma.Web.Gettext + + unquote(conn) + |> Plug.Conn.put_status(unquote(status)) + |> Phoenix.Controller.json(%{ + error: Pleroma.Web.Gettext.dgettext("errors", unquote(msgid), unquote(bindings)) + }) + end + end +end diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index 66813e4dd..b42f6887e 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -23,9 +23,11 @@ defmodule Pleroma.Web do def controller do quote do use Phoenix.Controller, namespace: Pleroma.Web + import Plug.Conn import Pleroma.Web.Gettext import Pleroma.Web.Router.Helpers + import Pleroma.Web.TranslationHelpers plug(:set_put_layout)