muffin-babel


Namemuffin-babel JSON
Version 1.5.0 PyPI version JSON
download
home_pagehttps://github.com/klen/muffin-babel
SummaryLocalization support for the Muffin Framework
upload_time2024-07-31 21:48:35
maintainerNone
docs_urlNone
authorKirill Klenov
requires_python<4.0,>=3.9
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.9

.. _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": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "localization, internationalization, muffin, babel, asyncio, trio, asgi",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/45/e2/1c854b41a4c9dd8d7e4e4c83defc828be89577e4fae87ed38648615ef62e/muffin_babel-1.5.0.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.9\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.5.0",
    "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": "bb242a683d3f4b603ef93ed56063258cfb0b844d7c3a335b3935c0aaa472df3a",
                "md5": "c5f2b11ed23d366eb6dba4464719f640",
                "sha256": "d8f1e0b138631d87ad4da6c8415e8570b9649d71626cf6ba381a9c12a24af29a"
            },
            "downloads": -1,
            "filename": "muffin_babel-1.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c5f2b11ed23d366eb6dba4464719f640",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5961,
            "upload_time": "2024-07-31T21:48:33",
            "upload_time_iso_8601": "2024-07-31T21:48:33.704043Z",
            "url": "https://files.pythonhosted.org/packages/bb/24/2a683d3f4b603ef93ed56063258cfb0b844d7c3a335b3935c0aaa472df3a/muffin_babel-1.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45e21c854b41a4c9dd8d7e4e4c83defc828be89577e4fae87ed38648615ef62e",
                "md5": "d3cdf3a3e1f608425f8b177f22b0cbdc",
                "sha256": "6cc332e33d63f39e1c706e869044d3db89e86c8e102abf170854a012ea58afb7"
            },
            "downloads": -1,
            "filename": "muffin_babel-1.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d3cdf3a3e1f608425f8b177f22b0cbdc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 5935,
            "upload_time": "2024-07-31T21:48:35",
            "upload_time_iso_8601": "2024-07-31T21:48:35.606883Z",
            "url": "https://files.pythonhosted.org/packages/45/e2/1c854b41a4c9dd8d7e4e4c83defc828be89577e4fae87ed38648615ef62e/muffin_babel-1.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-31 21:48:35",
    "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.85519s