Repository: Anbarryprojects/fastapi-babel (language: python)

Issue:
Fastapi Babel Logo
![fastapi-babel](https://user-images.githubusercontent.com/56755478/165474515-12392df4-a41c-4ed9-bed4-512f606caedc.png)



Discussion / hints:
![](https://user-images.githubusercontent.com/56755478/165474515-12392df4-a41c-4ed9-bed4-512f606caedc.png)


# FastAPI BABEL
Fastapi babel is a tool what supports i18n, l10n, date and time locales and all pybabel functionalities easily that integrated with fastapi framework.

## Features:
- **I18n** (Internationalization)
- **l10n** (Localization)
- **Date and time** locale
- **Decimal, Number** locale
- **Money and currency** locale converter
- locale selector from **http header**

## Support
**Python:** 3.6 and later (tested against 3.6, 3.7, 3.8 and 3.9)
**FastAPI**: 0.45.0 +
**PyBabel**: All

## Installation
    pip install fastapi-babel

# How to use FastAPI Babel?
- Create main.py file:

```python
from fastapi_babel import Babel
from fastapi_babel import BabelConfigs
from fastapi_babel import _

configs = BabelConfigs(
    ROOT_DIR=__file__,
    BABEL_DEFAULT_LOCALE="en",
    BABEL_TRANSLATION_DIRECTORY="lang",
)
babel = Babel(configs=configs)

def main():
	babel.locale = "en"
	en_text = _("Hello World")
	print(en_text)
	
	babel.locale = "fa"
	fa_text = _("Hello World")
	print(fa_text)

if __name__ == "__main__":
	main()
```

- ### PyBabel Commands
1. extracting
`pybabel extract -F babel.cfg -o messages.pot .`

2. initializing
`pybabel init -i messages.pot -d lang -l fa`

3. Goto *lang/fa/LC_MESSAGES/messages.po* and add your translation to your messages.

4. compiling
`pybabel compile -d lang`

- ### FastAPI Babel Commands
Install click at first:
`pip install click`

Add this snippet to your code:

```python
...
babel.run_cli()
...
```
Now you can follow those parts mentioned above for the message extracting process.
**For more information you can check helpers of babel cli:
**
`python main.py --help`

#### Why FastAPI Babel Cli is recommended?
when you are creating an application at a production level where you will deploy it on a server you may not find the right directory and paths of babel domain and config files, but FastAPI Babel Cli will do it perfectly without any concern about that. you only need to specify **domain name**, **babel.cfg** and** localization directory **.

**NOTICE:** you never use it beside fastapi runner file line `main.py` or `run.py`, because uvicorn cli will not work anymore.

You have better separate a babel cli runner file beside of fastapi runner file, by the way, you will not overwhelm with failure at uvicorn cli.


## Using FastAPI Babel in an API




Fix patch:
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6769e21
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,160 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+cover/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+.pybuilder/
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+#   For a library or package, you might want to ignore these files since the code is
+#   intended to run in multiple environments; otherwise, check them in:
+# .python-version
+
+# pipenv
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
+#   install all needed dependencies.
+#Pipfile.lock
+
+# poetry
+#   Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
+#   This is especially recommended for binary packages to ensure reproducibility, and is more
+#   commonly ignored for libraries.
+#   https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
+#poetry.lock
+
+# pdm
+#   Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
+#pdm.lock
+#   pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
+#   in version control.
+#   https://pdm.fming.dev/#use-with-ide
+.pdm.toml
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# Cython debug symbols
+cython_debug/
+
+# PyCharm
+#  JetBrains specific template is maintained in a separate JetBrains.gitignore that can
+#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
+#  and can be added to the global gitignore or merged into this file.  For a more nuclear
+#  option (not recommended) you can uncomment the following to ignore the entire idea folder.
+#.idea/
\ No newline at end of file
diff --git a/README.md b/README.md
index b97227f..3ba00ad 100644
--- a/README.md
+++ b/README.md
@@ -1,1 +1,236 @@
-"# fastapi-babel" 
+![](https://user-images.githubusercontent.com/56755478/165474515-12392df4-a41c-4ed9-bed4-512f606caedc.png)
+
+
+# FastAPI BABEL
+Fastapi babel is a tool what supports i18n, l10n, date and time locales and all pybabel functionalities easily that integrated with fastapi framework.
+
+## Features:
+- **I18n** (Internationalization)
+- **l10n** (Localization)
+- **Date and time** locale
+- **Decimal, Number** locale
+- **Money and currency** locale converter
+- locale selector from **http header**
+
+## Support
+**Python:** 3.6 and later (tested against 3.6, 3.7, 3.8 and 3.9)
+**FastAPI**: 0.45.0 +
+**PyBabel**: All
+
+## Installation
+    pip install fastapi-babel
+
+# How to use FastAPI Babel?
+- Create main.py file:
+
+```python
+from fastapi_babel import Babel
+from fastapi_babel import BabelConfigs
+from fastapi_babel import _
+
+configs = BabelConfigs(
+    ROOT_DIR=__file__,
+    BABEL_DEFAULT_LOCALE="en",
+    BABEL_TRANSLATION_DIRECTORY="lang",
+)
+babel = Babel(configs=configs)
+    
+def main():
+    babel.locale = "en"
+    en_text = _("Hello World")
+    print(en_text)
+
+    babel.locale = "fa"
+    fa_text = _("Hello World")
+    print(fa_text)
+
+if __name__ == "__main__":
+    main()
+```
+
+- ### PyBabel Commands
+1. extracting
+`pybabel extract -F babel.cfg -o messages.pot .`
+
+2. initializing
+`pybabel init -i messages.pot -d lang -l fa`
+
+3. Goto *lang/fa/LC_MESSAGES/messages.po* and add your translation to your messages.
+
+4. compiling
+`pybabel compile -d lang`
+
+- ### FastAPI Babel Commands
+Install click at first:
+`pip install click`
+
+Add this snippet to your code:
+
+```python
+...
+babel.run_cli()
+...
+```
+Now you can follow those part of mentioned above for message extracting process.
+**For more information your can check helpers of babel cli:
+**
+`python main.py --help`
+
+#### Why FastAPI Babel Cli is recommanded ?
+when you are creating application in a production level where you will deploy it on a server you may not found the right directory and paths of babel domain and config files, but FastAPI Babel Cli will do it perfectly without any concern about that. you only need to specify **domain name**, **babel.cfg** and** localization directory **.
+
+**NOTICE:** you never use it beside of fastapi runner file line `main.py` or `run.py`, because uvicorn cli will not work anymore.
+
+You have better to seperate a babel cli runner file beside of fastapi runner file, by the way you will not overwhelm with failure at uvicorn cli.
+
+
+[========]
+
+## Using FastAPI Babel in an API
+First of all we have to extract, translate and compile the messages, so follow the steps.
+
+Notice: first of all you should create a babel config file **babel.cfg** in project root or where you want to run cli's.
+
+*babel.cfg*
+
+    [python: **.py]
+
+
+- create file `babel.py` and write the code below.
+
+```python
+from fastapi_babel import Babel
+from fastapi_babel import BabelConfigs
+
+configs = BabelConfigs(
+    ROOT_DIR=__file__,
+    BABEL_DEFAULT_LOCALE="en",
+    BABEL_TRANSLATION_DIRECTORY="lang",
+)
+babel = Babel(configs=configs)
+
+if __name__ == "__main__":
+    babel.run_cli()
+```
+- extract messages with following command
+
+`python3 babel.py extract -d/--dir {watch_dir}`
+
+**Notice: ** watch_dir can be your project directory or messages you want to extract that.
+
+- add your own langauge locale directory such as fa by following commands.
+
+`python3 babel.py init -l fa`
+
+- go to ./lang/Fa/.po and add your translations.
+- compile all locale directorties.
+`python3 babel.py compile`
+
+```python
+from fastapi import FastAPI, Request
+from fastapi_babel import _
+from fastapi_babel.middleware import InternationalizationMiddleware as I18nMiddleware
+from .babel import babel
+
+app = FastAPI()
+app.add_middleware(I18nMiddleware, babel=babel)
+
+@app.get("/items/{id}", response_class=HTMLResponse)
+async def read_item(request: Request, id: str):
+    return id + _("Hello World")
+
+```
+
+- Now you can control your translation langauge from header of request and locale code. the meant locale header param is **Accept-Laguage **.
+
+Screenshot:
+[![Screenshot 1](https://user-images.githubusercontent.com/56755478/169701538-8f893d0e-fd09-4004-8e8d-5e045a1d588a.png "Screenshot 1")](https://user-images.githubusercontent.com/56755478/169701538-8f893d0e-fd09-4004-8e8d-5e045a1d588a.png "Screenshot 1")
+
+### How to use Jinja In FastAPI Babel
+
+- Add jinja extension to **babel.cfg**
+
+
+```xml
+[python: **.py] 
+extensions=jinja2.ext.autoescape,jinja2.ext.with_
+```
+
+
+*main.py*
+
+```python
+from fastapi import FastAPI, Request
+
+from fastapi_babel import Babel
+from fastapi_babel import BabelConfigs
+from fastapi_babel import _
+from fastapi_babel.middleware import InternationalizationMiddleware as I18nMiddleware
+
+from fastapi.responses import HTMLResponse
+from fastapi.staticfiles import StaticFiles
+from fastapi.templating import Jinja2Templates
+
+templates = Jinja2Templates(directory="templates")
+configs = BabelConfigs(
+    ROOT_DIR=__file__,
+    BABEL_DEFAULT_LOCALE="en",
+    BABEL_TRANSLATION_DIRECTORY="lang",
+)
+babel = Babel(configs=configs)
+babel.install_jinja(templates)
+
+app = FastAPI()
+app.add_middleware(I18nMiddleware, babel=babel)
+app.mount("/static", StaticFiles(directory="static"), name="static")
+
+@app.get("/items/{id}", response_class=HTMLResponse)
+async def read_item(request: Request, id: str):
+    return templates.TemplateResponse("item.html", {"request": request, "id": id})
+```
+
+*index.html*
+
+```html
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <h1>{{_("Hello World")}}</h1>
+</body>
+</html>
+```
+
+
+- Repeat all steps that we explained above for extracting messages, ...
+
+
+## Authors
+
+- [@Parsa Pourmhammad](https://github.com/Legopapurida)
+
+
+## Contributing
+
+Contributions are always welcome!
+
+See `contributing.md` for ways to get started.
+
+Please adhere to this project's `code of conduct`.
+
+
+## Feedback
+
+If you have any feedback, please reach out to us at parsapourmohammad@gmail.com
+
+
+## Support
+
+For support, email parsapourmohammad1999@gmail.com.
+
+
diff --git a/examples/with_jinja/babel.cfg b/examples/with_jinja/babel.cfg
new file mode 100644
index 0000000..c515dc4
--- /dev/null
+++ b/examples/with_jinja/babel.cfg
@@ -0,0 +1,2 @@
+[python: **.py]
+extensions=jinja2.ext.autoescape,jinja2.ext.with_
\ No newline at end of file
diff --git a/examples/full.py b/examples/with_jinja/full.py
similarity index 100%
rename from examples/full.py
rename to examples/with_jinja/full.py
diff --git a/examples/with_jinja/lang/fa/LC_MESSAGES/messages.mo b/examples/with_jinja/lang/fa/LC_MESSAGES/messages.mo
new file mode 100644
index 0000000..abc6f7b
Binary files /dev/null and b/examples/with_jinja/lang/fa/LC_MESSAGES/messages.mo differ
diff --git a/examples/with_jinja/lang/fa/LC_MESSAGES/messages.po b/examples/with_jinja/lang/fa/LC_MESSAGES/messages.po
new file mode 100644
index 0000000..eb21e4a
--- /dev/null
+++ b/examples/with_jinja/lang/fa/LC_MESSAGES/messages.po
@@ -0,0 +1,24 @@
+# Persian translations for PROJECT.
+# Copyright (C) 2022 ORGANIZATION
+# This file is distributed under the same license as the PROJECT project.
+# FIRST AUTHOR <EMAIL@ADDRESS>, 2022.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PROJECT VERSION\n"
+"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
+"POT-Creation-Date: 2022-05-22 19:08+0430\n"
+"PO-Revision-Date: 2022-05-22 19:09+0430\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language: fa\n"
+"Language-Team: fa <LL@li.org>\n"
+"Plural-Forms: nplurals=1; plural=0\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel 2.9.1\n"
+
+#: examples/test1/main.py:22
+msgid "Hello World"
+msgstr "سلام دنیا"
+
diff --git a/examples/with_jinja/templates/item.html b/examples/with_jinja/templates/item.html
new file mode 100644
index 0000000..bf9f3a8
--- /dev/null
+++ b/examples/with_jinja/templates/item.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <h1>{{_("Hello World")}}</h1>
+</body>
+</html>
\ No newline at end of file
diff --git a/fastapi_babel/__init__.py b/fastapi_babel/__init__.py
index 8fb6c49..2846daa 100644
--- a/fastapi_babel/__init__.py
+++ b/fastapi_babel/__init__.py
@@ -3,6 +3,6 @@
 from .core import _
 from .properties import RootConfigs as BabelConfigs
 
-__version__ = "0.0.1"
+__version__ = "0.0.3"
 __author__ = "papuridalego@gmail.com"
 __all__ = ["Babel", "BabelCli", "BabelConfigs", "_"]
\ No newline at end of file
diff --git a/fastapi_babel/__pycache__/__init__.cpython-39.pyc b/fastapi_babel/__pycache__/__init__.cpython-39.pyc
new file mode 100644
index 0000000..33e22ad
Binary files /dev/null and b/fastapi_babel/__pycache__/__init__.cpython-39.pyc differ
diff --git a/fastapi_babel/__pycache__/core.cpython-39.pyc b/fastapi_babel/__pycache__/core.cpython-39.pyc
new file mode 100644
index 0000000..b41a1c8
Binary files /dev/null and b/fastapi_babel/__pycache__/core.cpython-39.pyc differ
diff --git a/fastapi_babel/__pycache__/helpers.cpython-39.pyc b/fastapi_babel/__pycache__/helpers.cpython-39.pyc
new file mode 100644
index 0000000..2890a1b
Binary files /dev/null and b/fastapi_babel/__pycache__/helpers.cpython-39.pyc differ
diff --git a/fastapi_babel/__pycache__/middleware.cpython-39.pyc b/fastapi_babel/__pycache__/middleware.cpython-39.pyc
new file mode 100644
index 0000000..941de3d
Binary files /dev/null and b/fastapi_babel/__pycache__/middleware.cpython-39.pyc differ
diff --git a/fastapi_babel/__pycache__/properties.cpython-39.pyc b/fastapi_babel/__pycache__/properties.cpython-39.pyc
new file mode 100644
index 0000000..c911060
Binary files /dev/null and b/fastapi_babel/__pycache__/properties.cpython-39.pyc differ
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..fa7093a
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,3 @@
+[build-system]
+requires = ["setuptools>=42"]
+build-backend = "setuptools.build_meta"
\ No newline at end of file
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..3e1de76
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,85 @@
+[metadata]
+name = fastapi-babel
+version = attr: fastapi_babel.__version__
+url = https://github.com/Anbarryprojects/fastapi-babel
+project_urls =
+    Documentation = https://github.com/Anbarryprojects/fastapi-babel
+    Source Code = https://github.com/Anbarryprojects/fastapi-babel
+    Issue Tracker = https://github.com/Anbarryprojects/fastapi-babel/issues/
+license = MIT
+author = Parsa Pourmohammad
+author_email = parsapourmohammad1999@gmail.com
+maintainer = Anbarryprojects
+description = FastAPI babel support pybable tools like translation of text, formatting of dates, times and numbers, and time zones.
+long_description = file: README.md
+long_description_content_type = text/markdown
+classifiers =
+    Development Status :: 5 - Production/Stable
+    Environment :: Web Environment
+    Framework :: FastAPI
+    Intended Audience :: Developers
+    Topic :: Internet :: WWW/HTTP :: Dynamic Content
+    Topic :: Software Development :: Libraries :: Application Frameworks
+    Programming Language :: Python :: 3
+    License :: OSI Approved :: MIT License
+    Operating System :: OS Independent
+
+[options]
+packages = find:
+# package_dir = = fastapi_babel
+include_package_data = True
+python_requires = >= 3.7
+# Dependencies are in setup.py for GitHub's dependency graph.
+
+[options.packages.find]
+where = fastapi_babel
+
+[flake8]
+# B = bugbear
+# E = pycodestyle errors
+# F = flake8 pyflakes
+# W = pycodestyle warnings
+# B9 = bugbear opinions
+# ISC = implicit str concat
+select = B, E, F, W, B9, ISC
+ignore =
+    # slice notation whitespace, invalid
+    E203
+    # import at top, too many circular import fixes
+    E402
+    # line length, handled by bugbear B950
+    E501
+    # bare except, handled by bugbear B001
+    E722
+    # bin op line break, invalid
+    W503
+# up to 88 allowed by bugbear B950
+max-line-length = 80
+per-file-ignores =
+    # __init__ exports names
+    fastapi_babel/__init__.py: F401
+
+[mypy]
+files = fastapi_babel
+python_version = 3.7
+show_error_codes = True
+allow_redefinition = True
+disallow_subclassing_any = True
+# disallow_untyped_calls = True
+# disallow_untyped_defs = True
+# disallow_incomplete_defs = True
+no_implicit_optional = True
+local_partial_types = True
+# no_implicit_reexport = True
+strict_equality = True
+warn_redundant_casts = True
+warn_unused_configs = True
+warn_unused_ignores = True
+# warn_return_any = True
+# warn_unreachable = True
+
+[mypy-click.*]
+ignore_missing_imports = True
+
+[mypy-jinja.*]
+ignore_missing_imports = True
\ No newline at end of file
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..984ad2b
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,13 @@
+from setuptools import setup, find_packages
+
+# Metadata goes in setup.cfg. These are here for GitHub's dependency graph.
+setup(
+    name="fastapi-babel",
+    packages=find_packages(),
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=[
+        'fastapi',
+        'uvicorn'
+    ],
+)
\ No newline at end of file


Test patch:
diff --git a/examples/test1/__pycache__/main.cpython-39.pyc b/examples/test1/__pycache__/main.cpython-39.pyc
new file mode 100644
index 0000000..a1dc99c
Binary files /dev/null and b/examples/test1/__pycache__/main.cpython-39.pyc differ
diff --git a/examples/test1/babel.cfg b/examples/test1/babel.cfg
new file mode 100644
index 0000000..1d15bb3
--- /dev/null
+++ b/examples/test1/babel.cfg
@@ -0,0 +1,1 @@
+[python: **.py]
\ No newline at end of file
diff --git a/examples/test1/lang/fa/LC_MESSAGES/messages.mo b/examples/test1/lang/fa/LC_MESSAGES/messages.mo
new file mode 100644
index 0000000..abc6f7b
Binary files /dev/null and b/examples/test1/lang/fa/LC_MESSAGES/messages.mo differ
diff --git a/examples/test1/lang/fa/LC_MESSAGES/messages.po b/examples/test1/lang/fa/LC_MESSAGES/messages.po
new file mode 100644
index 0000000..eb21e4a
--- /dev/null
+++ b/examples/test1/lang/fa/LC_MESSAGES/messages.po
@@ -0,0 +1,24 @@
+# Persian translations for PROJECT.
+# Copyright (C) 2022 ORGANIZATION
+# This file is distributed under the same license as the PROJECT project.
+# FIRST AUTHOR <EMAIL@ADDRESS>, 2022.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PROJECT VERSION\n"
+"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
+"POT-Creation-Date: 2022-05-22 19:08+0430\n"
+"PO-Revision-Date: 2022-05-22 19:09+0430\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language: fa\n"
+"Language-Team: fa <LL@li.org>\n"
+"Plural-Forms: nplurals=1; plural=0\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel 2.9.1\n"
+
+#: examples/test1/main.py:22
+msgid "Hello World"
+msgstr "سلام دنیا"
+
diff --git a/examples/test1/main.py b/examples/test1/main.py
new file mode 100644
index 0000000..99a0a5d
--- /dev/null
+++ b/examples/test1/main.py
@@ -0,0 +1,27 @@
+from fastapi import FastAPI, Request
+
+from fastapi_babel import Babel
+from fastapi_babel import BabelConfigs
+from fastapi_babel import _
+from fastapi_babel.middleware import (
+    InternationalizationMiddleware as I18nMiddleware
+    )
+
+
+configs = BabelConfigs(
+    ROOT_DIR=__file__,
+    BABEL_DEFAULT_LOCALE="en",
+    BABEL_TRANSLATION_DIRECTORY="lang",
+)
+babel = Babel(configs=configs)
+
+app = FastAPI()
+app.add_middleware(I18nMiddleware, babel=babel)
+
+@app.get("/items/{id}")
+async def read_item(request: Request, id: str):
+    return {
+        "id": id, 
+        "message": _("Hello World"), 
+        "locale": request.headers.get("Accept-Language")
+        }
\ No newline at end of file