问题
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.
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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 ""
回答5:
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.
回答6:
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
回答7:
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/
来源:https://stackoverflow.com/questions/5938869/how-to-generate-a-new-pot-template-from-a-translated-po-file