fastapi-and-babel


Namefastapi-and-babel JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://github.com/heysaeid/fastapi-and-babel
SummaryEasy to use babel in FastAPI
upload_time2023-06-30 18:33:24
maintainer
docs_urlNone
authorSaeid Noormohammadi
requires_python
licenseMIT
keywords fastapi babel fastapi babel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI And Babel
FastAPIAndBabel allows you to easily use babel in your FastAPI projects and offers some features to improve and ease things.


## Install 
You can either download the source code of this repository or install it via pip:
```
pip install git+https://github.com/heysaeid/fastapi-and-babel
```

## Usage
First, we create an instance of FastAPIAndBabel in our program as shown below
‍‍‍
```
from fastapi import FastAPI
from fastapi_and_babel.translator import FastAPIAndBabel


app = FastAPI()
translator = FastAPIAndBabel(app, __file__, "de")
```
We create the following mapping file
babel.cfg
```
[python: **.py]
```

Save the file and then run the following command
```
pybabel extract -F babel.cfg -o messages.pot .
```

babel uses this file for mapping and stores the patterns in messages.pot

```
pybabel init -i messages.pot -d translations -l fa
```
Here -d says to save translations in translations, you can change it in config

After adding your messages, use the following command to compile

```pybabel compile -d translations```


Now we can translate our texts using the gettext method
```
from fastapi_and_babel import gettext as _

@app.get("/")
def index():
    return {"text": _("Hello World!")}
```





            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/heysaeid/fastapi-and-babel",
    "name": "fastapi-and-babel",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "fastapi,babel,fastapi babel",
    "author": "Saeid Noormohammadi",
    "author_email": "heysaeid92@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/33/a9/363432706f1a2bfdfd525c807c10639a6861c14403219e2ebe4fcf5197a0/fastapi-and-babel-0.0.1.tar.gz",
    "platform": "any",
    "description": "# FastAPI And Babel\nFastAPIAndBabel allows you to easily use babel in your FastAPI projects and offers some features to improve and ease things.\n\n\n## Install \nYou can either download the source code of this repository or install it via pip:\n```\npip install git+https://github.com/heysaeid/fastapi-and-babel\n```\n\n## Usage\nFirst, we create an instance of FastAPIAndBabel in our program as shown below\n\u200d\u200d\u200d\n```\nfrom fastapi import FastAPI\nfrom fastapi_and_babel.translator import FastAPIAndBabel\n\n\napp = FastAPI()\ntranslator = FastAPIAndBabel(app, __file__, \"de\")\n```\nWe create the following mapping file\nbabel.cfg\n```\n[python: **.py]\n```\n\nSave the file and then run the following command\n```\npybabel extract -F babel.cfg -o messages.pot .\n```\n\nbabel uses this file for mapping and stores the patterns in messages.pot\n\n```\npybabel init -i messages.pot -d translations -l fa\n```\nHere -d says to save translations in translations, you can change it in config\n\nAfter adding your messages, use the following command to compile\n\n```pybabel compile -d translations```\n\n\nNow we can translate our texts using the gettext method\n```\nfrom fastapi_and_babel import gettext as _\n\n@app.get(\"/\")\ndef index():\n    return {\"text\": _(\"Hello World!\")}\n```\n\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Easy to use babel in FastAPI",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/heysaeid/fastapi-and-babel"
    },
    "split_keywords": [
        "fastapi",
        "babel",
        "fastapi babel"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33a9363432706f1a2bfdfd525c807c10639a6861c14403219e2ebe4fcf5197a0",
                "md5": "3eb3ad144d28f1a58423de604d7f6677",
                "sha256": "537de935ce08996577cfd7d5be1863b65fb887cc02495789b826a993fb7ff505"
            },
            "downloads": -1,
            "filename": "fastapi-and-babel-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3eb3ad144d28f1a58423de604d7f6677",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3802,
            "upload_time": "2023-06-30T18:33:24",
            "upload_time_iso_8601": "2023-06-30T18:33:24.625093Z",
            "url": "https://files.pythonhosted.org/packages/33/a9/363432706f1a2bfdfd525c807c10639a6861c14403219e2ebe4fcf5197a0/fastapi-and-babel-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-30 18:33:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "heysaeid",
    "github_project": "fastapi-and-babel",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastapi-and-babel"
}
        
Elapsed time: 0.08146s