11

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.

richhallstoke
  • 1,519
  • 2
  • 16
  • 29
  • Why do you want to get an outdated pot file, if you have the final one? Shouldn't you only merge changes to your translate .po file? – vgru May 09 '11 at 15:29

7 Answers7

12

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.

Peter Eisentraut
  • 35,221
  • 12
  • 85
  • 90
  • 2
    Use the option `--keep-header` if you want to keep the header as it is in the translation (so you can modify it instead of creating a new one). – PhoneixS Nov 06 '17 at 12:54
  • 1
    Keeping the header as PhoneixS suggests may be necessary if your keys aren't plain ascii. – tremby Apr 17 '19 at 21:37
5

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.

Michele Locati
  • 1,655
  • 19
  • 25
3

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.

Michele Locati
  • 1,655
  • 19
  • 25
  • I think you definitely want `--keep-header`, since without it, it loses the character encoding information, leading to errors like: warning:The following msgid contains non-ASCII characters. "This will cause problems to translators who use a character encoding different from yours. Consider using a pure ASCII msgid instead." – Lucas Wiman May 12 '17 at 22:34
2

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 ""

richhallstoke
  • 1,519
  • 2
  • 16
  • 29
  • 1
    Note that with this answer you could have problems if some text has a double quote inside the text itself. – PhoneixS Mar 01 '17 at 15:47
0

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

Marie
  • 1
0

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/

Siltaar
  • 173
  • 1
  • 7
0

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.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • @ignacio-vazquez-abrams: Unfortunately this isn't a great option since generating the .pot file from source code also pulls in thousands of strings which should not be translated and mixes them all in together. It's taken considerable work to _clean_ the originally generated **.pot** file and the source code hasn't changed. I realise this isn't the normal way of working with gettext but still this is what I'm looking to achieve, perhaps with a **sed** command or something like that. – richhallstoke May 10 '11 at 08:07