Skip to main content

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

项目描述

我18ndude

<nav class="contents" id="contents">

内容

</nav>

介绍

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

GitHub 操作徽章

兼容性

i18ndude 适用于 Python 2.7、3.6、3.7、pypy 和 pypy3。不再支持旧版本,如果需要,请使用 i18ndude 4.x 系列。

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

UnicodeEncodeError

运行一些i18ndude命令时,您可能会收到UnicodeEncodeError。当i18ndude打印结果并且您重定向输出或管道时,尤其会发生这种情况。这很棘手,也许不可能在i18ndude本身中解决。请参阅有关stackoverflow的相关问题。这个问题指向一个解决方案,当你遇到这个问题时你自己可以做。在(类 Unix)shell 中,执行以下操作:

export PYTHONIOENCODING=utf-8

这在管道或重定向包含非 ascii 的输出时修复了 UnicodeEncodeErrors。我(Maurits)现在在我的 bash 个人资料中有这一行。

注意:如果你得到一个UnicodeDecodeError,所以 'decode' 而不是 'encode',那么它可能需要在i18ndude中修复。到时请报告

命令行界面

这些是各种命令行选项。

我18ndude

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.

optional arguments:
  -h, --help            show this help message and exit

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

查找未翻译

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

optional arguments:
  -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.

重建锅

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

optional arguments:
  -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

合并

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.


optional arguments:
  -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

同步

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

optional arguments:
  -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

筛选

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

optional arguments:
  -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.

混合

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

optional arguments:
  -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.

列表

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.


optional arguments:
  -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

合并

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

optional arguments:
  -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.

变更日志

5.5.0 (2022-09-19)

新的功能:

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

5.4.2 (2022-05-05)

Bug修复:

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

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

5.4.1 (2021-08-30)

Bug修复:

  • 支持来自 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"现在也接受要排除的目录名称。排除目录名称将排除给定目录中和下面的所有文件,但前提是目录名称与排除名称完全匹配(没有 glob,没有子字符串匹配)。现在,此更改还导致“测试”和“文档”的硬编码排除项实际起作用。(#86)

Bug修复:

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

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

  • 当内容为 None 时不要引发 AttributeError。(#84)

5.3.4 (2020-06-29)

Bug修复:

  • 当翻译为 99% 时,list 命令错误地显示 100% 已翻译。[长春黄酮] (#81)

5.3.3 (2020-04-22)

Bug修复:

  • 放弃对 3.4 和 3.5 的支持,我们一年以来都没有测试过。测试我们的 3.8 支持。[maurits] (#79)

5.3.2 (2020-02-25)

Bug修复:

  • 在 Python 文件中不需要的域的重建罐帮助中添加了提示。[maurits] (#49)

  • 修复了 Python 3.7 上的过滤器命令,可能更早。[maurits] (#75)

5.3.1 (2019-07-30)

Bug修复:

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

5.3.0 (2019-02-07)

新的功能:

  • 将 buildout 替换为 pip 以设置测试环境。不再在 Python 3.4 和 3.5 上进行测试。在 3.7 上进行测试。当前测试矩阵:2.7、3.6、3.7、pypy、pypy3。[maurits] (#66)

Bug修复:

  • 当没有给出参数时,显示帮助。这修复了在不带参数的情况下调用 'bin/i18ndude' 时某些 Python 版本上的错误。[maurits] (#68)

5.2.0 (2018-11-09)

新的功能:

  • 添加对所有元素的未翻译 aria-label 属性的检查。[詹贾普德里森]

Bug修复:

  • 修复了 plone.i18n导入。更改列表中的语言名称是有条件的导入,所以没什么大不了的。但它总是失败。[毛里求斯]

  • 在自述文件中,建议export PYTHONIOENCODING=utf-8修复UnicodeEncodeErrors。(注意:不是UnicodeDecodeErrors。)修复问题 55。[毛里求斯]

5.1.0 (2018-03-23)

新的功能:

  • list命令中,仅显示具有现有 po 文件的语言,按百分比排序。一个新的--tiered选项在三层中以特定顺序使用语言的传统行为。[毛里求斯]

Bug修复:

  • 对我们从中提取消息的文件进行排序。在 Linux 上,它们已经排序,但在 Mac 上没有,导致测试失败。[毛里求斯]

  • 修复了 find-untranslated 中另一个可能的 UnicodeDecodeError。[毛里求斯]

  • find-untranslated不再抱怨带有变色龙语法的属性。带有title="${context/Description}"的 html 标记不再被标记为具有未翻译的标题标记。修复问题 53。[毛里求斯]

5.0.2 (2018-03-12)

  • 修复了 find-untranslated 中一些可能的 UnicodeDecodeErrors。修复问题 52。[毛里求斯]

5.0.1 (2018-03-05)

  • 创建通用 Python 轮子。[毛里求斯]

5.0.0 (2018-03-05)

重大变化:

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

新的功能:

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

Bug修复:

  • 完全删除了 ordereddict`argparse依赖项。[毛里求斯]

  • 修复了许多 unicode/string/bytes 处理问题。鉴于测试覆盖率仅为 63%,可能仍有一些未修复的问题需要查找。[gyst]

去做:

  • i18ndude/pygettext.py:159:DeprecationWarning:不推荐使用 imp 模块以支持 importlib。但这不会导致任何破损。

4.3 (2017-07-31)

新的:

  • 支持模板中的变色龙重复语法。修复问题 #36。[毛里求斯]

  • plone.i18n依赖项移至plone extra。这仅用于在list命令中获取语言名称。我们现在回退到使用po文件中的语言名称。修复问题 #44。[毛里求斯]

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 文件。这不会破坏现有行为。请记住在表达式周围使用引号。[劳拉兹,莫里茨]

4.0.1 (2015-12-03)

修复:

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

4.0.0 (2015-12-03)

新的:

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

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

  • 在 find-untranslated 命令中,首先尝试将模板解析为 xml,这对非 html 文件有好处。如果失败,请尝试在 lxml HTMLPaser 的帮助下将其解析为 html,它可以更好地处理 html5 代码。如果失败,请使用我们值得信赖的自制 common.prepare_xml函数,它将所有内容都视为旧 html。请注意,我们在这里仍然使用xml.sax作为核心解析器。问题 #15 [maurits]

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

  • 使用 lxml 而不是 xml.etree 或 elementtree 来解析 GenericSetup xml 文件。[毛里求斯]

3.4.5 (2015-11-05)

新的:

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

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

  • 支持变色龙属性 tal:switch 和 tal:case。修复问题 #24。[警报]

3.4.4 (2015-11-04)

修复:

  • 在tal:something标签中时正确检查tal:condition 。[毛里求斯]

  • find-untranslated 中只忽略tal:condition="nothing",而不是其他条件。修复问题 #16。[毛里求斯]

  • 改进了prepare_xml函数。这试图解决缺少通常样板的模板,例如 xmlns:i18n="http://xml.zope.org/namespaces/i18n"。但其中有一些愚蠢的错误。此参考问题 #16。[毛里求斯]

3.4.3 (2015-09-01)

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

3.4.2 (2015-07-16)

  • 使用 wrapAndQuoteString 修复编码错误。[主题]

  • 佩普8。[主题]

3.4.1 (2015-06-25)

  • 也作为 Python 轮子发布。[毛里求斯]

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

3.4.0 (2014-11-27)

  • 放弃 Python 2.6 支持。它可能仍然有效,但测试只能在 Python 2.7 上运行。请注意,无论项目使用什么 Python 版本,都可以对所有项目使用一个中央 i18ndude 命令。[janjaapdriessen,莫里茨]

  • 对于查找未翻译的功能,通过在标签上设置“i18n:ignore”属性来添加标记要忽略的标签的可能性。也适用于具有“i18n:ignore-attributes”属性的属性。[詹贾普德里森]

3.3.5 (2014-08-05)

  • 避免 AttributeError:当.po文件在顶部附近缺少空 msgid 和 msgstr时,“NoneType”对象没有属性“comments” 。这是自动修复的,尽管它会覆盖一些标题。[毛里求斯]

3.3.4 (2014-07-02)

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

3.3.3 (2013-11-27)

  • 包管家。[哈维拉德]

3.3.2 (2013-11-27)

  • trmerge:当 mixin 翻译模糊时不要覆盖。[毛里求斯]

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

  • trmerge:添加--ignore-extra选项。这将忽略第二个 po 文件中的额外 msgid。[毛里求斯]

3.3.1 (2013-10-18)

  • 在某些情况下更新 script.py “arguments.exclude” 为 None。[贾科莫斯]

  • 固定可选参数排除。[shylux]

3.3.0 (2013-10-13)

  • 将命令行文档添加到包的详细描述中。[毛里求斯]

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

  • 修复list命令也可以在语言环境结构中工作。[毛里求斯]

  • 修复合并命令中的错误,其中--merge选项也将用作--merge2选项的值,如果该选项本身未使用。这导致了不必要的警告。[毛里求斯]

  • 现在, rebuild-pot--create domain选项是可选的。如果没有给出,i18ndude 从给定的.pot 文件中读取域。它始终是可选的,但文档没有显示它并且它不起作用。[毛里求斯]

  • 更新命令行选项处理。您现在可以通过使用--help选项调用单个命令来获得帮助。[毛里求斯]

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

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

  • 当包含双引号时,反斜杠转义添加到 msgid。[台东]

  • 添加 trmerge 命令以合并 po 文件。为 transifex 量身定制。[do3cc]

3.2.2 (2010-12-11)

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

3.2.1 (2010-10-31)

  • 修复了默认为双字节字符串制作 POT 文件的问题。[泰拉皮翁]

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)

  • 只有 Python < 2.5 才需要 elementtree。[长春花素]

  • 固定测试(John Trammell 提供的补丁)。[长春花素]

3.1.1 (2009-11-22)

  • 在注释的路径名中只删除一次“src”。示例:在它生成以下注释“#:archetypes.referencebrowserwidget/”之前,它并不是那么有用。现在它生成“archetypes.referencebrowserwidget/src/archetypes/referencebrowserwidget/...” [vincentfretin]

3.1 (2009-10-31)

  • 支持 GSReader 中的显式 msgid。[长春花素]

  • 更好地处理 msgid 引用。将所有引用保存在 PTReader 和 PYReader 中。在 POWriter 中,对引用进行规范化和排序,只写入 MAX_OCCUR(默认为 3)引用。如果要将所有引用写入生成的 POT 文件,可以设置 MAX_OCCUR=None。如果多次引用同一文件但行号不同,则仅写入第一个引用。[长春花素]

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

  • 修复处理要解析的损坏的 xml 文件时的行为。[AFD]

3.0 (2008-11-13)

  • 没有变化。[汉诺施]

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