From 20588517fc5ed86c77865d879027618a1eb54106 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Wed, 13 Jul 2022 18:31:35 -0400 Subject: [PATCH] Make admin api use translated config descriptions --- .../controllers/config_controller.ex | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/admin_api/controllers/config_controller.ex b/lib/pleroma/web/admin_api/controllers/config_controller.ex index 55ab6d063..f6fbbc910 100644 --- a/lib/pleroma/web/admin_api/controllers/config_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/config_controller.ex @@ -22,10 +22,42 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ConfigOperation + defp translate_descriptions(descriptions) do + Enum.map(descriptions, &translate_item/1) + end + + defp translate_string(str) do + Gettext.dgettext(Pleroma.Web.Gettext, "config_descriptions", str) + end + + defp maybe_put_translated(item, key) do + if item[key] do + Map.put(item, key, translate_string(item[key])) + else + item + end + end + + defp translate_item(item) do + item + |> maybe_put_translated(:label) + |> maybe_put_translated(:description) + |> translate_children() + end + + defp translate_children(%{children: children} = item) when is_list(children) do + item + |> Map.put(:children, translate_descriptions(children)) + end + + defp translate_children(item) do + item + end + def descriptions(conn, _params) do descriptions = Enum.filter(Pleroma.Docs.JSON.compiled_descriptions(), &whitelisted_config?/1) - json(conn, descriptions) + json(conn, translate_descriptions(descriptions)) end def show(conn, %{only_db: true}) do