A module providing Internationalization with a gettext-based API for extensions.
By using Gettext, your module compiles translations
that you can use in your application. To use this Gettext backend module,
call use Gettext and pass it as an option:
use Gettext, backend: MishkaCmsCore.Gettext
# Simple translation
gettext("Here is the string to translate")
# Plural translation
ngettext("Here is the string to translate",
"Here are the strings to translate",
3)
# Domain-based translation
dgettext("errors", "Here is the error message to translate")See the Gettext Docs for detailed usage.
The messages are read from priv/gettext, which holds the English catalogue only: the .pot
templates and en/LC_MESSAGES/*.po. A message with no translation in the reader's locale reads as
its own text, interpolated. To add a language, run
mix gettext.merge priv/gettext --locale xx and translate the .po files it creates.
Marking the untranslated
With config :mishka_cms_core, :gettext_marks_untranslated, true at compile time, which only the
test configurations set, a message the locale has no translation for reads as its interpolated text
behind the marker "[<locale>] ", so a test sees that a word went through Gettext in the locale of
the reader without a .po for that locale:
Gettext.put_locale(MishkaCmsCore.Gettext, "fa")
dgettext("mishka_gervaz", "Guest") #=> "[fa] Guest"The marker applies to every locale except "en", to plural messages, and to text with a missing
binding, which is still reported as the default does. A message with the context "alphabet" is a
sort key rather than a phrase, so it reads without the marker and with its letters in reverse
order: a list sorted by it comes out in the reverse of the English order, which tells an order that
follows the reader's alphabet from one that follows the code or the English text.
Without the flag, the default Gettext behaviour is kept.
Summary
Functions
Callback implementation for Gettext.Backend.handle_missing_bindings/2.
Callback implementation for Gettext.Backend.handle_missing_plural_translation/7.
Callback implementation for Gettext.Backend.handle_missing_translation/5.
Functions
Callback implementation for Gettext.Backend.handle_missing_bindings/2.
Callback implementation for Gettext.Backend.handle_missing_plural_translation/7.
Callback implementation for Gettext.Backend.handle_missing_translation/5.