Turbogears i18n pains
The final problem I have run into with TurboGears is the poor documentation regarding i18n with Genshi templates. The only way I have been able to get gettext to work for this blog was by using sourcecode from Transifex. To get i18n to work with genshi templates, I added this to config/app.cfg:
session_filter.on = True i18n.run_template_filter = True i18n.domain = "cblog" i18n.locale_dir = "locales/" i18n.po_view_dir = "locales/view/" i18n.locale_dir = "locales/"
and this to controllers.py:
# i18n support from turbogears.i18n import gettext from genshi.filters import Translator import turbogears.view def genshi_loader_callback(template): template.filters.insert(0, Translator(gettext)) def init_callback(): turbogears.view.engines['genshi'].loader.callback = genshi_loader_callback turbogears.startup.call_on_startup.append( init_callback ) config.update({'genshi.loader_callback': genshi_loader_callback}) # i18n support - end
To create the translation files, I followed the instructions from the Genshi i18n page. First, I created a mappings.cfg file containing:
# Extraction from Python source files [python: **.py] # Extraction from Genshi HTML and text templates [genshi: **/templates/**.html]
And then ran:
pybabel extract -o locales/cblog.pot -F ./mappings.cfg cblog pybabel init -D cblog -i locales/cblog.pot -d locales/ -l en # for the english language pybabel compile -D cblog -d locales/ -f --statistics
Unfortunately, in order for the changes to the translated strings to take effect, the application needs to be restarted. The need to restart the server each time a translated string changes seems silly. Also, I spent more than 3 days hunting for documentation on how to actually get the i18n to work. Hopefully, doing the same with Django will be less painful.
After trying to work with the framework for over two weeks, I am about to give up on TurboGears, at least until 2.0 hits Debian. Hopefully, Django is going to work a bit better.
The final problem I have run into with TurboGears is the poor documentation regarding i18n with Genshi templates. The only way I have been able to get gettext to work for this blog was by using sourcecode from Transifex. To get i18n to work with genshi templates, I added this to config/app.cfg:
session_filter.on = True i18n.run_template_filter = True i18n.domain = "cblog" i18n.locale_dir = "locales/" i18n.po_view_dir = "locales/view/" i18n.locale_dir = "locales/"
and this to controllers.py:
# i18n support from turbogears.i18n import gettext from genshi.filters import Translator import turbogears.view def genshi_loader_callback(template): template.filters.insert(0, Translator(gettext)) def init_callback(): turbogears.view.engines['genshi'].loader.callback = genshi_loader_callback turbogears.startup.call_on_startup.append( init_callback ) config.update({'genshi.loader_callback': genshi_loader_callback}) # i18n support - end
To create the translation files, I followed the instructions from the Genshi i18n page. First, I created a mappings.cfg file containing:
# Extraction from Python source files [python: **.py] # Extraction from Genshi HTML and text templates [genshi: **/templates/**.html]
And then ran:
pybabel extract -o locales/cblog.pot -F ./mappings.cfg cblog pybabel init -D cblog -i locales/cblog.pot -d locales/ -l en # for the english language pybabel compile -D cblog -d locales/ -f --statistics
Unfortunately, in order for the changes to the translated strings to take effect, the application needs to be restarted. The need to restart the server each time a translated string changes seems silly. Also, I spent more than 3 days hunting for documentation on how to actually get the i18n to work. Hopefully, doing the same with Django will be less painful.