【问题标题】:How to use internationalization in chameleon with pyramid web framework?如何在带有金字塔网络框架的变色龙中使用国际化?
【发布时间】:2012-05-02 07:19:23
【问题描述】:

我做了以下事情:

  1. 在 development.ini 中将 pyramid.default_locale_name = en 更改为 de
  2. 我的index.pt 看起来像这样:

    <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="mvc">
    <a href="/user/login/form" i18n:translate="">Login Page</a><br />
    <a href="/user/register/form" i18n:translate="">Register Page</a><br />
    <a href="/ds/landing/view" i18n:translate="">Datasource landing page</a> <br />
    <p>${locale_name}</p>
    
  3. 我已对 setup.py 进行了更改

    message_extractors = { '.': [
    ('**.py',   'lingua_python', None ),
    ('**.pt',   'lingua_xml', None ),
    ]}
    
  4. 当我运行python setup.py extract_messagespython setup.py update_catalog 时,我的locale/de/LC_MESSAGES/mvc.po 得到所有字符串。翻译后就变成了

    # German translations for mvc.
    # Copyright (C) 2012 ORGANIZATION
    # This file is distributed under the same license as the mvc project.
    # FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
    #
    msgid ""
    msgstr ""
    "Project-Id-Version: mvc 0.0\n"
    "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
    "POT-Creation-Date: 2012-05-02 12:24+0530\n"
    "PO-Revision-Date: 2012-05-02 11:38+0530\n"
    "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    "Language-Team: de <LL@li.org>\n"
    "Plural-Forms: nplurals=2; plural=(n != 1)\n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=utf-8\n"
    "Content-Transfer-Encoding: 8bit\n"
    "Generated-By: Babel 0.9.6\n"
    
    #: mvc/templates/index.pt:2
    msgid "Login Page"
    msgstr "sign in page"
    
    #: mvc/templates/index.pt:3
    #, fuzzy
    msgid "Register Page"
    msgstr "register in this Page"
    
    #: mvc/templates/index.pt:4
    msgid "Datasource landing page"
    msgstr "Landing Page of datasources"
    

    忽略英文,因为我没有做任何实际的翻译。我想检查它是否有效。

  5. 我做了python setup.py compie_catalog 并创建了 mvc.mo 文件

  6. 但是当我加载页面时,我得到的是相同的页面,但没有翻译。从视图中可以看出,语言环境似乎已正确设置

    @view_config(route_name='home',renderer='templates/index.pt')
    def index_view(request):
        from pyramid.i18n import negotiate_locale_name
    
        return {'locale_name' : negotiate_locale_name(request)}
    
  7. 我什至在我的 init.py

  8. 中添加了config.add_translation_dirs('mvc:locale')

我做错了什么?还是我做对了?

【问题讨论】:

    标签: python internationalization pyramid chameleon


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2013-07-14
    • 1970-01-01
    相关资源
    最近更新 更多