An Elm package for internationalization (i18n) using GNU gettext MO/PO files. This library allows you to load compiled binary translation files (.mo) and translate text at runtime in your Elm application.
- Simple
t,tn,tp,tpnAPI for translation functions - Support for string formatting with
{placeholder}syntax - Plural form support following gettext plural-form rules
- Context-aware translations to disambiguate identical strings
- Load translations from binary MO files (compiled from PO files)
Add this package to your Elm project:
elm install panthus/elm-gettextA typical i18n workflow looks like this:
-
Write your Elm code using
t,tn,tp,tpnfunctions for all translatable stringsNote that translatable strings cannot be dynamically passed to the translation functions (via variables, loaded from somewhere etc), because the extraction tool requires static strings to be able to extract them into a
.potfile. -
Extract strings from your code into a
.pottemplate file using@panthus/elm-xgettext -
Create/update
.pofiles from the.potfile for each target language -
Translate the strings in each
.pofile (using POEdit or similar) -
Compile
.pofiles to.mobinary files using@panthus/elm-xgettext -
Load the
.mofiles at runtime in your application
See the example/ directory for a complete working example demonstrating:
- Loading translations from MO files
- Switching languages at runtime
- Using all translation functions (
t,tn,tp,tpn)