如何从翻译的 .po 文件生成新的 .pot 模板
从不完整的 gettext .pot 文件开始,生成的 .po 翻译文件现在包含大量最初不在 .pot 中的翻译字符串 文件。
如何从翻译的 .po 文件反向生成其他语言的 .pot 文件(带有空白翻译条目的字符串)?
感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以使用如下内容:
msgfilter
将程序应用于文件中的所有翻译,而true
只是一些不会为任何输入输出任何内容的程序。您可能需要在此之后修改一下标题注释,使其看起来像一个新的 POT 文件。
You can use something like this:
msgfilter
applies a program to all translations in a file, andtrue
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.
虽然 @richhallstoke 报告的命令可以在 Linux 和 Mac 上运行,
但在 Windows 上却会失败,因为我们没有
true
命令。我刚刚发布了一个在线工具来执行此操作(除其他外):只需在浏览器中拖放即可您的 .po 文件,点击“工具”图标,然后单击“转换为 .pot”。
PS:该在线工具是 FOSS:其源代码位于 GitHub 上。
While the command reported by @richhallstoke works on Linux and Mac
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.
我花了很长时间才找到一种方法,但最终我找到了使用 Notepad++ 的解决方案。从搜索|替换...菜单中,我能够使用正则表达式全部替换。
查找:
msgstr ".*"
替换为:
msgstr ""
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 ""
我认为最干净的方法是使用 Peter Eisentraut 建议的解决方案:
msgfilter -i xx.po -o new.pot true
您还可以通过添加
- 来保留 gettext 标头-keep-header
在最后一个true
参数之前。在这种情况下,您需要检查生成的标头,因为它可能包含特定于语言的指令(例如复数规则的数量)。对于 Windows 用户:为了使用这种方法,您需要一个行为类似于
true
的程序(即,除了运行成功之外,它不执行任何操作),例如true
for Windows 我正是出于这个原因编写的。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 finaltrue
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 thetrue
for Windows I wrote for exactly this reason.当前的 Windows 版 PoEdit 3.4.1 中没有
msgfilter.exe
,但您可以使用xgettext.exe
(您可以在 ...\Poedit\GettextTools\ 中找到它) bin) 以从 .po 文件开始生成 .pot 文件:With current PoEdit 3.4.1 for Windows there is no
msgfilter.exe
, but you can usexgettext.exe
(you can find it in ...\Poedit\GettextTools\bin) to generate a .pot file starting from the .po file:如果您想更新翻译字符串,则不需要 .pot 文件。从 poedit :目录,从 .pot 文件更新,然后在浏览器窗口中将 .pot 文件仅更改为“所有文件”,选择您的 .po 文件,它将处理
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
你不知道。您可以从源代码生成 .pot 文件。
msgmerge
然后获取新的 .pot 文件和现有的 .po 文件,并将旧条目合并到新文件中。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.就问题而言,这里是 vim 替换命令,用于从完整的 .po 文件的翻译中生成 .pot 文件。
:%s/msgid\_.\{-\}msgstr \(\("."\_.\)\)/msgid \1msgstr ""\r/
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/