Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
i18n support for bottlepy
Python
Tag: v0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
.gitignore
LICENSE
MANIFEST
README.md
bottle_i18n.py
setup.py

README.md

The bottle-i18n plugin integrates the multilingual internationalization services gettext from Python with your Bottle application.

Usage Example:

#!/usr/bin/python

import bottle
from bottle.ext.i18n import I18NPlugin, I18NMiddleware, i18n_defaults

i18n_defaults(bottle.SimpleTemplate, bottle.request)

def get():
    app = bottle.Bottle()

    @app.route('/')
    def index():
        return bottle.template("<b>{{_('hello')}} I18N<b/>?")


    sub_app = bottle.Bottle()

    @sub_app.route('/')
    def sub():
        return bottle.template("current language is {{lang()}}")


    app.mount(app = sub_app , prefix = '/sub', skip = None)

    return I18NMiddleware(app, I18NPlugin(domain='messages', default='en', locale_dir='./locale'))


if __name__ == '__main__':
    bottle.run(app=get(), host='localhost', port='8000', quiet=False, reloader=True)

Running the above example it automatically loads the default language en if in the URL the langauge code or the HTTP_ACCEPT_LANGUAGe sent from the browser is missing.

The URL structure is as follow

http://localhost:8000/<language-code>/<route>
Something went wrong with that request. Please try again.