poedit 似乎是在 Python 中处理 gettext/po 文件的首选库。 docs 显示如何遍历消息字符串、保存 po 和 mo 文件等。但是,我不清楚,如何编辑特定条目?
比方说,我遍历现有 po 文件中的所有消息,并以带有 textareas 的 HTML 表单显示它们。通过提交表单,我得到 - 例如 - 原始
msgstr = " Hello World "
和通过文本区域翻译
msgstr = " Hello World "
po 文件中的原始部分可能如下所示:
#: .\accounts\forms.py:26 .\accounts\registration\forms.py:48
msgid "Hello World"
msgstr ""
或设置模糊标志:
#: .\accounts\forms.py:26 .\accounts\registration\forms.py:48
#, fuzzy
msgid "Hello World"
msgstr "Hallo"
现在我如何在实际的 po 文件中更新这个特定的翻译?如果此消息被标记为“模糊”,我该如何删除此标志?
任何帮助表示赞赏...
最佳答案
好吧,通读了polib的源代码后,我找到了这种方式来实现,我想要的:
entry = po.find('Email address')
if entry:
entry.msgstr = 'E-Mail-Adresse'
if 'fuzzy' in entry.flags:
entry.flags.remove('fuzzy')
这似乎是要走的路......
在复数的情况下 - 仅举个例子:
entry = po.find('%s hour ago')
if entry and entry.msgid_plural:
entry.msgstr_plural['0'] = 'Vor %s Stunde'
entry.msgstr_plural['1'] = 'Vor %s Stunden'
polib 的文档应该最终更新。否则很棒的工具。
关于python - 在 Python 中使用 polib 修改/更新 po 文件中的条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14405425/