Skip to content

Commit

Permalink
Fixed unit tests for Flask-Babel 3
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Jan 17, 2023
1 parent 9a8a411 commit 547a784
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions examples/babel/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ class BabelForm(FlaskForm):
SECRET_KEY = "secret"
WTF_I18N_ENABLED = True

app = Flask(__name__)
app.config.from_object(__name__)

# config babel
babel = Babel(app)


@babel.localeselector
def get_locale():
"""how to get the locale is defined by you.
Expand All @@ -39,6 +32,13 @@ def get_locale():
return code


app = Flask(__name__)
app.config.from_object(__name__)

# config babel
babel = Babel(app, locale_selector=get_locale)


@app.route("/", methods=("GET", "POST"))
def index():
form = BabelForm()
Expand Down
5 changes: 2 additions & 3 deletions tests/test_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ def test_i18n(app, client):
except ImportError:
pytest.skip("Flask-Babel must be installed.")

babel = Babel(app)

@babel.localeselector
def get_locale():
return request.accept_languages.best_match(["en", "zh"], "en")

Babel(app, locale_selector=get_locale)

@app.route("/", methods=["POST"])
def index():
form = NameForm()
Expand Down

0 comments on commit 547a784

Please sign in to comment.