Skip to content

Commit 118019a

Browse files
authored
Merge pull request #212 from python-babel/v2.1.0
v3.0.0
2 parents 5c06d08 + 76d55cb commit 118019a

18 files changed

+411
-307
lines changed

.bumpversion.cfg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[bumpversion]
2-
current_version = 2.0.0
2+
current_version = 3.0.0
33
commit = True
44
tag = True
55

6-
[bumpversion:file:setup.py]
6+
[bumpversion:file:pyproject.toml]
7+
search = 'version = "{current_version}"'
8+
replace = 'version = "{new_version}"'
79

810
[bumpversion:file:docs/conf.py]

.github/workflows/release.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
on:
2-
push:
3-
# Sequence of patterns matched against refs/tags
4-
tags:
5-
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
2+
release:
3+
types:
4+
- created
65

76
name: Release
87

@@ -21,15 +20,12 @@ jobs:
2120
with:
2221
python-version: 3.8
2322

24-
- name: Install python dependencies
25-
run: |
26-
python -m pip install --upgrade pip setuptools
27-
pip install wheel twine
23+
- name: Install Poetry
24+
uses: snok/install-poetry@v1
2825

2926
- name: Publishing
3027
env:
31-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
32-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
28+
PYPI_TOKEN: ${{ secrets.PYPI_PASSWORD }}
3329
run: |
34-
python setup.py sdist bdist_wheel
35-
twine upload dist/*
30+
poetry config pypi-token.pypi $PYPI_TOKEN
31+
poetry publish --build

.github/workflows/test.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,22 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
python-version: [3.7, 3.8, 3.9, pypy3.7]
13+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", pypy3.7]
1414

1515
steps:
16-
# Python needs to be setup before checkout to prevent files from being
17-
# left in the source tree. See setup-python/issues/106.
16+
- uses: actions/checkout@v3
17+
1818
- name: Set up Python ${{ matrix.python-version }}
1919
uses: actions/setup-python@v4
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222

23-
- uses: actions/checkout@v3
23+
- name: Install Poetry
24+
uses: snok/install-poetry@v1
2425

25-
- name: Installing python dependencies
26-
run: |
27-
python -m pip install --upgrade pip setuptools
28-
pip install -e '.[dev]'
26+
- name: Installing
27+
run: poetry install --no-interaction
2928

3029
- name: Running tests
3130
run: |
32-
pytest
31+
poetry run pytest --cov=flask_babel --cov-report=xml

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ docs/_build
88
.vscode
99
*.code-workspace
1010
venv
11+
poetry.lock
12+
.idea

CHANGELOG

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
v3.0.0
2+
3+
Major version bump as this version removes support for Python 3.5 and 3.6, along with multiple
4+
major breaking changes. Hope you've been following SemVer :)
5+
6+
- Dropped support for end-of-life Python 3.5 and 3.6, added tests for 3.10 and 3.11.
7+
- Fixes to documentation to address outdated links and settings (#204, 201)
8+
- Jinja version 3 or greater is now required (released 2021)
9+
- Removed Babel._date_formats, use the public Babel.date_formats instead.
10+
- list_translations() always returns the default locale, even if it does not exist. (#75)
11+
- Add lazy_npgettext() (#68)
12+
- Babel.locale_selector and Babel.timezone_selector no longer exist. They must be provided
13+
either when the Babel() object is created or when init_app() is called. This is to support
14+
having a single Babel object for multiple Flask apps (#107) as well as to simplify settings
15+
and multi-threaded state.
16+
- Most configuration options can be passed directly through init_app().

MANIFEST.in

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
![Tests](https://github.com/python-babel/flask-babel/workflows/Tests/badge.svg?branch=master)
44
[![PyPI](https://img.shields.io/pypi/v/flask-babel.svg?maxAge=2592000)](https://pypi.python.org/pypi/Flask-Babel)
55

6-
Implements i18n and l10n support for Flask. This is based on the Python
7-
[babel][] module as well as [pytz][] both of which are installed automatically
8-
for you if you install this library.
6+
Implements i18n and l10n support for Flask. This is based on the Python
7+
[babel][] and [pytz][] modules.
98

10-
# Documention
9+
## Documentation
1110

1211
The latest documentation is available [here][docs].
1312

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Armin Ronacher'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '2.0.0'
25+
release = '3.0.0'
2626

2727

2828
# -- General configuration ---------------------------------------------------

docs/index.rst

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Install the extension from PyPi::
1717
$ pip install Flask-Babel
1818

1919
Please note that Flask-Babel requires Jinja >=2.5. If you are using an
20-
older version you will have to upgrade or disable the Jinja support
20+
older version you will have to upgrade or disable the Jinja support
2121
(see configuration).
2222

2323

@@ -31,13 +31,12 @@ object after configuring the application::
3131
from flask_babel import Babel
3232

3333
app = Flask(__name__)
34-
app.config.from_pyfile('mysettings.cfg')
3534
babel = Babel(app)
3635

37-
To disable jinja support, include ``configure_jinja=False`` in the Babel
38-
constructor call. The babel object itself can be used to configure the babel support
39-
further. Babel has the following configuration values that can be used to
40-
change some internal defaults:
36+
To disable jinja support, include ``configure_jinja=False`` in the Babel
37+
constructor call. The babel object itself can be used to configure the babel
38+
support further. Babel has the following configuration values that can be used
39+
to change some internal defaults:
4140

4241
=============================== =============================================
4342
`BABEL_DEFAULT_LOCALE` The default locale to use if no locale
@@ -52,10 +51,18 @@ change some internal defaults:
5251
folders. Defaults to ``translations``.
5352
`BABEL_DOMAIN` The message domain used by the application.
5453
Defaults to ``messages``.
54+
55+
It can also be a semi-colon (``;``) separated
56+
string of different domains for each of the
57+
translation directories, eg::
58+
59+
BABEL_TRANSLATION_DIRECTORIES=/path/to/translations;/another/path/
60+
BABEL_DOMAINS=messages;myapp
61+
5562
=============================== =============================================
5663

5764
For more complex applications you might want to have multiple applications
58-
for different users which is where selector functions come in handy. The
65+
for different users which is where selector functions come in handy. The
5966
first time the babel extension needs the locale (locale code/ID) of the
6067
current user it will call a :meth:`~Babel.localeselector` function, and
6168
the first time the timezone is needed it will call a
@@ -71,7 +78,6 @@ Example selector functions::
7178

7279
from flask import g, request
7380

74-
@babel.localeselector
7581
def get_locale():
7682
# if a user is logged in, use the locale from the user settings
7783
user = getattr(g, 'user', None)
@@ -82,12 +88,14 @@ Example selector functions::
8288
# example. The best match wins.
8389
return request.accept_languages.best_match(['de', 'fr', 'en'])
8490

85-
@babel.timezoneselector
8691
def get_timezone():
8792
user = getattr(g, 'user', None)
8893
if user is not None:
8994
return user.timezone
9095

96+
app = Flask(__name__)
97+
babel = Babel(app, locale_selector=get_locale, timezone_selector=get_timezone)
98+
9199
The example above assumes that the current user is stored on the
92100
:data:`flask.g` object.
93101

@@ -256,7 +264,6 @@ this is what you want in there:
256264

257265
[python: **.py]
258266
[jinja2: **/templates/**.html]
259-
extensions=jinja2.ext.autoescape,jinja2.ext.with_
260267

261268
Save it as ``babel.cfg`` or something similar next to your application.
262269
Then it's time to run the `pybabel` command that comes with Babel to
@@ -392,6 +399,8 @@ Gettext Functions
392399

393400
.. autofunction:: lazy_pgettext
394401

402+
.. autofunction:: lazy_npgettext
403+
395404
Low-Level API
396405
`````````````
397406

0 commit comments

Comments
 (0)