Changeset View
Changeset View
Standalone View
Standalone View
larus/web/gettext.ex
defmodule Larus.Gettext do | defmodule Larus.Gettext do | ||||
@moduledoc """ | @moduledoc """ | ||||
A module providing Internationalization with a gettext-based API. | A module providing Internationalization with a gettext-based API. | ||||
By using [Gettext](http://hexdocs.pm/gettext), | By using [Gettext](http://hexdocs.pm/gettext), | ||||
your module gains a set of macros for translations, for example: | your module gains a set of macros for translations, for example: | ||||
import Larus.Gettext | import Larus.Gettext | ||||
# Simple translation | # Simple translation | ||||
gettext "Here is the string to translate" | gettext "Here is the string to translate" | ||||
# Plural translation | # Plural translation | ||||
ngettext "Here is the string to translate", | ngettext "Here is the string to translate", | ||||
"Here are the strings to translate", | "Here are the strings to translate", | ||||
3 | 3 | ||||
# Domain-based translation | # Domain-based translation | ||||
dgettext "errors", "Here is the error message to translate" | dgettext "errors", "Here is the error message to translate" | ||||
See the [Gettext Docs](http://hexdocs.pm/gettext) for detailed usage. | See the [Gettext Docs](http://hexdocs.pm/gettext) for detailed usage. | ||||
""" | """ | ||||
use Gettext, otp_app: :larus | use Gettext, otp_app: :larus | ||||
def supported_locales do | |||||
known = Gettext.known_locales(Larus.Gettext) | |||||
allowed = config[:locales] | |||||
Set.intersection(Enum.into(known, HashSet.new), Enum.into(allowed, HashSet.new)) | |||||
|> Set.to_list | |||||
end | |||||
defp config do | |||||
Application.get_env(:larus, __MODULE__) | |||||
end | |||||
end | end |