一个用于i18ndude的帮助器/包装器脚本,可以更轻松地在公共plone环境中处理翻译文件。
zettwerk.i18nduder的Python项目详细描述
简介
向plone产品添加翻译的任务或多或少总是相同的:
- 创建和注册locales目录
- 添加语言
- 使用rebuild pot命令调用i18ndude
- 使用sync命令调用i18ndude
- 将最后两个命令与find untranslated一起运行几次
- 也可以直接编译MO文件
zettwerk.i18nduder试图通过包装i18ndude命令来简化这个过程,并通过直接从buildout主文件夹调用它来避免文件夹和路径处理。它什么也没有,你不能直接使用i18ndude,但是在我们的内部使用中,它使翻译工作变得更容易和更快。
要实现这一点,只有一个假设,这在粘贴器创建的plone产品中应该很常见:您的翻译域与您的python包同名。
安装
在buildout.cfg中放入一个I18ndder部分,并按如下方式定义:
[i18nduder] recipe = zc.recipe.egg eggs = ${instance:eggs} zettwerk.i18nduder
重要的是要包含你的实例鸡蛋,因为duder通过导入它来获得包的路径。还要注意,zettwerk.i18nduder包含对i18ndude的依赖。
可用的命令和用法
生成的脚本称为duder。要查看命令列表,请使用–help参数:
> ./bin/duder --help > Usage: duder command -p package.name or --help for details > > Available commands: > create Create the locales folder and/or add given languages > update Call rebuild-pot and sync > mo Call msgfmt to build the mo files > find Find untranslated strings (domain independent) > > Options: > -h, --help show this help message and exit > -p PACKAGE, --package=PACKAGE > Name of the package > -d DOMAIN, --domain=DOMAIN > Name of the i18n domain. Only needed if it is different > from the package name. > -l LANGUAGES, --languages=LANGUAGES > List of comma-separated names of language strings. > Only used for create command. For example: -l en,de
示例
以下命令用于新创建的,并用包名dummy注册到buildout原型产品中的命令。例如
首先,我们创建locales文件夹并添加一些语言:
> ./bin/duder create -p dummy.example -l en,de > Created locales folder at: /home/joerg/Instances/Plone4/src/dummy.example/dummy/example/locales > Don't forget to add this to your configure.zcml: > <i18n:registerTranslations directory="locales" / > > - en language added > - de language added
要添加另一种语言,请再次调用:
> ./bin/duder create -p dummy.example -l nl > Locales folder already exists at: /home/joerg/Instances/Plone4/src/dummy.example/dummy/example/locales > - nl language added
在使用dummy.exmaple之后,必须完成一些翻译:
> ./bin/duder update -p dummy.example > nl/LC_MESSAGES/dummy.example.po: 1 added, 0 removed > en/LC_MESSAGES/dummy.example.po: 1 added, 0 removed > de/LC_MESSAGES/dummy.example.po: 1 added, 0 removed
注意,pot/po头不是用这个操作的。这必须手工完成。
查找未翻译的内容也可用:
> ./bin/duder find -p dummy.example > wrote output to: /home/joerg/Instances/Plone4/dummy.example-untranslated
MO文件可以这样编译:
> ./bin/duder mo -p dummy.example
这称为“msgfmt”,因此它必须在您的系统上可用。
有关域的说明
到目前为止,I18ndude可能还不错,它不能通过MessageFactory来区分域。因此,如果使用domain选项运行duder,则会得到给定域的msgid(当在i18n:domain的模板文件中显式使用时)和翻译,这些翻译是通过默认域的messagefactory创建的。
请随时与我们联系,寻求建议和改进。
更改日志
0.2.1(2011-04-05)
- 在更新调用后添加了完整路径输出
0.2(2011-04-03)
- 添加了-d选项以添加显式域名
- 重构命令
- PEP8清理
0.1(2010-11-13)
- 带有以下命令的初始版本:create、update、find、mo