跳转到主要内容

i18ndude执行与ZPT、Python脚本和国际化相关的各种任务。

项目描述

i18ndude

简介

i18ndude 执行与 ZPT、Python 脚本和 i18n 相关的各种任务。

GitHub Actions badge

兼容性

i18ndude 与 Python 3.8-3.11 和 PyPy3 兼容。旧版本不再受支持,如果需要,请使用 i18ndude 5.x 系列。

您可以使用 Buildout 或 pip 安装 i18ndude。使用 pip 时,您可能需要查看我们的 requirements.txt

UnicodeEncodeError

运行某些 i18ndude 命令时,您可能会遇到 UnicodeEncodeError。这特别可能发生在 i18ndude 打印结果并重定向输出或管道输出时。这在 i18ndude 本身中可能是棘手甚至无法解决的。请参阅此相关的 stackoverflow 问题。这个问题指向了一个当您遇到这种情况时可以自己执行的解决方案。在 (Unix-like) shell 中,执行以下操作:

export PYTHONIOENCODING=utf-8

这可以修复包含非 ascii 字符的输出管道或重定向时的 UnicodeEncodeErrors。我现在在我的 bash 配置文件中有这一行。

注意:如果您遇到 UnicodeDecodeError,那么 'decode' 而不是 'encode',那么这可能是在 i18ndude 中需要修复的某些内容。请 报告 它。

提交前钩子

从版本 6 开始,我们有一个 pre-commit 钩子可用

-   repo: https://github.com/collective/i18ndude
    rev: "master"
    hooks:
    -   id: i18ndude

目前它只找到未标记为翻译的字符串。

命令行界面

这些是各种命令行选项。

i18ndude

usage: i18ndude [-h]
                {find-untranslated,rebuild-pot,merge,sync,filter,admix,list,trmerge}
                ...

i18ndude performs various tasks related to ZPT's, Python Scripts
and i18n.

Its main task is to extract translation strings (msgids) into a
.pot file (with the 'rebuild-pot' command), and sync the .pot file
with .po files (with the 'sync' command).

Call i18ndude with one of the listed subcommands followed by
--help to get help for that subcommand.

options:
  -h, --help            show this help message and exit

subcommands:
  {find-untranslated,rebuild-pot,merge,sync,filter,admix,list,trmerge}

find-untranslated

usage: i18ndude find-untranslated [-h] [-s] [-n] [files ...]

    Provide a list of ZPT filenames and I will output a report of places
    where I suspect untranslated messages, i.e. tags for which
    "i18n:translate" or "i18n:attributes" are missing.

    If you provide the -s option, the report will only contain a summary
    of errors and warnings for each file (or no output if there are no
    errors or warnings). If you provide the -n option, the report will
    contain only the errors for each file.

    You can mark tags to be ignored for this translation check by
    setting the "i18n:ignore" attribute on the tag. Same for
    attributes with "i18n:ignore-attributes". Note that i18ndude may
    be happy with this, but your template engine may fail when trying
    to render a template containing those ignore hints.  You need
    Chameleon 2.23 or higher, or the to be released zope.tal 4.1.2.


positional arguments:
  files            list of ZPT filenames

options:
  -h, --help       show this help message and exit
  -s, --silent     The report will only contain a summary of errors and
                   warnings for each file (or no output if there are no errors
                   or warnings).
  -n, --nosummary  The report will contain only the errors for each file.

rebuild-pot

usage: i18ndude rebuild-pot [-h] [--wrap | --no-wrap] [--width NUMBER] -p
                            filename [-c domain] [-m filename]
                            [--merge2 filename]
                            [--exclude "<ignore1> <ignore2> ..."]
                            [--no-line-numbers] [--line-numbers]
                            [path ...]

    Given a pot-file via the --pot option you can specify one or more
    directories which including all sub-folders will be searched for
    PageTemplates (*.*pt) and Python scripts (*.*py).

    Make sure you have a backup copy of the original pot-file in case
    you need to fill back in ids by hand.

    If you specify a domain in --create I will create the pot file and
    look for messages for that domain.  Otherwise I will take the
    domain from the Domain header in the given pot file and keep the
    headers from the file as base for a new pot file.

    Note that in Python files we simply look for text within an underscore
    method: _("...").  We do not know which domain this is.
    If this finds text from a domain that you do not want to find,
    you should give the underscore method for the unwanted domain
    a different name, for example:

      from zope.i18nmessageid import MessageFactory
      PMF = MessageFactory("plone")
      PMF("...")

    If you give me an additional pot-file with the --merge <filename>
    option, I try to merge these msgids into the target-pot file
    afterwards. If a msgid already exists in the ones I found in the
    ZPTs, I'll warn you and ignore that msgid. I take the mime-header
    from this additional pot-file. If you provide a second pot-file via
    --merge2 <filename> I'll merge this into the first merge's result

    You can also provide a list of filenames (or regular expressions for
    filenames) which should not be included by using the --exclude argument,
    which takes a whitespace delimited list of files (or regular expressions
    for files).

    By default we add a comment showing references to file paths and line numbers
    that contain the message, like this:

        #: ./browser.py:32

    You can suppress the line numbers by using the --no-line-numbers option.
    The default might change in the future.  If you love line numbers, you can
    add --line-numbers to be sure you keep them when you get a newer version
    of i18ndude.  If you specify both options, the last one wins.


positional arguments:
  path

options:
  -h, --help            show this help message and exit
  --wrap                Wrap long lines.
  --no-wrap             Do not wrap long lines. This is the default.
  --width NUMBER        Set output page width. Default is 79.
  -p filename, --pot filename
  -c domain, --create domain
  -m filename, --merge filename
  --merge2 filename
  --exclude "<ignore1> <ignore2> ..."
  --no-line-numbers
  --line-numbers

merge

usage: i18ndude merge [-h] [--wrap | --no-wrap] [--width NUMBER] -p filename
                      -m filename [--merge2 filename]

    Given a pot-file via the --pot option and a second
    pot-file with the --merge <filename> option, I try to merge
    these msgids into the target-pot file. If a msgid already
    exists, I'll warn you and ignore that msgid.

    If you provide a --merge2 <filename> I'll first merge this one
    in addition to the first one.


options:
  -h, --help            show this help message and exit
  --wrap                Wrap long lines.
  --no-wrap             Do not wrap long lines. This is the default.
  --width NUMBER        Set output page width. Default is 79.
  -p filename, --pot filename
  -m filename, --merge filename
  --merge2 filename

sync

usage: i18ndude sync [-h] [--wrap | --no-wrap] [--width NUMBER] -p potfilename
                     pofilename [pofilename ...]

    Given a pot-file with the --pot option and a list of po-files I'll
    remove from the po files those message translations of which the
    msgids are not in the pot-file and add messages that the pot-file has
    but the po-file doesn't.


positional arguments:
  pofilename

options:
  -h, --help            show this help message and exit
  --wrap                Wrap long lines.
  --no-wrap             Do not wrap long lines. This is the default.
  --width NUMBER        Set output page width. Default is 79.
  -p potfilename, --pot potfilename

filter

usage: i18ndude filter [-h] [--wrap | --no-wrap] [--width NUMBER] file1 file2

    Given two pot-files I will write a copy of file1 to stdout with all
    messages removed that are also in file2, i.e. where msgids match.


positional arguments:
  file1
  file2

options:
  -h, --help      show this help message and exit
  --wrap          Wrap long lines.
  --no-wrap       Do not wrap long lines. This is the default.
  --width NUMBER  Set output page width. Default is 79.

admix

usage: i18ndude admix [-h] [--wrap | --no-wrap] [--width NUMBER] file1 file2

    Given two po-files I will look for translated entries in file2 that
    are untranslated in file1. I add these translations (msgstrs) to
    file1. Note that this will not affect the number of entries in file1.
    The result will be on stdout.


positional arguments:
  file1
  file2

options:
  -h, --help      show this help message and exit
  --wrap          Wrap long lines.
  --no-wrap       Do not wrap long lines. This is the default.
  --width NUMBER  Set output page width. Default is 79.

list

usage: i18ndude list [-h] -p product [product ...] [-t] [--tiered]

    This will create a simple listing that displays how much of the
    combined products pot's is translated for each language. Run this
    from the directory containing the pot-files. The product name is
    normally a domain name.

    By default we show the languages of existing po files,
    ordered by percentage.

    With the --tiered option, we split the languages in three tiers or groups,
    the first two with languages that Plone was traditionally translated in,
    in a hardcoded order, followed by other languages.
    This was the default output for years.


options:
  -h, --help            show this help message and exit
  -p product [product ...], --products product [product ...]
  -t, --table           Output as html table
  --tiered              Show in traditional three-tiered order

trmerge

usage: i18ndude trmerge [-h] [--wrap | --no-wrap] [--width NUMBER] [-i]
                        [--no-override]
                        file1 file2

    Given two po-files I will update all translations from file2 into
    file1. Missing translations are added.

    If a translation was fuzzy in file1, and there is a nonempty translation
    in file2, the fuzzy marker is removed.

    Fuzzy translations in file2 are ignored.

    The result will be on stdout.  If you want to update the first
    file in place, use a temporary file, something like this:

      i18ndude trmerge file1.po file2.po > tmp_merge && mv tmp_merge file1.po


positional arguments:
  file1
  file2

options:
  -h, --help          show this help message and exit
  --wrap              Wrap long lines.
  --no-wrap           Do not wrap long lines. This is the default.
  --width NUMBER      Set output page width. Default is 79.
  -i, --ignore-extra  Ignore extra messages: do not add msgids that are not in
                      the original po-file. Only update translations for
                      existing msgids.
  --no-override       Do not override translations, only add missing
                      translations.

变更日志

6.2.1 (2024-07-30)

错误修复

  • 删除使用 setuptools 运行测试的旧方法 [gforcada] (#114)

6.2.0 (2024-04-22)

新功能

  • 添加对 python 3.12 的支持。 [pbauer] (#113)

6.1.0 (2023-07-18)

新功能

  • 让 i18n:ignore 忽略其作用域内的所有可翻译字符串。 (#109)

错误修复

  • 删除 Python 2 支持代码。使用 pyupgrade、isort、black、flake8。 [maurits] (#23)

6.0.0 (2023-05-30)

错误修复

  • 修复 pre-commit 集成。 [gforcada] (#1)

6.0.0a1 (2023-05-08)

重大更改

  • 停止支持 Python 2。需要 Python 3.8+(也支持 PyPy3)。 [gforcada, maurits] (#50)

新功能

  • 添加 pre-commit 钩子,目前只用于查找未标记为翻译的字符串。 [gforcada] (#50)

错误修复

  • 修复 prepare_cli_documentation 命令的编码问题。 [gforcada] (#101)

5.5.0 (2022-09-19)

新功能

  • rebuild-pot 添加布尔选项 --no-line-numbers。使用此选项以防止在 pot 文件中包含行号。默认情况下仍然包含它们,因此没有行为更改。默认值可能在将来更改。如果您想确保在将来保留行号,请使用新的 --line-numbers 选项。 [maurits] (#77)

5.4.2 (2022-05-05)

错误修复

  • 注释中的前导空格保持稳定。 (#91)

  • 在 Python 3.10 上进行测试。不需要代码更改。 [maurits] (#310)

5.4.1 (2021-08-30)

错误修复

  • 支持 Chameleon 的定义语法。这是用于解包语法的,例如 tal:define="(text,url) python:view.linkinfo"。这避免了从使用此语法的模板中提取消息时出现 TALError: invalid define syntax。 [maurits] (#36)

5.4.0 (2021-05-28)

新功能

  • i18ndude rebuild-pot --exclude="name1 name2" 现在也接受排除目录名。排除目录名将排除指定目录及其下所有文件,但前提是目录名与排除名称完全匹配(不支持通配符,不支持子字符串匹配)。此更改现在还使得对“tests”和“docs”的硬编码排除实际上生效。 (#86)

错误修复

  • 使用 GitHub Actions 而不是 Travis CI 进行测试。[maurits] (#83)

  • 支持 Python 3.9。无需代码更改。[maurits] (#83)

  • 当内容为 None 时,不要引发 AttributeError。[#84]

5.3.4 (2020-06-29)

错误修复

  • 当翻译完成度为 99% 时,列表命令错误地显示为 100% 翻译。[vincentfretin] (#81)

5.3.3 (2020-04-22)

错误修复

  • 放弃 3.4 和 3.5 支持,因为我们已经一年没有测试这些版本了。测试我们的 3.8 支持。[maurits] (#79)

5.3.2 (2020-02-25)

错误修复

  • rebuild-pot 的帮助中添加了有关 Python 文件中不希望存在的域的提示。[maurits] (#49)

  • 修复了 Python 3.7 上的过滤命令,可能也适用于更早的版本。[maurits] (#75)

5.3.1 (2019-07-30)

错误修复

  • 在运行 find-untranslated 代码分析时,不允许 i18n:name 属性中使用非单词字符(但允许使用破折号)。[gyst] (#71)

5.3.0 (2019-02-07)

新功能

  • 使用 pip 而不是 buildout 来设置测试环境。不再在 Python 3.4 和 3.5 上进行测试。在 3.7 上进行测试。当前测试矩阵:2.7、3.6、3.7、pypy、pypy3。[maurits] (#66)

错误修复

  • 如果没有提供任何参数,则显示帮助信息。这修复了在某些 Python 版本上调用“bin/i18ndude”不带参数时出现的错误。[maurits] (#68)

5.2.0 (2018-11-09)

新功能

  • 添加了对所有元素上未翻译的 aria-label 属性的检查。[janjaapdriessen]

错误修复

  • 修复了 plone.i18n 的导入。这是一个条件导入,用于更改列表中语言名称,所以没有严重问题。但它总是失败。[maurits]

  • 在说明文档中建议使用 export PYTHONIOENCODING=utf-8 来修复 UnicodeEncodeErrors。注意:不是 UnicodeDecodeErrors。修复了 问题 55。[maurits]

5.1.0 (2018-03-23)

新功能

  • list 命令中,仅显示具有现有 po 文件的语种,按百分比排序。新的 --tiered 选项使用传统的行为,将语种分为三个层级进行排序。[maurits]

错误修复

  • 对从文件中提取消息的文件进行排序。在 Linux 上这些文件已经排序,但在 Mac 上没有,导致测试失败。[maurits]

  • 在 find-untranslated 中修复了另一个可能的 UnicodeDecodeError。[maurits]

  • find-untranslated 不再对具有 chameleon 语法的属性进行投诉。带有 title="${context/Description}" 的 html 标签不再被标记为有未翻译的标题标签。修复了 问题 53。[maurits]

5.0.2 (2018-03-12)

  • 在 find-untranslated 中修复了一些可能的 UnicodeDecodeError。[maurits]

5.0.1 (2018-03-05)

  • 创建通用 Python 轮。[maurits]

5.0.0 (2018-03-05)

重大更改

  • 放弃对 python 2.6 及更老版本的支持。保留 python2.7 支持。[gyst]

新功能

  • 支持 python 3.6、3.5、3.4、pypy 和 pypy3。[gyst]

错误修复

  • 完全移除了 ordereddict`argparse 依赖。[maurits]

  • 修复了许多 unicode/字符串/bytes 处理问题。考虑到测试覆盖率仅为 63%,可能还有一些未修复的问题需要寻找。[gyst]

待办事项

  • i18ndude/pygettext.py:159: DeprecationWarning: the imp module is deprecated in favour of importlib. This does not cause any breakage though.

4.3 (2017-07-31)

新增

  • 支持模板中的 Chameleon 重复语法。修复了 问题 #36。[maurits]

  • plone.i18n 依赖项移动到 plone 扩展中。这仅在 list 命令中用于获取语言名称。我们现在回退到使用 po 文件中的语言名称。修复了 问题 #44。[maurits]

4.2 (2017-06-21)

新增

  • find-untranslated 中,不要报告被 Chameleon 语法替换的项。因此,<span>${view/test}</span> 将不再被标记为缺少翻译。(注意,如果你觉得合适,仍然可以添加 i18n:translate,就像 Plone 那样翻译动态计算的评审状态。)[Netroxen, maurits]

  • 查找未翻译的属性现在也会检查输入标签上的“占位符”属性。

4.1 (2016-12-02)

新增

  • 允许使用正则表达式用于 -exclude 参数。例如,使用 *.py 来排除所有 Python 文件。这不会破坏现有行为。请记住在表达式中使用引号。[laulaz, maurits]

4.0.1 (2015-12-03)

修复

  • 修复了 find-untranslated 中报告的一些行号。修复了问题 #34。[maurits]

4.0.0 (2015-12-03)

新增

  • 从 zcml 中提取字符串。问题 #28 [maurits]

  • 不再在 .po 和 .pot 文件的末尾打印两个空行。[maurits]

  • 在 find-untranslated 命令中,首先尝试将模板解析为 XML,这对非 HTML 文件很有用。如果失败,尝试使用 lxml HTMLParser 解析 HTML,它会更好地处理 HTML5 代码。如果失败,则使用我们信任的本地 common.prepare_xml 函数,它将所有内容视为旧 HTML。请注意,我们仍然在这里使用 xml.sax 作为核心解析器。问题 #15 [maurits]

  • 在 find-untranslated 命令中忽略隐藏文件。问题 #29 [maurits]

  • 使用 lxml 而不是 xml.etree 或 elementtree 来解析 GenericSetup XML 文件。[maurits]

3.4.5 (2015-11-05)

新增

  • 首先尝试原始 zope.tal 解析器。只有当它失败时,我们才尝试自己的解析器/生成器。[maurits]

  • 支持 Chameleon 未命名属性而不会崩溃。例如: tal:attributes="python:{'data-something': 'chameleon-only'}" [maurits]

  • 支持 chameleon 属性 tal:switch 和 tal:case。修复了问题 #24。[ale-rt]

3.4.4 (2015-11-04)

修复

  • 当它在 tal:something 标签中时,正确检查 tal:condition。[maurits]

  • find-untranslated 中仅忽略 tal:condition="nothing",而不是其他条件。修复了问题 #16。[maurits]

  • 改进了 prepare_xml 函数。它试图解决缺少常用模板,如 xmlns:i18n="http://xml.zope.org/namespaces/i18n" 的模板。但其中有一些愚蠢的错误。这引用了问题 #16。[maurits]

3.4.3 (2015-09-01)

  • 修复 nosummary 选项从 find-untranslated。它报告了错误信息。[gforcada]

3.4.2 (2015-07-16)

  • 修复 wrapAndQuoteString 中的编码错误。[thet]

  • Pep8。[thet]

3.4.1 (2015-06-25)

  • 也作为 Python 轮子发布。[maurits]

  • 修复了字符串包含换行符时的包装问题。问题 #13 [maurits]

3.4.0 (2014-11-27)

  • 停止支持 Python 2.6。它可能仍然可以工作,但测试只在 Python 2.7 上运行。请注意,可以使用一个中央 i18ndude 命令来管理所有项目,无论它们使用的是哪种 Python 版本。[janjaapdriessen, maurits]

  • 对于 find-untranslated 功能,添加将标签标记为要忽略的可能性,通过在标签上设置“i18n:ignore”属性来实现。这也适用于具有“i18n:ignore-attributes”属性的属性。[janjaapdriessen]

3.3.5 (2014-08-05)

  • 避免在 .po 文件缺少顶部附近的空 msgid 和 msgstr 时出现 AttributeError: ‘NoneType’ object has no attribute ‘comments’。这会自动修复,尽管它将覆盖一些标题。[maurits]

3.3.4 (2014-07-02)

  • 正确包装第一行。修复 #9。[gforcada]

3.3.3 (2013-11-27)

  • 包维护。[hvelarde]

3.3.2 (2013-11-27)

  • trmerge:当混合翻译模糊时不要覆盖。[maurits]

  • trmerge:添加 --no-override 参数。这意味着:不要覆盖翻译,只添加缺失的翻译。[maurits]

  • trmerge:添加 --ignore-extra 选项。这会忽略第二个 po 文件中的额外 msgid。[maurits]

3.3.1 (2013-10-18)

  • 在某些情况下更新 script.py,“arguments.exclude” 为 None。[giacomos]

  • 修复可选参数 exclude。[shylux]

3.3.0 (2013-10-13)

  • 将命令行文档添加到包的长描述中。[maurits]

  • 添加选项 --wrap--no-wrap--width=NUMBER 到所有写入文件的命令中。使用这些选项来决定长行是否折叠以及折叠的宽度。默认宽度为 79。默认情况下我们不会折叠,因为我们以前从未折叠过。这可能会在未来改变,所以如果您 真的 想要确保在将来使用 i18ndude 的版本时不进行折叠,现在可以添加 --no-wraphttps://github.com/collective/i18ndude/issues/3 [maurits]

  • 修复 list 命令,使其也能在 locales 结构中工作。[maurits]

  • 修复了 merge 命令中的一个错误,其中如果未使用 --merge 选项,则该选项会被用作 --merge2 选项的值。这导致了不必要的警告。[maurits]

  • 现在 rebuild-pot--create domain 选项是可选的。如果没有提供,i18ndude 会从给定的 .pot 文件中读取域。它始终是可选的,但文档没有显示这一点,并且它不起作用。[maurits]

  • 更新命令行选项处理。现在您可以通过调用它们并带有 --help 选项来获取单个命令的帮助。[maurits]

  • 当被调用的函数产生错误时返回退出代码 1。这目前只在调用 find-untranslated 时有效。https://github.com/collective/i18ndude/issues/1 [maurits]

  • 将代码移动到 https://github.com/collective/i18ndude [maurits]

  • 在包含双引号时,添加了对 msgid 的反斜杠转义。[taito]

  • 添加 trmerge 命令以合并 po 文件。针对 transifex 定制。[do3cc]

3.2.2 (2010-12-11)

  • 将密钥编码为 utf-8,以避免 Merge-Warning 消息中的 UnicodeEncodeError。[mikerhodes]

3.2.1 (2010-10-31)

  • 修复了默认为双字节字符串创建 POT 文件的问题。[terapyon]

3.2 (2010-09-04)

  • 用 ordereddict 包替换内部 odict 实现。(从 Python 2.7 返回的实现)[vincentfretin]

3.1.3 (2010-09-04)

  • 在 add() 中打印警告消息时避免 UnicodeDecodeError。[rnix]

3.1.2 (2010-02-14)

  • elementtree 仅在 Python < 2.5 时需要。[vincentfretin]

  • 修复了测试(由 John Trammell 提供的补丁)。[vincentfretin]

3.1.1 (2009-11-22)

  • 在路径名中只去除一次“src”以进行注释。例如:之前它生成了以下注释“#: archetypes.referencebrowserwidget/”,这不是很有用。现在它生成“archetypes.referencebrowserwidget/src/archetypes/referencebrowserwidget/…” [vincentfretin]

3.1 (2009-10-31)

  • 支持 GSReader 中的显式 msgid。[vincentfretin]

  • 更好地处理 msgid 引用。在 PTReader 和 PYReader 中保留所有引用。在 POWriter 中,规范和排序引用,仅写入 MAX_OCCUR(默认为 3)引用。如果您想将所有引用写入生成的 POT 文件,可以将 MAX_OCCUR 设置为 None。在相同文件但行号不同的几个引用的情况下,仅写入第一个引用。[vincentfretin]

  • 现在依赖zope.tal 3.5.2来在消息ID在目录中已存在且默认消息不同时打印警告。简化PTReader代码。在GSReader、PYReader和合并的目录(ptctl、pyctl、gsctl)中检查具有不同默认值的msgid。[vincentfretin]

  • 修复处理需要解析的损坏XML文件时的行为。[afd]

3.0 (2008-11-13)

  • 没有更改。[hannosch]

对于较早的更改,请参阅docs/ChangeLog

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

i18ndude-6.2.1.tar.gz (88.0 kB 查看散列值)

上传时间 源代码

构建分发

i18ndude-6.2.1-py3-none-any.whl (76.1 kB 查看散列值)

上传时间 Python 3

支持