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 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(__file__, app, "en")
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 en
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!")}
Metadata
Release files for fastapi-and-babel 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_and_babel-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for fastapi_and_babel-0.0.4-py3-none-any.whl |
Release files / fastapi_and_babel-0.0.4-py3-none-any.whl
| Download URL | fastapi_and_babel-0.0.4-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a220fe9c922bdfaa130d8f6943775fc31fcc171d7b1f6598ed3e7da600d281e
|
|
BLAKE2b-256 checksum How to use checksums |
e44536f58d8f79db0dd54b831b6fd36e8fdd4236263392432a9bf524d00625a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for fastapi-and-babel 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.