Mar*_*ger 11 translation edit gettext po
有没有人知道从PO文件批量删除所有模糊翻译的方法.就像是:
if#,fuzzy == TRUE然后SET msgstr =""AND REMOVE#,模糊
Aar*_*n M 13
如果安装了gettext,则可以使用msgattrib命令来完成此操作:
msgattrib --clear-fuzzy --empty -o /path/to/output.po /path/to/input.po
msgattrib的完整文档在这里:
https://www.gnu.org/software/gettext/manual/html_node/msgattrib-Invocation.html
小智 7
如果安装了GNU gettext,则可以使用此命令删除模糊消息:
msgattrib --no-fuzzy -o path/to/your/output/po/file path/to/your/input/po/file
您可以使用polib删除模糊字符串,polib是Python中用于处理gettext po文件的库:
import os, polib
for dirname, dirnames, filenames in os.walk('/path/to/your/project/'):
for filename in filenames:
try: ext = filename.rsplit('.', 1)[1]
except: ext = ''
if ext == 'po':
po = polib.pofile(os.path.join(dirname, filename))
for entry in po.fuzzy_entries():
entry.msgstr = ''
if entry.msgid_plural: entry.msgstr_plural['0'] = ''
if entry.msgid_plural and '1' in entry.msgstr_plural: entry.msgstr_plural['1'] = ''
if entry.msgid_plural and '2' in entry.msgstr_plural: entry.msgstr_plural['2'] = ''
entry.flags.remove('fuzzy')
po.save()
Run Code Online (Sandbox Code Playgroud)
此脚本删除模糊转换字符串+模糊标记,但保持未翻译的原始msgids完整.有些语言(ru,cz,...)有两种以上的复数形式,因此,我们检查msgstr_plural ['2'].列表索引必须是一个字符串.不要使用整数.