【问题标题】:How to deal with Internationalization when using mako on django ,在 django 上使用 mako 时如何处理国际化,
【发布时间】:2011-06-07 16:32:44
【问题描述】:

这是代码:

{% load i18n %}
{% trans 'hello test' %}

但是,mako 无法读取此代码,

那么如何使用 mako 进行国际化,

谢谢

【问题讨论】:

标签: python django internationalization mako


【解决方案1】:

我检查了documentation,它描述了 Mako 将Babel 用于 i18n。所以你可以使用它,或者像@Yuji 建议的那样,通过调用任意 Python 代码来使用 Django 的 i18n。

但我认为使用 Babel 更漂亮:

# /myproj/babel.cfg

# this loads all Django templates, 
# e.g. /myproj/templates/myapp/hello_world.html
[mako: **/templates/**.*]

# /myproj/templates/myapp/hello_world.html
<html>
   <body>
       ${_('Hello world!')}
   </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多