POT generation: Missing options

The resulting POT file using the pot script
(Sage 9.x: Localization | Roots Documentation)
can be used for translating and saving a PO file.

The PO file doesn’t contain the necessary options for updating the translations directly from that PO file (which already contains all the translated strings).
What options have to be missed - and can the pot script be modified to include these options?

What are the options are you mention? I’m using Poedit and I can update the po file from script generated pot file whithout problems.

1 Like

The following npm script is used:

"pot": "mkdir -p ./resources/lang && find ./resources ./app -iname '*.php' | xargs xgettext --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -o resources/lang/example.pot && find ./resources -iname '*.blade.php' | xargs xgettext --language=Python --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -j -o resources/lang/example.pot"

When the resulting POT file is opened in POEdit, saved as a translation file and then a source update is tried, POEdit tries to scan all files, (also node_modules) and hangs. The catalog options are empty.

A command already built into wp cli seems to do the same:
wp i18n make-pot.

From

npm script for converting the PO files to JSON files for being used as Gutenberg editor translations:

"po2json": "find ./resources/lang -iname '*.po' -and -not -iname '*.json' -exec sh -c ./node_modules/.bin/po2json {} ${0%.po}.json -f jed \\;"

I do not use predefined routes inside poedit file and, from poedit, run “Catalog > Updtate from source code”.

Instead, I run yarn pot every time I want to update the catalog, and, from poedit, run “Catalog > Update from POT file”.

Doesn’t it work for you?

I’ve recently have to work with a multilingual website (37 to be exact. and it’s WPML. you can multiply nightmare factor here) so manually updating PO via Poedit become a very painful task. So I come up with an npm script to help update PO and compile into MO

ps. I change command from yarn pot to yarn translation

    "translation": "mkdir -p ./resources/lang && find ./resources ./app -iname '*.php' | xargs xgettext --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -o resources/lang/sage.pot && find ./resources -iname '*.blade.php' | xargs xgettext --language=Python --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -j -o resources/lang/sage.pot",
    "translation:update": "for filename in ./resources/lang/*.po; do msgmerge -U $filename ./resources/lang/sage.pot; done; rm ./resources/lang/*.po~",
    "translation:compile": "rm ./resources/lang/*.mo; for filename in ./resources/lang/*.po; do msgfmt $filename -o \"${filename%.*}.mo\"; done"

and then you run yarn translation && yarn translation:update && yarn translation:compile

3 Likes

@Jirayu: It would be great if these scripts can be expanded to also use JS files, notably for Gutenberg block styles/formats translations.

Just found the official alternative to po2json from npm, using wp CLI:
https://developer.wordpress.org/cli/commands/i18n/make-json/