1
我也做了以下內容:如何在金字塔web框架中使用變色龍國際化?
- 變化
pyramid.default_locale_name = en
到de
在development.ini 我
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>
我已經修改了setup.py
message_extractors = { '.': [ ('**.py', 'lingua_python', None), ('**.pt', 'lingua_xml', None), ]}
當我運行
python setup.py extract_messages
和python 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 protected]>, 2012. # msgid "" msgstr "" "Project-Id-Version: mvc 0.0\n" "Report-Msgid-Bugs-To: [email protected]\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 protected]>\n" "Language-Team: de <[email protected]>\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"
忽略英文,因爲我沒有做任何實際的翻譯。我想檢查它是否有效。
我做
python setup.py compie_catalog
和mvc.mo文件被創建但是,當我打開我收到同一頁的頁面沒有翻譯得到回升。該區域似乎已經正確設置,我可以從視圖
@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)}
我甚至已經添加
config.add_translation_dirs('mvc:locale')
我初始化的.py
我在做什麼錯看?或者我做什麼都對嗎?