kar*_*njo 1 python localization mako pyramid
我需要本地化我的金字塔应用程序,但我有一个问题。该setup.py文件包含以下message_extractors变量:
message_extractors = { '.': [
('templates/**.html', 'mako', None),
('templates/**.mako', 'mako', None),
('static/**', 'ignore', None)
]},
Run Code Online (Sandbox Code Playgroud)
我已经创建了目录my_package_name/locale。在__init__.py我添加config.add_translation_dirs('my_package_name:locale').
但是,当我跑
(my_virtual_env): python setup.py extract_messages
我收到消息
running extract_messages
error: no output file specified`
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,extract_messages在这种情况下不需要 --output-file 参数。
这种行为的原因是什么?
您还需要与 setup.py 位于同一目录中的 setup.cfg,大致包含以下内容:
[compile_catalog]
directory = YOURPROJECT/locale
domain = YOURPROJECT
statistics = true
[extract_messages]
add_comments = TRANSLATORS:
output_file = YOURPROJECT/locale/YOURPROJECT.pot
width = 80
[init_catalog]
domain = YOURPROJECT
input_file = YOURPROJECT/locale/YOURPROJECT.pot
output_dir = YOURPROJECT/locale
[update_catalog]
domain = YOURPROJECT
input_file = YOURPROJECT/locale/YOURPROJECT.pot
output_dir = YOURPROJECT/locale
previous = true
Run Code Online (Sandbox Code Playgroud)
当然,您将用您的项目名称替换 YOURPROJECT。我认为 setup.cfg 文件曾经是金字塔 1.5 之前项目的一部分,但现在金字塔使用 lingua 和 gettext 而不是 babel 它不再需要了。如果您遵循当前的金字塔文档,您可能会更好:http : //pyramid.readthedocs.org/en/latest/narr/i18n.html