Hi,
I finally managed to get i18n working in my genshi templates with
TG-1.0.2/1.0.3, but I'm not sure if its the right way. To make things
work I had to add a translator filter to Genshi. This requires a
modification to TG view/base.py:
2.4.egg/turbogears/view [dag]: diff -u base.py.orig base.py
--- base.py.orig 2007-07-26 14:33:12.000000000 +0200
+++ base.py 2007-07-26 14:33:47.000000000 +0200
@@ -347,6 +347,7 @@
"genshi.encoding" : config.get("genshi.encoding", "utf-8"),
"genshi.default_doctype" :
config.get("genshi.default_doctype", None),
"genshi.lookup_errors" : config.get("genshi.lookup_errors",
"strict"),
+ "genshi.loader_callback" :
config.get("genshi.loader_callback", None),
"kid.encoding" : config.get("kid.encoding", "utf-8"),
"kid.assume_encoding" : config.get("kid.assume_encoding",
"utf-8"),
"kid.precompiled" : config.get("kid.precompiled", False),
Then in my controller.py I added:
from turbogears.i18n import gettext
from genshi.filters import Translator
def genshi_loader_callback(template):
template.filters.insert(0, Translator(gettext))
config.update({'genshi.loader_callback' : genshi_loader_callback})
Now, all the text in my Genshi templates are translated (like they
used to be when using Kid) without having to make a mess in the
template files. Thus I can write:
<p>Hello, world!</p>
instead of:
<p>${_("Hello, world!")}</p>
Does this look like the correct way to do it? Should the patch to
view.py be added to the TG code, so we can add template filters, or
should TG add the translation filter itself in future versions? What
do you think?
-- Dag
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---