Running into an issue with i18n that I'm reasonably sure is something
simple I'm missing. extract_messages finds the phrases from the html,
update_catalog, modify the .po file, compile_catalog, hit a few test
URLs and the .mo file is used only for translations in the
controllers.
Relevant details:
Turbogears 1.9.7a3
Babel-0.9.3-py2.5.egg
Genshi-0.5.1-py2.5-linux-i686.egg
Mako-0.2.2-py2.5.egg
Pylons-0.9.7rc1-py2.5.egg
Followed the instructions on
http://www.turbogears.org/2.0/docs/main/Internationalization.html
Made one minor change to setup.py uncommenting:
message_extractors = {'cptest': [
('**.py', 'python', None),
('templates/**.mak', 'mako', None),
('templates/**.html', 'genshi', None),
('public/**', 'ignore', None)]},
(also fixed the extension for mako which defaults to .mako, while TG2
looks for .mak)
$ python setup.py extract_messages
...
extracting messages from cptest/templates/__init__.py
extracting messages from cptest/templates/about.html
extracting messages from cptest/templates/login.html
...
It does pull the messages from about.html
$ python setup.py update_catalog -l es
running update_catalog
updating catalog 'cptest/i18n/es/LC_MESSAGES/cptest.po' based on
'cptest/i18n/cptest.pot'
does properly list the messages
#: cptest/controllers/root.py:18
msgid "Homepage"
msgstr "página principal"
#: cptest/templates/about.html:14
msgid "Learning TurboGears 2.0: Quick guide to the Quickstart pages."
msgstr "spanish learning turbogears 2.0 quick guide"
$ python setup.py compile_catalog
running compile_catalog
2 of 95 messages (2%) translated in 'cptest/i18n/es/LC_MESSAGES/
cptest.po'
compiling catalog 'cptest/i18n/es/LC_MESSAGES/cptest.po' to 'cptest/
i18n/es/LC_MESSAGES/cptest.mo'
compile_catalog does recognize the messages
from development.ini:
[app:main]
lang = es
I've also set my browser to prefer Spanish (es)
from root.py
@expose('cptest.templates.index')
def index(self):
return dict(page=_('Homepage'))
This does work and the page properly displays:
Now Viewing: página principal
So, i18n works to this point. Phrases translated within controllers
using _() notation translate properly. Even removing lang=es from
development.ini works properly with my browser set to prefer Spanish
(es). However, translations within the page do not work.
Even a simple change to the login.html is not reflected in the
rendered version, but, it does appear to be properly inserted in
the .mo file. pybabel does appear to have a few problems parsing the
genshi templates due to some of the nesting and xhtml markup, but, it
appears to have not had any problems with the login.html template
which is why I tried it first. While extract_messages appears to scan
the .mak template file, I was unable to get pybabel to catalog the
text portions from it.
As far as I can tell, TG2 does appear to pass everything through
pylons which passes it through the i18n translator. The filter does
appear to be installed in the pylons filter path. Have I missed
something, or is i18n broken?