2022-07-13 15:59:23 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-01 04:11:47 -07:00
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
2022-07-13 15:59:23 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Docs.Translator.Compiler do
|
|
|
|
@external_resource "config/description.exs"
|
|
|
|
@raw_config Pleroma.Config.Loader.read("config/description.exs")
|
|
|
|
@raw_descriptions @raw_config[:pleroma][:config_description]
|
|
|
|
|
|
|
|
defmacro __before_compile__(_env) do
|
|
|
|
strings =
|
|
|
|
__MODULE__.descriptions()
|
|
|
|
|> __MODULE__.extract_strings()
|
|
|
|
|
|
|
|
quote do
|
|
|
|
def placeholder do
|
|
|
|
unquote do
|
|
|
|
Enum.map(
|
|
|
|
strings,
|
2022-07-14 15:41:33 -06:00
|
|
|
fn {path, type, string} ->
|
|
|
|
ctxt = msgctxt_for(path, type)
|
|
|
|
|
2022-07-13 15:59:23 -06:00
|
|
|
quote do
|
2022-07-14 15:41:33 -06:00
|
|
|
Pleroma.Web.Gettext.dpgettext_noop(
|
|
|
|
"config_descriptions",
|
|
|
|
unquote(ctxt),
|
|
|
|
unquote(string)
|
|
|
|
)
|
2022-07-13 15:59:23 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def descriptions do
|
|
|
|
Pleroma.Web.ActivityPub.MRF.config_descriptions()
|
|
|
|
|> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
|
|
|
|
|> Pleroma.Docs.Generator.convert_to_strings()
|
|
|
|
end
|
|
|
|
|
|
|
|
def extract_strings(descriptions) do
|
|
|
|
descriptions
|
2022-07-14 15:41:33 -06:00
|
|
|
|> Enum.reduce(%{strings: [], path: []}, &process_item/2)
|
|
|
|
|> Map.get(:strings)
|
2022-07-13 15:59:23 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
defp process_item(entity, acc) do
|
|
|
|
current_level =
|
|
|
|
acc
|
|
|
|
|> process_desc(entity)
|
|
|
|
|> process_label(entity)
|
|
|
|
|
|
|
|
process_children(entity, current_level)
|
|
|
|
end
|
|
|
|
|
2022-07-14 15:41:33 -06:00
|
|
|
defp process_desc(acc, %{description: desc} = item) do
|
|
|
|
%{
|
|
|
|
strings: [{acc.path ++ [key_for(item)], "description", desc} | acc.strings],
|
|
|
|
path: acc.path
|
|
|
|
}
|
2022-07-13 15:59:23 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
defp process_desc(acc, _) do
|
|
|
|
acc
|
|
|
|
end
|
|
|
|
|
2022-07-14 15:41:33 -06:00
|
|
|
defp process_label(acc, %{label: label} = item) do
|
|
|
|
%{
|
|
|
|
strings: [{acc.path ++ [key_for(item)], "label", label} | acc.strings],
|
|
|
|
path: acc.path
|
|
|
|
}
|
2022-07-13 15:59:23 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
defp process_label(acc, _) do
|
|
|
|
acc
|
|
|
|
end
|
|
|
|
|
2022-07-14 15:41:33 -06:00
|
|
|
defp process_children(%{children: children} = item, acc) do
|
|
|
|
current_level = Map.put(acc, :path, acc.path ++ [key_for(item)])
|
|
|
|
|
2022-07-13 15:59:23 -06:00
|
|
|
children
|
2022-07-14 15:41:33 -06:00
|
|
|
|> Enum.reduce(current_level, &process_item/2)
|
|
|
|
|> Map.put(:path, acc.path)
|
2022-07-13 15:59:23 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
defp process_children(_, acc) do
|
|
|
|
acc
|
|
|
|
end
|
2022-07-14 15:41:33 -06:00
|
|
|
|
|
|
|
def msgctxt_for(path, type) do
|
|
|
|
"config #{type} at #{Enum.join(path, " > ")}"
|
|
|
|
end
|
|
|
|
|
|
|
|
defp convert_group({_, group}) do
|
|
|
|
group
|
|
|
|
end
|
|
|
|
|
|
|
|
defp convert_group(group) do
|
|
|
|
group
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_for(%{group: group, key: key}) do
|
|
|
|
"#{convert_group(group)}-#{key}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_for(%{group: group}) do
|
|
|
|
convert_group(group)
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_for(%{key: key}) do
|
|
|
|
key
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_for(_) do
|
|
|
|
nil
|
|
|
|
end
|
2022-07-13 15:59:23 -06:00
|
|
|
end
|