muffin-babel


Namemuffin-babel JSON
Version 1.4.3 PyPI version JSON
download
home_pagehttps://github.com/klen/muffin-babel
SummaryLocalization support for the Muffin Framework
upload_time2023-05-22 12:06:04
maintainer
docs_urlNone
authorKirill Klenov
requires_python>=3.8,<4.0
licenseMIT
keywords localization internationalization muffin babel asyncio trio asgi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Muffin-Babel
############

.. _description:

**Muffin-Babel** -- an extension to Muffin_ that adds localization support with help of Babel_.

.. _badges:

.. image:: https://github.com/klen/muffin-babel/workflows/tests/badge.svg
    :target: https://github.com/klen/muffin-babel/actions
    :alt: Tests Status

.. image:: https://img.shields.io/pypi/v/muffin-babel
    :target: https://pypi.org/project/muffin-babel/
    :alt: PYPI Version

.. image:: https://img.shields.io/pypi/pyversions/muffin-babel
    :target: https://pypi.org/project/muffin-babel/
    :alt: Python Versions

.. _contents:

.. contents::

.. _requirements:

Requirements
=============

- python >= 3.8

.. _installation:

Installation
=============

**Muffin-Babel** should be installed using pip: ::

    pip install muffin-babel

.. _usage:

Usage
=====

Initialize and setup the plugin:

.. code-block:: python

    import muffin
    import muffin_babel

    # Create Muffin Application
    app = muffin.Application('example')

    # Initialize the plugin
    # As alternative: babel = muffin_babel.Plugin(app, **options)
    babel = muffin_babel.Plugin()
    babel.setup(app, template_folders=['src/templates'])

    # Use it inside your handlers
    @app.route('/')
    async def index(request):
        # Get current locale
        assert babel.current_locale
        # Translate a text
        return babel.gettext('Hello World!')


Setup a locale selector function (by default the plugin is parsing ``accept-language`` header):

.. code-block:: python

    @babel.locale_selector
    async def get_locale(request):
        """ Return locale either from request.query or from request headers. """
        locale = request.query.get('lang')
        if not locale:
            return await muffin_babel.select_locale_by_request(request, default)
        return locale

Use `babel.gettext`, `babel.pgettext` callables in your code:

.. code-block:: python

    @app.route('/')
    def index(request):
        return 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 inside the Jinja2 templates' context.


Options
-------

========================== ============== ===============================================
 Name                      Default Value  Description
========================== ============== ===============================================
 **AUTO_DETECT_LOCALE**    ``True``       Installs a middleware to automatically detect users locales
 **CONFIGURE_JINJA2**      ``True``       Installs i18n support for jinja2 templates (through ``muffin-jinja``)
 **DEFAULT_LOCALE**        ``"en"``       Default locale
 **DOMAIN**                ``"messages"`` Default localization domain
 **SOURCES_MAP**                          Babel sources map
 **OPTIONS_MAP**                          Babel options map
========================== ============== ===============================================

You are able to provide the options when you are initiliazing the plugin:

.. code-block:: python

    babel.setup(app, default_locale='fr')


Or setup it inside ``Muffin.Application`` config using the ``BABEL_`` prefix:

.. code-block:: python

   BABEL_DEFAULT_LOCALE = 'fr'

``Muffin.Application`` configuration options are case insensitive

Commands
========

The plugin adds two commands to your Muffin_ application.

Extract messages
----------------

Extract strings from your application to locales: ::

    $ muffin app_package babel_extract_messages [OPTIONS] appdir


Translate ``.po`` files and compile translations: ::

    $ muffin app_package babel_compile_messages [OPTIONS]


.. _bugtracker:

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:

Contributing
============

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


Contributors
=============

* klen_ (Kirill Klenov)

.. _license:

License
========

Licensed under a `MIT license`_.

.. _links:


.. _klen: https://github.com/klen
.. _Muffin: https://github.com/klen/muffin
.. _Muffin-Jinja2: https://github.com/klen/muffin-jinja2
.. _Babel: http://babel.edgewall.org/

.. _MIT license: http://opensource.org/licenses/MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klen/muffin-babel",
    "name": "muffin-babel",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "localization,internationalization,muffin,babel,asyncio,trio,asgi",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ea/da/54383580b52e2b84029439fdad9722fed37647f129a49e6da54eeb5a9108/muffin_babel-1.4.3.tar.gz",
    "platform": null,
    "description": "Muffin-Babel\n############\n\n.. _description:\n\n**Muffin-Babel** -- an extension to Muffin_ that adds localization support with help of Babel_.\n\n.. _badges:\n\n.. image:: https://github.com/klen/muffin-babel/workflows/tests/badge.svg\n    :target: https://github.com/klen/muffin-babel/actions\n    :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/muffin-babel\n    :target: https://pypi.org/project/muffin-babel/\n    :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/muffin-babel\n    :target: https://pypi.org/project/muffin-babel/\n    :alt: Python Versions\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.8\n\n.. _installation:\n\nInstallation\n=============\n\n**Muffin-Babel** should be installed using pip: ::\n\n    pip install muffin-babel\n\n.. _usage:\n\nUsage\n=====\n\nInitialize and setup the plugin:\n\n.. code-block:: python\n\n    import muffin\n    import muffin_babel\n\n    # Create Muffin Application\n    app = muffin.Application('example')\n\n    # Initialize the plugin\n    # As alternative: babel = muffin_babel.Plugin(app, **options)\n    babel = muffin_babel.Plugin()\n    babel.setup(app, template_folders=['src/templates'])\n\n    # Use it inside your handlers\n    @app.route('/')\n    async def index(request):\n        # Get current locale\n        assert babel.current_locale\n        # Translate a text\n        return babel.gettext('Hello World!')\n\n\nSetup a locale selector function (by default the plugin is parsing ``accept-language`` header):\n\n.. code-block:: python\n\n    @babel.locale_selector\n    async def get_locale(request):\n        \"\"\" Return locale either from request.query or from request headers. \"\"\"\n        locale = request.query.get('lang')\n        if not locale:\n            return await muffin_babel.select_locale_by_request(request, default)\n        return locale\n\nUse `babel.gettext`, `babel.pgettext` callables in your code:\n\n.. code-block:: python\n\n    @app.route('/')\n    def index(request):\n        return babel.gettext('Hello!')\n\n\nJinja2\n------\n\nThe `Muffin-Babel` has integration with `Muffin-Jinja2`, so if you have\n`muffin_jinja2` plugin enabled, the plugin provides `gettext` and `ngettext`\nfunction inside the Jinja2 templates' context.\n\n\nOptions\n-------\n\n========================== ============== ===============================================\n Name                      Default Value  Description\n========================== ============== ===============================================\n **AUTO_DETECT_LOCALE**    ``True``       Installs a middleware to automatically detect users locales\n **CONFIGURE_JINJA2**      ``True``       Installs i18n support for jinja2 templates (through ``muffin-jinja``)\n **DEFAULT_LOCALE**        ``\"en\"``       Default locale\n **DOMAIN**                ``\"messages\"`` Default localization domain\n **SOURCES_MAP**                          Babel sources map\n **OPTIONS_MAP**                          Babel options map\n========================== ============== ===============================================\n\nYou are able to provide the options when you are initiliazing the plugin:\n\n.. code-block:: python\n\n    babel.setup(app, default_locale='fr')\n\n\nOr setup it inside ``Muffin.Application`` config using the ``BABEL_`` prefix:\n\n.. code-block:: python\n\n   BABEL_DEFAULT_LOCALE = 'fr'\n\n``Muffin.Application`` configuration options are case insensitive\n\nCommands\n========\n\nThe plugin adds two commands to your Muffin_ application.\n\nExtract messages\n----------------\n\nExtract strings from your application to locales: ::\n\n    $ muffin app_package babel_extract_messages [OPTIONS] appdir\n\n\nTranslate ``.po`` files and compile translations: ::\n\n    $ muffin app_package babel_compile_messages [OPTIONS]\n\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/muffin-babel/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of Muffin-Babel happens at: https://github.com/klen/muffin-babel\n\n\nContributors\n=============\n\n* klen_ (Kirill Klenov)\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n.. _links:\n\n\n.. _klen: https://github.com/klen\n.. _Muffin: https://github.com/klen/muffin\n.. _Muffin-Jinja2: https://github.com/klen/muffin-jinja2\n.. _Babel: http://babel.edgewall.org/\n\n.. _MIT license: http://opensource.org/licenses/MIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Localization support for the Muffin Framework",
    "version": "1.4.3",
    "project_urls": {
        "Homepage": "https://github.com/klen/muffin-babel",
        "Repository": "https://github.com/klen/muffin-babel"
    },
    "split_keywords": [
        "localization",
        "internationalization",
        "muffin",
        "babel",
        "asyncio",
        "trio",
        "asgi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92d94f55e65dc3c77c8befec0d553af9978287f34ae70971929b7103315fa25b",
                "md5": "f7998d5556c599aad0c330a03b62ba66",
                "sha256": "73c0a2402726384332e99d88c741f5f8507f6a4c177495cf2adf530ddaffa6e3"
            },
            "downloads": -1,
            "filename": "muffin_babel-1.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f7998d5556c599aad0c330a03b62ba66",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 5964,
            "upload_time": "2023-05-22T12:06:02",
            "upload_time_iso_8601": "2023-05-22T12:06:02.572723Z",
            "url": "https://files.pythonhosted.org/packages/92/d9/4f55e65dc3c77c8befec0d553af9978287f34ae70971929b7103315fa25b/muffin_babel-1.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eada54383580b52e2b84029439fdad9722fed37647f129a49e6da54eeb5a9108",
                "md5": "595b6731e069d07533aa222d1d68c293",
                "sha256": "af755f71e3c3ef5753156f303b8dfbd149e022f0fdce41d7dcf467c5f4324424"
            },
            "downloads": -1,
            "filename": "muffin_babel-1.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "595b6731e069d07533aa222d1d68c293",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 5876,
            "upload_time": "2023-05-22T12:06:04",
            "upload_time_iso_8601": "2023-05-22T12:06:04.473253Z",
            "url": "https://files.pythonhosted.org/packages/ea/da/54383580b52e2b84029439fdad9722fed37647f129a49e6da54eeb5a9108/muffin_babel-1.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-22 12:06:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "klen",
    "github_project": "muffin-babel",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "muffin-babel"
}
        
Elapsed time: 0.06756s