Package: tower
Tower provides some additional functionality to Jinja and it’s i18n extension,
and the Babel library.Author: Wil Clouser andcontributorsLicence: BSDCompatibility: Python 2.6 and 2.7, Django 1.4, 1.5 and 1.6Requirements: django, babel, jinja2, jingo and translate-toolkitProject URL:https://github.com/clouserw/towerDocumentation:http://tower.readthedocs.org/en/latest/Specifics:Pulls strings from a variety of sources: Python, JavaScript, and .lhtml files.Collapses whitespace in all strings to prevent unwieldy msgids.Supports Gettext context (msgctxt) in all gettext, and ngettext calls.Supports merging PHP and Python .pot files.  This is temporary.  If you want
to support that for an extended time look at phppo2pypo in theTranslate Toolkit.RequirementsDjangoBabelJinja2 and Jingotranslate-toolkitSeerequirements.txtfor details.InstallationInstall from pypi with:pip install towerSource code is athttp://github.com/clouserw/tower.Install from GitHub with:pip install -e git://github.com/clouserw/tower.git#egg=towerConfigureAdd toINSTALLED_APPSin your Django settings file:INSTALLED_APPS = (
    # ...
    'tower',
    # ...
)Then configure.django.conf.settings.DOMAIN_METHODSDefault:None–you must set this.The value is a dict of domain to file spec and extraction method tuples.For example, this creates a domain “messages” and in that domain
extracts all the l10n strings from .py and .html files:DOMAIN_METHODS = {
    'messages': [
        ('fjord/**.py', 'tower.tools.extract_tower_python'),
        ('fjord/**.html', 'tower.tools.extract_tower_template'),
    ]
}Usetower.tools.extract_tower_pythonfor Python files andtower.tools.extract_tower_templatefor Jinja2 templates.The l10n strings will be saved in a .pot file with the name of the
domain. In the above example, it’d bemessages.pot.django.conf.settings.STANDALONE_DOMAINSDefault:['messages']By default, all domains specified inDOMAIN_METHODSget merged
into one big .pot file. If you don’t want that, you can specify
which domains get their own .pot file withSTANDALONE_DOMAINS.django.conf.settings.TOWER_KEYWORDSTODO: Document this.django.conf.settings.TOWER_ADD_HEADERSDefault:FalseIf you have trouble extracting strings with Tower, try setting this
to True.django.conf.settings.ROOTThis points to the source code directory where you want yourlocale/directory to be.django.conf.settings.pathThis is a function that takes arbitrary set of args and combines
them withROOTto form a new path.Example:import os

# The settings file is in fjord/fjord/settings/base.py. From
# base, up two directories is the initial fjord directory
# which is where all the source code and the fjord Django
# project are.
ROOT = os.path.dirname(os.path.dirname(__file__))

path = lambda *args: os.path.abspath(os.path.join(ROOT, *args))UsageExtract:./manage.py extractMerge:./manage.py mergeA note on whitespaceWhen tower extracts strings, it collapses whitespace. This makes it easier
for localizers. It also means you need to use ugettext, ungettext, ugettext_lazy
and ungettext_lazy from tower. Otherwise the msgids being passed in won’t have
their whitespace stripped and thus won’t match anything in your .mo file.A note onsafe-nessL10n strings are marked “safe” for Jinja2 automatically, so they will not be
HTML-escaped:{{ _('Hello <strong>World</strong>') }}This works as expected. When interpolating into an L10n string, however, it will
be marked as “unsafe” and escaped, unless you usejingo’s|fe()helper (which will escape the
arguments but not the string they are interpolated into). Like this:{{ _('Hello <strong>{0}</strong>')|fe(user.nickname) }}Run testsRun:python run_tests.py