Find file
Fetching contributors…
Cannot retrieve contributors at this time
122 lines (70 sloc) 2.63 KB

Localization (L10n)

Playdoh comes with all the libraries and tools you will need in production or development for localization.

Localization works by searching for localizable text in your source code and extracting (or merging them) into .po files in locale/.


The one set of low level tools not provided is gettext.

# for ubuntu/debian
aptitude install gettext

# for mac
brew install gettext

Testing It Out, Right Now

Playdoh comes with a sample app called examples which is also localized into French. This is so that you can get the hang of how things work out of the box. To get started, simply follow these quick steps:

  1. ./bin/ locale/
  2. Set DEV=True in
  3. ./ runserver
  4. Point your browser to


If you don't have any localization you need to do the following:

  1. ./ extract -c
  2. ./ merge -c

This will populate your locale/ directory.


Once your directories are set up you'll need to tend to your strings and their localization.


You can localize strings both in python code as well as Jinja templates.

In python:

from tower import ugettext as _, ugettext_lazy as _lazy

yodawg = _lazy('The Internet')

def myview(request):
    return render('template.html', {msg=_('Hello World'), msg2=yodawg})

_lazy is used when we are not in scope of a request. This lets us evaluate a string, such as yodawg, at the last possible second when we finally can draw upon the request's context. E.g. in a template:

{{ msg2 }}

Will be evaluated to whatever The Internet is in the requester's locale.

In Jinja we can use the following syntax for localized strings:

<h1>{{ _('Hello') }}</h1>

{% trans link='' %}
<p>Go to this <a href="{{ link }}">site</a>.</p>
{% endtrans %}

Updating our strings

If you make changes to your strings you can update them:

./ extract
./ merge

Note: you do not need -c for either command if you've created the required directories.

If you want to see these changes in your project:

./bin/ locale/

Creating New Locales

In your projects add the new locale to KNOWN_LANGUAGES.

Then run ./ merge -c which will create directories for any locales that are missing in /locale.