How to use internationalization in chameleon with pyramid web framework?
-
05-06-2021 - |
Question
I have done the following:
- Change
pyramid.default_locale_name = en
tode
in development.ini My
index.pt
looks like this:<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>
I have made changes to the setup.py
message_extractors = { '.': [ ('**.py', 'lingua_python', None ), ('**.pt', 'lingua_xml', None ), ]}
When I run
python setup.py extract_messages
andpython setup.py update_catalog
mylocale/de/LC_MESSAGES/mvc.po
gets all the strings. After translation it becomes# 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"
Ignore the English as I have not done any actual translation. I want to check if it works.
I did
python setup.py compie_catalog
and mvc.mo file is createdBut when I load the page I am getting the same page without translations getting picked up. The locale seems to have set properly as I can see from the view
@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)}
I have even added
config.add_translation_dirs('mvc:locale')
to my init.py
What am I doing wrong? Or am I doing anything right at all?
Solution
Did you configure the translation domain for your translations?
http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/i18n.html#translation-domains