translate field names for visibility dropdown
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
8512be0282
commit
1675d66b67
2 changed files with 59 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue