Internationalization

Glashammer provides internationalization out of the box using the Babel library. You can enable it by adding the i18n bundle during application setup:

from glashammer.bundles.i18n import setup_i18n
app.add_setup(setup_i18n)

The language is decided by the configuration variable ‘language’.

Formatting Dates in Templates

The i18n bundle provides two template filters which format dates, or datetimes into the locale’s current format. These filters accept an additional argument which is the format type (‘short’, ‘medium’, ‘long’; default is ‘medium’) and so can be used in a template like so for a date object:

{{ d|formatdate('long') }}

The API of the actual functions, if you want or need to use them outside templates, are as so:

glashammer.bundles.i18n.format_datetime(datetime=None, format='medium')
Return a date formatted according to the given pattern.
glashammer.bundles.i18n.format_date(date=None, format='medium')
Return the date formatted according to the pattern.

Bundle cheat-sheet

External Dependencies
Configuration variables added
  • language (type: str, default: ‘en’)
Template filters added
  • formatdatetime

    format a datetime object to the current language

  • formatdate

    format a date object to the current language

Full API

glashammer.bundles.i18n

i18n tools for Glashammer.

copyright:Copyright 2008 by Armin Ronacher.
license:MIT
glashammer.bundles.i18n.gettext(string)
Translate the given string to the language of the application.
glashammer.bundles.i18n.ngettext(singular, plural, n)
Translate the possible pluralized string to the language of the application.