Skip to content
i18n support for bottlepy
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

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

Usage Example:


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

i18n_defaults(bottle.SimpleTemplate, bottle.request)

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

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

    sub_app = bottle.Bottle()

    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__':, 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

Something went wrong with that request. Please try again.