Skip to main content

No project description provided

Project description

Muffin-Babel – an extension to Muffin that adds localization support with help of babel.

Build Status http://img.shields.io/pypi/v/muffin-babel.svg?style=flat-square http://img.shields.io/pypi/dm/muffin-babel.svg?style=flat-square

Requirements

  • python >= 3.5.3

Installation

Muffin-Babel should be installed using pip:

pip install muffin-babel

Usage

Add muffin_babel to PLUGINS in your Muffin application config:

import muffin

app = muffin.Application(
    'example',

    PLUGINS=(
        'muffin_jinja2',
        'muffin_babel',
    )

)

Setup a locale selector function:

@app.ps.babel.locale_selector
def set_locale(request):
    """ Return locale from GET lang-param or automatically. """
    return request.GET.get(
        'lang',

        # Get locale based on user settings
        app.ps.babel.select_locale_by_request(request)
    )

Use app.ps.babel.gettext, app.ps.babel.pgettext, app.ps.babel.lazy_gettext function in your code:

@app.register('/')
def index(request):
    return app.ps.babel.gettext('Hello!')

Jinja2

The Muffin-Babel has integration with Muffin-Jinja2, so if you have muffin_jinja2 plugin enabled, the plugin provides gettext and ngettext function in Jinja2 templates’ context.

Options

BABEL_CONFIGURE_JINJA2

Install i18n support to Muffin-Jinja2 (True)

BABEL_DEFAULT_LOCALE

Set default locale (en)

BABEL_DOMAIN

Set default domain (messages)

BABEL_LOCALES_DIRS

List of directories where locales are leaving

BABEL_SOURCES_MAP

Babel sources map

BABEL_OPTIONS_MAP

Babel options map

Commands

The plugin adds two commands to your Muffin application.

Extract messages

Extract strings from your application to locales:

$ muffin app_module extract_messages [OPTIONS] appdir

Translate .po files and compile translations:

$ muffin app_module compile_messages [OPTIONS]

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/muffin-babel/issues

Contributing

Development of Muffin-Babel happens at: https://github.com/klen/muffin-babel

Contributors

  • klen (Kirill Klenov)

License

Licensed under a MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

muffin-babel-0.4.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

muffin_babel-0.4.2-py2.py3-none-any.whl (7.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file muffin-babel-0.4.2.tar.gz.

File metadata

  • Download URL: muffin-babel-0.4.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.3

File hashes

Hashes for muffin-babel-0.4.2.tar.gz
Algorithm Hash digest
SHA256 04d1268d2d2fb1936995457c17bcfa6afdd8ce9dea211c5d23585fadac487136
MD5 4d607fedc577d86259d05076ce2030d3
BLAKE2b-256 bd8ad9cfb6e152534b1b2edace31070dae9367300245696fc05c8c02d134efe0

See more details on using hashes here.

File details

Details for the file muffin_babel-0.4.2-py2.py3-none-any.whl.

File metadata

  • Download URL: muffin_babel-0.4.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.3

File hashes

Hashes for muffin_babel-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8d8012eb111ae93a838833300782ae96b6b16fe054a0c18da765e5cc80369074
MD5 a6e2d67f8061f31aa4bac3ca105b5a13
BLAKE2b-256 60c047d4298fd8dac0e1e52a7be09328ab4b59401b3205e1cb89e93b3e7d530d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page