tools.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:django-transtool 作者: liminspace 项目源码 文件源码
def get_diff_po(po1_fn, po2_fn):
    po1_lines = []
    po2_lines = []
    for entry in sorted(polib.pofile(po1_fn), key=lambda obj: obj.msgid):
        po1_lines.append((
            u'msgid {}\n\n'
            u'msgstr {}\n\n'
        ).format(entry.msgid, entry.msgstr))
    for entry in sorted(polib.pofile(po2_fn), key=lambda obj: obj.msgid):
        po2_lines.append((
            u'msgid {}\n\n'
            u'msgstr {}\n\n'
        ).format(entry.msgid, entry.msgstr))
    added = removed = 0
    for diff_line in difflib.unified_diff(po1_lines, po2_lines):
        if diff_line.startswith('+++ ') or diff_line.startswith('--- ') or diff_line.startswith('@@ '):
            continue
        if diff_line.startswith('+'):
            added += 1
        elif diff_line.startswith('-'):
            removed += 1
    return added + removed
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号