Refactor to avoid calling Mobilizon.Cldr.known_locale_name with a string

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2022-03-21 17:50:38 +01:00
parent 3dd0b60606
commit 7067173a5a
3 changed files with 28 additions and 14 deletions

View File

@@ -12,4 +12,18 @@ defmodule Mobilizon.Cldr do
else: nil
),
providers: [Cldr.Number, Cldr.Calendar, Cldr.DateTime, Cldr.Language]
def known_locale?(locale) do
Mobilizon.Cldr.known_locale_names()
|> Enum.map(&Atom.to_string/1)
|> Enum.member?(locale)
end
def locale_or_default(locale, default \\ "en") do
if known_locale?(locale) do
locale
else
default
end
end
end