删除PO文件的所有模糊条目 [英] Removing all fuzzy entries of a PO file

查看:180
本文介绍了删除PO文件的所有模糊条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有人知道一种从PO文件中批量删除所有模糊翻译的方法.像这样:

Does anyone know a method to mass delete all fuzzy translations from a PO file. Something like:

如果#,模糊== TRUE,则设置msgstr ="并删除#,模糊

if #, fuzzy == TRUE Then SET msgstr="" AND REMOVE #, fuzzy

推荐答案

您可以使用 polib ,它是Python中用于处理gettext po文件的库:

You can remove fuzzy strings with polib, which is THE library in Python for working with gettext po files:

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()

此脚本删除了模糊翻译字符串+模糊标记,但使未翻译的原始msgids保持完整.有些语言(ru,cz,...)具有两种以上的复数形式,因此,我们检查msgstr_plural ['2'].列表索引必须是字符串.请勿为此使用整数.

This script removes the fuzzy translation strings + fuzzy flags, but keeps the untranslated original msgids intact. Some languages (ru, cz, ...) have more than two plural forms, therefore, we check on msgstr_plural['2']. The list index has to be a string. Don't use integers for that.

这篇关于删除PO文件的所有模糊条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆