@@ -17,7 +17,7 @@ Install the extension from PyPi::
1717 $ pip install Flask-Babel
1818
1919Please 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
5764For 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
5966first time the babel extension needs the locale (locale code/ID) of the
6067current user it will call a :meth: `~Babel.localeselector ` function, and
6168the 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+
9199The 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
261268Save it as ``babel.cfg `` or something similar next to your application.
262269Then 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+
395404Low-Level API
396405`````````````
397406
0 commit comments