Usage¶
Workflow¶
- Create your po files using your current workflow.
- Create your mo files using your current workflow.
- Choose one of the following:
- Transpile your mo files to js files using gettextjs
- Import your mo files in js and use the webpack loader.
Transpile using CLI¶
Transpile all your MO files to JS using gettextjs <input> <output>.
Note that the resulting code is ES7 code (including import) and needs to be transpiled before used.
Webpack¶
Add the gettextjs/dist/loader loader to your webpack config for mo files:
The babel-loader is needed because the gettextjs loader outputs ES7, but you can use another loader to do the JS->JS transpilation.
Using transpiled files¶
The transpiled files have a default export which is an instance of Translations()
.
They can either be used directly or you can call set_catalog()
with the instance.
gettext()
and ngettext()
are equivalent to gettext(3)
and ngettext(3). gettext()
takes a single msgid
and returns the
translation for it, if it finds one, or the msgid
. ngettext()
is
used for translations which may have plurals.