2019-09-30 18:18:04 +02:00
|
|
|
defmodule Mobilizon.Cldr do
|
|
|
|
@moduledoc """
|
|
|
|
Module to define supported locales
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Cldr,
|
2020-11-06 11:25:58 +01:00
|
|
|
locales: Application.get_env(:mobilizon, :cldr)[:locales],
|
2021-06-22 13:15:21 +02:00
|
|
|
add_fallback_locales: true,
|
2020-11-17 15:42:03 +01:00
|
|
|
gettext:
|
|
|
|
if(Application.fetch_env!(:mobilizon, :env) == :prod,
|
|
|
|
do: Mobilizon.Web.Gettext,
|
|
|
|
else: nil
|
|
|
|
),
|
2020-10-07 15:37:23 +02:00
|
|
|
providers: [Cldr.Number, Cldr.Calendar, Cldr.DateTime, Cldr.Language]
|
2022-03-21 17:50:38 +01:00
|
|
|
|
|
|
|
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
|
2019-09-30 18:18:04 +02:00
|
|
|
end
|