gettext
Consider using the
tfunction (less code, supports template expressions)
The default alias for gettext function is _.
Usage
import { gettext } from 'ttag';
gettext('simple gettext');
or
import { _ } from 'ttag';
_('simple gettext');
Try
https://jsfiddle.net/AlexMost/us7hufjr/3/
Format
Valid
gettext('simple gettext');
Invalid
gettext(`template literal`); // template literals are not supported
gettext('one', 'two'); // gettext supports only 1 argument
Extract
All translations can be extracted to .po file with ttag-cli tool.
import { gettext } from 'ttag';
gettext('Hello');
will be extracted to this:
msgid "Hello"
msgstr ""
Resolve
Suppose we have translated phrase in .po:
msgctxt "email"
msgid "Hello"
msgstr "Вітаємо"
The result js for uk locale will be
gettext('Вітаємо').