1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Docs.Translator.Compiler do
6 @external_resource "config/description.exs"
7 @raw_config Pleroma.Config.Loader.read("config/description.exs")
8 @raw_descriptions @raw_config[:pleroma][:config_description]
10 defmacro __before_compile__(_env) do
12 __MODULE__.descriptions()
13 |> __MODULE__.extract_strings()
20 fn {path, type, string} ->
21 ctxt = msgctxt_for(path, type)
24 Pleroma.Web.Gettext.dpgettext_noop(
25 "config_descriptions",
38 Pleroma.Web.ActivityPub.MRF.config_descriptions()
39 |> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
40 |> Pleroma.Docs.Generator.convert_to_strings()
43 def extract_strings(descriptions) do
45 |> Enum.reduce(%{strings: [], path: []}, &process_item/2)
49 defp process_item(entity, acc) do
52 |> process_desc(entity)
53 |> process_label(entity)
55 process_children(entity, current_level)
58 defp process_desc(acc, %{description: desc} = item) do
60 strings: [{acc.path ++ [key_for(item)], "description", desc} | acc.strings],
65 defp process_desc(acc, _) do
69 defp process_label(acc, %{label: label} = item) do
71 strings: [{acc.path ++ [key_for(item)], "label", label} | acc.strings],
76 defp process_label(acc, _) do
80 defp process_children(%{children: children} = item, acc) do
81 current_level = Map.put(acc, :path, acc.path ++ [key_for(item)])
84 |> Enum.reduce(current_level, &process_item/2)
85 |> Map.put(:path, acc.path)
88 defp process_children(_, acc) do
92 def msgctxt_for(path, type) do
93 "config #{type} at #{Enum.join(path, " > ")}"
96 defp convert_group({_, group}) do
100 defp convert_group(group) do
104 def key_for(%{group: group, key: key}) do
105 "#{convert_group(group)}-#{key}"
108 def key_for(%{group: group}) do
112 def key_for(%{key: key}) do