All text strings you want translated should be included in the _() function. This function is built-in to TurboGears, so you don't need to import it specifically into your module, if you have already called "import turbogears".
import turbogears
from turbogears import controllers
class Controller(controllers.Root):
@turbogears.expose(html="myapp.templates.welcome.kid")
def index(self):
return dict(message=_("Welcome"))
Congratulations, your application is now localized!
Thanks to Dan Jacob's work, TurboGears internationalization support will take it from here.
If you update your controllers file like this:
import turbogears
import cherrypy
from turbogears import controllers
class Root(controllers.RootController):
@turbogears.expose(template="langtest.templates.welcome")
def index(self,lang=None):
#for this to work you have to enable sessions in your config file:
#sessionFilter.on = True
if lang: cherrypy.session['locale'] = lang
return dict(now=_('today'))
Your users will be able to select a locale for duration of their session, by passing a (supported) language as parameter