Add translation helpers
authorEgor Kislitsyn <egor@kislitsyn.com>
Wed, 10 Jul 2019 07:52:41 +0000 (14:52 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 10 Jul 2019 11:10:09 +0000 (18:10 +0700)
lib/pleroma/web/translation_helpers.ex [new file with mode: 0644]
lib/pleroma/web/web.ex

diff --git a/lib/pleroma/web/translation_helpers.ex b/lib/pleroma/web/translation_helpers.ex
new file mode 100644 (file)
index 0000000..8f5a43b
--- /dev/null
@@ -0,0 +1,17 @@
+# 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(%{})) 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
index 66813e4ddaffa5ad1fd4f807047e639c86a29cc0..b42f6887e17b090535f9170f6703ee8ca9b6f2fa 100644 (file)
@@ -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)