richhallstoke
richhallstoke

Reputation: 1601

How to generate a new .pot template from a translated .po file

Having started off with an incomplete gettext .pot file, the resulting .po translations file now includes a large number of translation strings that were not originally in the .pot file.

How can I backwards generate a .pot file for other languages (strings with blank translation entries) from a translated .po file?

Thanks for your help.

Upvotes: 12

Views: 11825

Answers (8)

hexaae
hexaae

Reputation: 270

With current PoEdit 3.4.1 for Windows there is no msgfilter.exe, but you can use xgettext.exe (you can find it in ...\Poedit\GettextTools\bin) to generate a .pot file starting from the .po file:

xgettext.exe -i xx.po -o new.pot

Upvotes: 1

Michele Locati
Michele Locati

Reputation: 1844

While the command reported by @richhallstoke works on Linux and Mac

msgfilter -i xx.po -o new.pot true

On Windows this fails because we don't have the true command.

I just released an online tool that perform this operation (among others): simply drag and drop in the browser your .po file, hit the "Tools" icon and click "Convert to .pot".

PS: that online tool is FOSS: its source code is on GitHub.

Upvotes: 8

Michele Locati
Michele Locati

Reputation: 1844

I think that the cleanest approach would be to use the solution suggested by Peter Eisentraut:

msgfilter -i xx.po -o new.pot true

You can also keep the gettext header by adding the --keep-header before the final true argument. In this case you need to check the resulting header because it may contain language-specific instructions (like the number of plural rules).

For Windows users: in order to use this approach, you need a program that acts like true (that is, it does nothing except running succesflully), like the true for Windows I wrote for exactly this reason.

Upvotes: 3

Siltaar
Siltaar

Reputation: 173

Just sided to the question, here is the vim substitution command to make a .pot file from the translation of a fullfilled .po file.

:%s/msgid\_.\{-\}msgstr \(\("."\_.\)\)/msgid \1msgstr ""\r/

Upvotes: 0

Marie
Marie

Reputation: 11

if you want to updates the translation strings you don't need a .pot file. From poedit : catalog, update from .pot file, then in the browser window change .pot files only to "all files", select your .po file and it will process

Upvotes: 1

Peter Eisentraut
Peter Eisentraut

Reputation: 36739

You can use something like this:

msgfilter -i xx.po -o new.pot true

msgfilter applies a program to all translations in a file, and true is just some program that doesn't output anything for any input.

You will probably need to massage the header comment a bit after this to make it really look like a fresh POT file.

Upvotes: 13

richhallstoke
richhallstoke

Reputation: 1601

This took ages to figure out a way of doing it, but in the end I found a solution using Notepad++. From the Search|Replace... menu I was able to Replace All with a regular expression.

Find: msgstr ".*"

Replace with: msgstr ""

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799072

You don't. You generate the .pot file from the source code. msgmerge then takes the new .pot file and the existing .po file, and merges old entries into the new file.

Upvotes: 0

Related Questions