Skip to content
rrouse edited this page Nov 7, 2011 · 1 revision

This page describes how to completely internationalize and localize a Chicago Boss app in just a few minutes.

Introduction. I18n is something most people avoid, and for good reason: to get even basic i18n, you’ve traditionally needed to to hire translators, rewrite large amounts of the code base, and muck around with PO- and MO-files. But Chicago Boss makes I18n nice and simple. If you don’t mind quick-and-dirty translations from Google Translate for a first pass, you won’t even need translators.

Step 1. The first and hardest step is to internationalize your templates by putting strings you want to translate into a special trans tag, e.g.:

{% trans "Welcome!" %}

If you have code that displays validation errors returned from BossRecord:save, you should put those in trans tags, too, e.g.:


<ol>
{% for error in validation_errors %}
<li>{% trans error %}
{% endfor %}
</ol>

Step 2. Now we need to create a language file. Visit /admin/lang on your development server. You should see a page like this:

Step 3. Click “New language file”

Step 4. Choose a language for which you want to have a translation, and click “Create language file”.

Step 5. You should a page with a lot of messages pulled from your app’s templates, as well as all the error messages returned by the validation_errors() function of your data models. (You’ll see messages taken from the /admin interface itself, too.)

Step 6. Fill out the form yourself, or cheat and click “Fill in the blanks with Google!”

Step 7. Click “Submit translations”

Step 8. You should see all of your translations for the language you chose.

…and that’s it! Visitors to your site who specify this language in their browsers will automatically see these messages instead of the original ones.

You can find the files used for translations in the lang/ directory in your project directory. They’re just PO-files, so if your PO-foo is strong you can edit them directly.

What if you want to override the language specified in a user’s browser settings? Not a problem. You just need to return a “Content-Language” HTTP header from your controller, like so:

{ok, [], [{"Content-Language", "fr"}]}.

That code would ensure that the French language strings are used (assuming you created a language file for fr).

See also: How Chicago Boss Chooses Which Language To Serve