Skip to content

Commit f6d20cc

Browse files
authored
Merge pull request #4 from Anbarryprojects/development-v0
#2 added project to pypi
2 parents 03be24c + c6f9c86 commit f6d20cc

File tree

20 files changed

+352
-1
lines changed

20 files changed

+352
-1
lines changed

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/
877 Bytes
Binary file not shown.

examples/test1/babel.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[python: **.py]
482 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Persian translations for PROJECT.
2+
# Copyright (C) 2022 ORGANIZATION
3+
# This file is distributed under the same license as the PROJECT project.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2022.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: PROJECT VERSION\n"
9+
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10+
"POT-Creation-Date: 2022-05-22 19:08+0430\n"
11+
"PO-Revision-Date: 2022-05-22 19:09+0430\n"
12+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13+
"Language: fa\n"
14+
"Language-Team: fa <LL@li.org>\n"
15+
"Plural-Forms: nplurals=1; plural=0\n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=utf-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Generated-By: Babel 2.9.1\n"
20+
21+
#: examples/test1/main.py:22
22+
msgid "Hello World"
23+
msgstr "سلام دنیا"
24+

examples/test1/main.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from fastapi import FastAPI, Request
2+
3+
from fastapi_babel import Babel
4+
from fastapi_babel import BabelConfigs
5+
from fastapi_babel import _
6+
from fastapi_babel.middleware import (
7+
InternationalizationMiddleware as I18nMiddleware
8+
)
9+
10+
11+
configs = BabelConfigs(
12+
ROOT_DIR=__file__,
13+
BABEL_DEFAULT_LOCALE="en",
14+
BABEL_TRANSLATION_DIRECTORY="lang",
15+
)
16+
babel = Babel(configs=configs)
17+
18+
app = FastAPI()
19+
app.add_middleware(I18nMiddleware, babel=babel)
20+
21+
@app.get("/items/{id}")
22+
async def read_item(request: Request, id: str):
23+
return {
24+
"id": id,
25+
"message": _("Hello World"),
26+
"locale": request.headers.get("Accept-Language")
27+
}

examples/with_jinja/babel.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[python: **.py]
2+
extensions=jinja2.ext.autoescape,jinja2.ext.with_
File renamed without changes.
482 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Persian translations for PROJECT.
2+
# Copyright (C) 2022 ORGANIZATION
3+
# This file is distributed under the same license as the PROJECT project.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2022.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: PROJECT VERSION\n"
9+
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10+
"POT-Creation-Date: 2022-05-22 19:08+0430\n"
11+
"PO-Revision-Date: 2022-05-22 19:09+0430\n"
12+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13+
"Language: fa\n"
14+
"Language-Team: fa <LL@li.org>\n"
15+
"Plural-Forms: nplurals=1; plural=0\n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=utf-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Generated-By: Babel 2.9.1\n"
20+
21+
#: examples/test1/main.py:22
22+
msgid "Hello World"
23+
msgstr "سلام دنیا"
24+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<h1>{{_("Hello World")}}</h1>
11+
</body>
12+
</html>

fastapi_babel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
from .core import _
44
from .properties import RootConfigs as BabelConfigs
55

6-
__version__ = "0.0.1"
6+
__version__ = "0.0.3"
77
__author__ = "papuridalego@gmail.com"
88
__all__ = ["Babel", "BabelCli", "BabelConfigs", "_"]
430 Bytes
Binary file not shown.
8.63 KB
Binary file not shown.
680 Bytes
Binary file not shown.
Binary file not shown.
989 Bytes
Binary file not shown.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=42"]
3+
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
[metadata]
2+
name = fastapi-babel
3+
version = attr: fastapi_babel.__version__
4+
url = https://github.com/Anbarryprojects/fastapi-babel
5+
project_urls =
6+
Documentation = https://github.com/Anbarryprojects/fastapi-babel
7+
Source Code = https://github.com/Anbarryprojects/fastapi-babel
8+
Issue Tracker = https://github.com/Anbarryprojects/fastapi-babel/issues/
9+
license = MIT
10+
author = Parsa Pourmohammad
11+
author_email = parsapourmohammad1999@gmail.com
12+
maintainer = Anbarryprojects
13+
description = FastAPI babel support pybable tools like translation of text, formatting of dates, times and numbers, and time zones.
14+
long_description = file: README.md
15+
long_description_content_type = text/markdown
16+
classifiers =
17+
Development Status :: 5 - Production/Stable
18+
Environment :: Web Environment
19+
Framework :: FastAPI
20+
Intended Audience :: Developers
21+
Topic :: Internet :: WWW/HTTP :: Dynamic Content
22+
Topic :: Software Development :: Libraries :: Application Frameworks
23+
Programming Language :: Python :: 3
24+
License :: OSI Approved :: MIT License
25+
Operating System :: OS Independent
26+
27+
[options]
28+
packages = find:
29+
# package_dir = = fastapi_babel
30+
include_package_data = True
31+
python_requires = >= 3.7
32+
# Dependencies are in setup.py for GitHub's dependency graph.
33+
34+
[options.packages.find]
35+
where = fastapi_babel
36+
37+
[flake8]
38+
# B = bugbear
39+
# E = pycodestyle errors
40+
# F = flake8 pyflakes
41+
# W = pycodestyle warnings
42+
# B9 = bugbear opinions
43+
# ISC = implicit str concat
44+
select = B, E, F, W, B9, ISC
45+
ignore =
46+
# slice notation whitespace, invalid
47+
E203
48+
# import at top, too many circular import fixes
49+
E402
50+
# line length, handled by bugbear B950
51+
E501
52+
# bare except, handled by bugbear B001
53+
E722
54+
# bin op line break, invalid
55+
W503
56+
# up to 88 allowed by bugbear B950
57+
max-line-length = 80
58+
per-file-ignores =
59+
# __init__ exports names
60+
fastapi_babel/__init__.py: F401
61+
62+
[mypy]
63+
files = fastapi_babel
64+
python_version = 3.7
65+
show_error_codes = True
66+
allow_redefinition = True
67+
disallow_subclassing_any = True
68+
# disallow_untyped_calls = True
69+
# disallow_untyped_defs = True
70+
# disallow_incomplete_defs = True
71+
no_implicit_optional = True
72+
local_partial_types = True
73+
# no_implicit_reexport = True
74+
strict_equality = True
75+
warn_redundant_casts = True
76+
warn_unused_configs = True
77+
warn_unused_ignores = True
78+
# warn_return_any = True
79+
# warn_unreachable = True
80+
81+
[mypy-click.*]
82+
ignore_missing_imports = True
83+
84+
[mypy-jinja.*]
85+
ignore_missing_imports = True

setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from setuptools import setup, find_packages
2+
3+
# Metadata goes in setup.cfg. These are here for GitHub's dependency graph.
4+
setup(
5+
name="fastapi-babel",
6+
packages=find_packages(),
7+
include_package_data=True,
8+
zip_safe=False,
9+
install_requires=[
10+
'fastapi',
11+
'uvicorn'
12+
],
13+
)

0 commit comments

Comments
 (0)