删除 PO 文件的所有模糊条目

发布于 2024-12-04 02:18:51 字数 105 浏览 0 评论 0原文

有谁知道从 PO 文件中批量删除所有模糊翻译的方法。类似于:

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是偏爱你 2024-12-11 02:18:52

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

您可以使用 polib 删除模糊字符串,这 脚本删除模糊翻译字符串+模糊标志,但保持未翻译的原始 msgids 完整。有些语言(ru、cz、...)有两个以上的复数形式,因此,我们检查 msgstr_plural[2]。对于旧版本的 polib,msgstr_plural 的索引是一个字符串,因此这将变为 msgstr_plural['2']

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

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]. With older versions of polib, the index to msgstr_plural is a string, so this would become msgstr_plural['2'].

对岸观火 2024-12-11 02:18:52

如果您安装了 GNU gettext,那么您可以使用此命令来删除模糊消息:

msgattrib --no-fuzzy -o 路径/到/您的/输出/po/文件 路径/到/您的/输入/po/文件

If you have GNU gettext installed then you can use this command to remove fuzzy messages:

msgattrib --no-fuzzy -o path/to/your/output/po/file path/to/your/input/po/file

晒暮凉 2024-12-11 02:18:51

如果安装了 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-Inspiration.html

If gettext is installed you can use the msgattrib command to accomplish this:

msgattrib --clear-fuzzy --empty -o /path/to/output.po /path/to/input.po

The full documentation for msgattrib is here:

https://www.gnu.org/software/gettext/manual/html_node/msgattrib-Invocation.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文