我已经尝试将i18n功能添加到当前项目中。
requires = [
...
+ 'Babel',
+ 'lingua',
]
setup(name='myproject.app.product',
...
+ message_extractors = { '.': [
+ ('**.py', 'lingua_python', None ),
+ ('**.pt', 'lingua_xml', None ),
+ ('src/myproject/app/product/**/templates/**.html', 'mako', None ),
+ ('src/myproject/app/product/**/templates/**.mako', 'mako', None ),
+ ('src/myproject/app/product/**/static/**', 'ignore', None ),
+ ]},
}
)
[compile_catalog]
directory = src/myproject/app/product/locale
domain = product
statistics = true
[extract_messages]
add_comments = TRANSLATORS:
output_file = src/myproject/app/product/locale/product.pot
width = 80
[init_catalog]
domain = product
input_file = src/myproject/app/product/locale/product.pot
output_dir = src/myproject/app/product/locale
[update_catalog]
domain = product
input_file = src/myproject/app/product/locale/product.pot
output_dir = src/myproject/app/product/locale
previous = true
config.add_translation_dirs('myproject.app.product:locale')
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="product">
<h2 i18n:translate="search_documentation">Search documentation</h2>
pyramid.default_locale_name = en
...
msgid "search_documentation"
msgstr "Search Documentation"
最后,我编译了翻译的.po文件并启动了项目以查看该布局页面。它显示Search documentation
但不显示Search Documentation
。这意味着i18n设置不起作用。
问题出在哪里?如何配置?