fix(backend): Handle CLDR data having no standard property for a language

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-05-03 11:58:13 +02:00
parent 79b48da222
commit dbe2da79c3
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -183,7 +183,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
case Language.known_languages(String.to_existing_atom(locale)) do
data when is_map(data) ->
data
|> Enum.map(fn {code, elem} -> %{code: code, name: elem.standard} end)
|> Enum.map(fn {code, elem} ->
%{code: code, name: Map.get(elem, :standard, "Unknown")}
end)
|> Enum.filter(fn %{code: code, name: _name} -> code in codes end)
|> (&{:ok, &1}).()
@ -197,7 +199,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
case Language.known_languages(String.to_existing_atom(locale)) do
data when is_map(data) ->
data = Enum.map(data, fn {code, elem} -> %{code: code, name: elem.standard} end)
data =
Enum.map(data, fn {code, elem} ->
%{code: code, name: Map.get(elem, :standard, "Unknown")}
end)
{:ok, data}
{:error, err} ->