gettext v0.15.0 mix gettext.merge View Source
Merges PO/POT files with PO files.
This task is used when translations in the source code change: when they do,
mix gettext.extract is usually used to extract the new translations to POT
files. At this point, developers or translators can use this task to “sync”
the newly updated POT files with the existing locale-specific PO files. All
the metadata for each translation (like position in the source code, comments
and so on) is taken from the newly updated POT file; the only things taken
from the PO file are the actual translated strings.
Translations in the updated PO/POT file that have an exact match (a translation with the same msgid) in the old PO file are merged as described above. When a translation in the update PO/POT files has no match in the old PO file, a fuzzy match for that translation is attempted. For example, assume we have this POT file:
msgid "hello, world!" msgstr ""
and we merge it with this PO file:
# notice no exclamation point here msgid "hello, world" msgstr "ciao, mondo"
Since the two translations are very similar, the msgstr from the existing translation will be taken over to the new translation, which will however be marked as fuzzy:
#, fuzzy msgid "hello, world!" msgstr "ciao, mondo"
fuzzy flag calls for review from a translator.
Fuzzy matching can be configured (for example, the threshold for translation similarity can be tweaked) or disabled entirely; lool at the “Options” section below.
mix gettext.merge OLD_FILE UPDATED_FILE [OPTIONS] mix gettext.merge DIR [OPTIONS]
If two files are given as arguments, they must be a
.po file and a
.pot file. The first one is the old PO file, while the second one is
the last generated one. They are merged and written over the first file. For
mix gettext.merge priv/gettext/en/LC_MESSAGES/default.po priv/gettext/default.pot
If only one argument is given, then that argument must be a directory
containing Gettext translations (with
.pot files at the root level alongside
locale directories - this is usually a “backend” directory used by a Gettext
mix gettext.merge priv/gettext
--locale LOCALE option is given, then only the PO files in
DIR/LOCALE/LC_MESSAGES will be merged with the POT files in
DIR. If no
options are given, then all the PO files for all locales under
merged with the POT files in
By default, Gettext will determine the number of plural forms for newly generated translations
by checking the value of
nplurals in the
Plural-Forms header in the existing
.po file. If
.po file doesn’t already exist and Gettext is creating a new one or if the
header is not in the
.po file, Gettext will use the number of plural forms that
Gettext.Plural returns for the locale of the file being created. The number of plural forms
can be forced through the
--plural-forms option (see below).
--locale- a string representing a locale. If this is provided, then only the PO files in
DIR/LOCALE/LC_MESSAGESwill be merged with the POT files in
DIR. This option can only be given when a single argument is passed to the task (a directory).
--no-fuzzy- stops fuzzy matching from being performed when merging files.
--fuzzy-threshold- a float between
1which represents the miminum Jaro distance needed for two translations to be considered a fuzzy match. Overrides the global
:fuzzy_thresholdoption (see the docs for
Gettextfor more information on this option).
--plural-forms- a integer strictly greater than
0. If this is passed, new translations in the target PO files will have this number of empty plural forms. See the “Plural forms” section above.