2019-09-30 18:18:04 +02:00
|
|
|
defmodule Mobilizon.Cldr do
|
|
|
|
@moduledoc """
|
|
|
|
Module to define supported locales
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Cldr,
|
2022-09-21 10:15:28 +02:00
|
|
|
locales: Application.compile_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:
|
2022-09-21 08:53:50 +02:00
|
|
|
if(Application.compile_env(:mobilizon, :env) == :prod,
|
2020-11-17 15:42:03 +01:00
|
|
|
do: Mobilizon.Web.Gettext,
|
|
|
|
else: nil
|
|
|
|
),
|
2022-09-19 09:19:28 +02:00
|
|
|
providers: [Cldr.Number, Cldr.Calendar, Cldr.DateTime, Cldr.Language],
|
|
|
|
precompile_transliterations: [{:latn, :arabext}]
|
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
|