fix ecto helpers

This commit is contained in:
Maksim Pechnikov 2020-11-10 10:07:29 +03:00
parent 122e487274
commit ffa1b00fa1

View File

@ -22,19 +22,14 @@ defmodule Pleroma.EctoHelper do
end end
defp do_prettify({field_name, {msg, variables}}, mapping_fields) do defp do_prettify({field_name, {msg, variables}}, mapping_fields) do
compound_message = do_interpolate(msg, variables) do_prettify({field_name, do_interpolate(msg, variables)}, mapping_fields)
do_prettify({field_name, compound_message}, mapping_fields)
end end
defp do_interpolate(string, [{name, value} | rest]) do defp do_interpolate(string, [{name, value} | rest]) do
n = Atom.to_string(name) string
msg = String.replace(string, "%{#{n}}", do_to_string(value)) |> String.replace("%{#{name}}", to_string(value))
do_interpolate(msg, rest) |> do_interpolate(rest)
end end
defp do_interpolate(string, []), do: string defp do_interpolate(string, []), do: string
defp do_to_string(value) when is_integer(value), do: Integer.to_string(value)
defp do_to_string(value) when is_bitstring(value), do: value
defp do_to_string(value) when is_atom(value), do: Atom.to_string(value)
end end