如何将i18n功能添加到大型金字塔项目中?

时间:2016-01-19 01:30:41

标签: python internationalization pyramid

我已经尝试将i18n功能添加到当前项目中。

将包添加到myproject / product / setup.py

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 ),
+          ]},
}
)

将配置添加到myproject / product / setup.cfg

[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

将add_translation_dirs添加到myproject / product / src / myproject / app / product / init .py

config.add_translation_dirs('myproject.app.product:locale')

更改html信息并将测试输出消息添加到布局文件:myproject / product / src / myproject / app / product / show / templates / pc / layout.html

<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>

将default_locale_name添加到application.ini

pyramid.default_locale_name = en

将测试消息添加到.po文件:myproject / product / src / myproject / app / product / locale / en / LC_MESSAGES / product.po

...
msgid "search_documentation"
msgstr "Search Documentation"

最后,我编译了翻译的.po文件并启动了项目以查看该布局页面。它显示Search documentation但不显示Search Documentation。这意味着i18n设置不起作用。

问题出在哪里?如何配置?

0 个答案:

没有答案