translate field names for visibility dropdown
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Simon 2025-12-11 00:51:26 +01:00
parent 8512be0282
commit 1675d66b67
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
2 changed files with 59 additions and 2 deletions

View file

@ -152,9 +152,25 @@ defmodule MvWeb.Components.FieldVisibilityDropdownComponent do
defp field_to_string(field) when is_atom(field), do: Atom.to_string(field)
defp field_to_string(field) when is_binary(field), do: field
defp format_field_label(field) do
defp format_field_label(field) when is_atom(field) do
MvWeb.Translations.MemberFields.label(field)
end
defp format_field_label(field) when is_binary(field) do
case safe_to_existing_atom(field) do
{:ok, atom} -> MvWeb.Translations.MemberFields.label(atom)
:error -> fallback_label(field)
end
end
defp safe_to_existing_atom(string) do
{:ok, String.to_existing_atom(string)}
rescue
ArgumentError -> :error
end
defp fallback_label(field) do
field
|> field_to_string()
|> String.replace("_", " ")
|> String.split()
|> Enum.map_join(" ", &String.capitalize/1)