messageformat2


Namemessageformat2 JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryPython implementation of Unicode MessageFormat 2.0
upload_time2024-05-19 16:24:11
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT License Copyright (c) European Organization for Nuclear Research (CERN) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords i18n internationalization localization messageformat messageformat 2 cldr gettext
VCS
bugtrack_url
requirements babel click
Travis-CI No Travis.
coveralls test coverage No coveralls.
            

# MessageFormat2 [![Documentation Status](https://readthedocs.org/projects/messageformat2/badge/?version=latest)](https://messageformat2.readthedocs.io/en/latest/?badge=latest) [![CI](https://github.com/tomasr8/messageformat2/workflows/CI/badge.svg)](https://github.com/tomasr8/messageformat2/workflows/CI/badge.svg) [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)

This is a Python implementation of the [Unicode Message Format 2.0
specification](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html).

Message Format 2.0 (MF2) is a new iteration of Message Format which aims to be
more expressive and flexible than both Message Format 1.0 and, in the context of
Python, gettext.

If you would like to learn more about MF2 itself head over to the [Unicode technical
specification](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html).

## Features

The library includes:

- A message parser and a formatter
- Several builtin formatters and selectors described by the
  [spec](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html#function-registry)
  and the possibility to write custom formatters/selectors
- Helper classes to inspect and transform the message [data
  model](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html#interchange-data-model)

## [Documentation](https://messageformat2.readthedocs.io/en/latest/)

## Installation

Via pip for Python `>= 3.12`

```sh
pip install messageformat2
```

## Examples

### Simple messages

```python
from messageformat2 import format_message

format_message("Hello, {$name}!", {"name": "Alice"})  # -> "Hello, Alice!"
```

Messages can be reused with different inputs.

```python
from messageformat2 import Message

message = Message("Hello, {$name}!")
message.format({"name": "Alice"})  # -> "Hello, Alice!"
message.format({"name": "Bob"})  # -> "Hello, Bob!"
```

### Built-in formatters

There are several builtin locale-aware formatters available.

```python
from datetime import datetime
from messageformat2 import Message

message = Message("Today's date is {$now :date}")
now = datetime.now()
message.format({"now": now}, locale='en_US')
# -> Today's date is 5/10/2024
message.format({"now": now}, locale='en_GB')
# -> Today's date is 10/05/2024
```

### Plural support

MF2 supports pluralization using built-in or custom selectors.

```python
from messageformat2 import Message

msg = Message ("""\
.match {$count :number}
one {{You have {$count} notification.}}
*   {{You have {$count} notifications.}}
""")

msg.format({"count": 42}, locale='en_US') # -> "You have 42 notifications."
msg.format({"count": 1}, locale='en_US') # -> "You have 1 notification."
```

Complete documentation is available [here](https://messageformat2.readthedocs.io/en/latest/).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "messageformat2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "i18n, internationalization, localization, messageformat, messageformat 2, cldr, gettext",
    "author": null,
    "author_email": "Tomas Roun <tomas.roun8@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/cf/95/80899530c3e7642e80b7e4a2c292fed996c26f924638ecea468c6e4576e7/messageformat2-0.1.0.tar.gz",
    "platform": null,
    "description": "\n\n# MessageFormat2 [![Documentation Status](https://readthedocs.org/projects/messageformat2/badge/?version=latest)](https://messageformat2.readthedocs.io/en/latest/?badge=latest) [![CI](https://github.com/tomasr8/messageformat2/workflows/CI/badge.svg)](https://github.com/tomasr8/messageformat2/workflows/CI/badge.svg) [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)\n\nThis is a Python implementation of the [Unicode Message Format 2.0\nspecification](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html).\n\nMessage Format 2.0 (MF2) is a new iteration of Message Format which aims to be\nmore expressive and flexible than both Message Format 1.0 and, in the context of\nPython, gettext.\n\nIf you would like to learn more about MF2 itself head over to the [Unicode technical\nspecification](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html).\n\n## Features\n\nThe library includes:\n\n- A message parser and a formatter\n- Several builtin formatters and selectors described by the\n  [spec](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html#function-registry)\n  and the possibility to write custom formatters/selectors\n- Helper classes to inspect and transform the message [data\n  model](https://www.unicode.org/reports/tr35/tr35-72/tr35-messageFormat.html#interchange-data-model)\n\n## [Documentation](https://messageformat2.readthedocs.io/en/latest/)\n\n## Installation\n\nVia pip for Python `>= 3.12`\n\n```sh\npip install messageformat2\n```\n\n## Examples\n\n### Simple messages\n\n```python\nfrom messageformat2 import format_message\n\nformat_message(\"Hello, {$name}!\", {\"name\": \"Alice\"})  # -> \"Hello, Alice!\"\n```\n\nMessages can be reused with different inputs.\n\n```python\nfrom messageformat2 import Message\n\nmessage = Message(\"Hello, {$name}!\")\nmessage.format({\"name\": \"Alice\"})  # -> \"Hello, Alice!\"\nmessage.format({\"name\": \"Bob\"})  # -> \"Hello, Bob!\"\n```\n\n### Built-in formatters\n\nThere are several builtin locale-aware formatters available.\n\n```python\nfrom datetime import datetime\nfrom messageformat2 import Message\n\nmessage = Message(\"Today's date is {$now :date}\")\nnow = datetime.now()\nmessage.format({\"now\": now}, locale='en_US')\n# -> Today's date is 5/10/2024\nmessage.format({\"now\": now}, locale='en_GB')\n# -> Today's date is 10/05/2024\n```\n\n### Plural support\n\nMF2 supports pluralization using built-in or custom selectors.\n\n```python\nfrom messageformat2 import Message\n\nmsg = Message (\"\"\"\\\n.match {$count :number}\none {{You have {$count} notification.}}\n*   {{You have {$count} notifications.}}\n\"\"\")\n\nmsg.format({\"count\": 42}, locale='en_US') # -> \"You have 42 notifications.\"\nmsg.format({\"count\": 1}, locale='en_US') # -> \"You have 1 notification.\"\n```\n\nComplete documentation is available [here](https://messageformat2.readthedocs.io/en/latest/).\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) European Organization for Nuclear Research (CERN)  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python implementation of Unicode MessageFormat 2.0",
    "version": "0.1.0",
    "project_urls": {
        "Github": "https://github.com/tomasr8/messageformat2",
        "Homepage": "https://github.com/tomasr8/messageformat2"
    },
    "split_keywords": [
        "i18n",
        " internationalization",
        " localization",
        " messageformat",
        " messageformat 2",
        " cldr",
        " gettext"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cff7c14c7be926afafc52bff8a4110393b111a6cba64ca9da0074db3c9b28786",
                "md5": "2da4857402d334b0f0ff394e6156a5e9",
                "sha256": "bbedf6e8fe91330d41fa96ed9729f9f92f68cd590ded0c4ad5591a9af7f73b2e"
            },
            "downloads": -1,
            "filename": "messageformat2-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2da4857402d334b0f0ff394e6156a5e9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 18947,
            "upload_time": "2024-05-19T16:24:09",
            "upload_time_iso_8601": "2024-05-19T16:24:09.060160Z",
            "url": "https://files.pythonhosted.org/packages/cf/f7/c14c7be926afafc52bff8a4110393b111a6cba64ca9da0074db3c9b28786/messageformat2-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf9580899530c3e7642e80b7e4a2c292fed996c26f924638ecea468c6e4576e7",
                "md5": "8716b5808de74d09f54ee26d30ab8ca1",
                "sha256": "f7eacaad6b9f47c15d554d1cc076ac99cc0ef0c81082757fdc31591a6b84edf6"
            },
            "downloads": -1,
            "filename": "messageformat2-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8716b5808de74d09f54ee26d30ab8ca1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 31328,
            "upload_time": "2024-05-19T16:24:11",
            "upload_time_iso_8601": "2024-05-19T16:24:11.014540Z",
            "url": "https://files.pythonhosted.org/packages/cf/95/80899530c3e7642e80b7e4a2c292fed996c26f924638ecea468c6e4576e7/messageformat2-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-19 16:24:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tomasr8",
    "github_project": "messageformat2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "babel",
            "specs": [
                [
                    "==",
                    "2.15.0"
                ]
            ]
        },
        {
            "name": "click",
            "specs": [
                [
                    "==",
                    "8.1.7"
                ]
            ]
        }
    ],
    "lcname": "messageformat2"
}
        
Elapsed time: 0.28988s