Internationalization

To internationalize used a standard utility gettext (http://www.gnu.org/software/gettext/).
Before you begin, setup it in your system, such as:
debian
apt-get install gettext
nixos
nix-env -i gettext

Also you need Babel package:

pip install babel

pyramid_sacrud has certain labels in templates like “Home”, “Create”, “Delete”, etc. If these labels appear in English on your admin panel although you specified another language, then this page is for you.

pyramid_sacrud needs your help for translation of these labels. Translation process involves the following steps:

Update translatable messages

Execute extract_messages each time a translatable message text is changed or added:

python setup.py extract_messages

or for linux:

make extract_messages

This will create or update pyramid_sacrud/locale/pyramid_sacrud.pot file, the central messages catalog used by the different translations.

Create new translation catalog

Execute init_catalog once for each new language, e.g.:

python setup.py init_catalog -l de -i pyramid_sacrud/locale/pyramid_sacrud.pot -o pyramid_sacrud/locale/de/LC_MESSAGES/pyramid_sacrud.po

This will create a file pyramid_sacrud/locale/de/LC_MESSAGES/pyramid_sacrud.po in which translations needs to be placed.

Update translation catalog

Execute update_catalog for each existing language, e.g.:

python setup.py update_catalog

or for linux:

make update_catalog

This will update file pyramid_sacrud/locale/de/LC_MESSAGES/pyramid_sacrud.po where translations of new text needs to be placed.

Compile catalogs

Execute compile_catalog for each existing language, e.g.:

python setup.py compile_catalog

or for linux:

make compile_catalog

Example

English locale by default:

Russian locale:

German locale:

See also

For more information about Internationalization and Localization read official pyramid docs http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/i18n.html

Also see basic settings in setup.cfg file (hint steal from here).

Templates

For translate use _ps function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2014 uralbash <root@uralbash.ru>
#
# Distributed under terms of the MIT license.

"""
Internationalization and Localization
"""
from pyramid.i18n import TranslationStringFactory

_ps = TranslationStringFactory('pyramid_sacrud')


def includeme(config):
    config.add_translation_dirs('pyramid_sacrud:locale/')
    config.scan('.views')

Example with Jinja2 template:

<div class="dashboard-title">{{ _ps('Dashboard') }}</div>
{{ _ps(_(crumb.name)) }}
  Read the Docs
v: latest  
Versions
latest
stable
master
Free document hosting provided by Read the Docs.