Framework.I18n.Gettext (Framework v0.5.0)

View Source

Gettext backend for Framework internationalization.

This module uses Gettext to provide compile-time translations for framework messages and errors. Product applications can use this backend or define their own.

Translation Files

Translation files are stored in priv/gettext/<locale>/LC_MESSAGES/:

priv/gettext/
  en-US/LC_MESSAGES/
    default.po      # Default domain for general messages
    errors.po       # Error messages
  es-ES/LC_MESSAGES/
    default.po
    errors.po
  fr-FR/LC_MESSAGES/
    default.po
    errors.po

Extracting Translations

Use the built-in Gettext tasks to extract and merge translations:

# Extract translation keys from code
mix gettext.extract

# Merge new keys into existing .po files
mix gettext.merge priv/gettext

Adding New Translations

  1. Add translation calls in code using Framework.I18n.t/3
  2. Run mix gettext.extract to extract keys
  3. Run mix gettext.merge priv/gettext to update .po files
  4. Edit .po files to add translations

Summary

Functions

handle_missing_bindings(exception, incomplete)

Callback implementation for Gettext.Backend.handle_missing_bindings/2.

handle_missing_plural_translation(locale, domain, msgctxt, msgid, msgid_plural, n, bindings)

Callback implementation for Gettext.Backend.handle_missing_plural_translation/7.

handle_missing_translation(locale, domain, msgctxt, msgid, bindings)

Callback implementation for Gettext.Backend.handle_missing_translation/5.

priv_gettext_path()

Returns the path to the Gettext locales directory.

This is used by Gettext to find translation files.