admi18n

Painless localization for your next TurboGears Project in 10 steps

1. Mark your text strings with _()

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"))

2. Start toolbox from your project directory

Choose the new admin18n tool from the list

3. Start by collecting your strings

From the left menu, choose 'Collect your strings'

4. Run the string collection tool

You can configure which files you want to translate, by default all your python filers and kid templates are selected.

5. Project directory

The tool creates a locale directory for you and saved the message file there

6. Message file

Once your pot file is generated you can mail it to your translators

7.0 Add a locale

Choose the language you wish to add from the drop down list

7.1 Add a locale

Now you can choose the language you wish to add from the drop down list

7.2 Add a locale

 

7.3 Add a locale

 

8.0 Edit the language file

You can upload (or copy) your message file returned from your translators

8.1 Edit the language file

Or edit your strings directly

8.2 Edit the language file

Or edit your strings directly

8.3 Edit the language file

Or edit your strings directly

8.4 Edit the language file

Or edit your strings directly

9.0 Compile your message file

Select the locale and compile the message file

9.1 Compile your message file

Select the locale and compile the message file

10. Wrap-up

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