Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

add i18n documentation #638

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Christophe Simonis
David Ignacio
Eric Butler
Eskil Heyn Olsen
Ingo Kleiber
Iuri de Silvio
Jay Goel
Jiri Kuncar
Expand Down
37 changes: 37 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Quick Start
- `Basic MongoEngine Application <#basic-mongoengine-application>`_
- `Basic Peewee Application <#basic-peewee-application>`_
- `Mail Configuration <#mail-configuration>`_
- `Localization Configuration <#localization-configuration>`_

Basic SQLAlchemy Application
=============================
Expand Down Expand Up @@ -367,3 +368,39 @@ the basic application code in the previous section::
To learn more about the various Flask-Mail settings to configure it to
work with your particular email server configuration, please see the
`Flask-Mail documentation <http://packages.python.org/Flask-Mail/>`_.


Localization Configuration
==========================

Flask-Security comes with translations for several languages. Localization is implemented via
`Flask-BabelEx <https://pythonhosted.org/Flask-BabelEx/>`_, a fork of the
`Flask-Babel <https://pythonhosted.org/Flask-Babel/>`_ package.

The following three step process will enable translations/i18n for a basic application:

1. Install Flask-BabelEx::

pip install flask-babelex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


2. Configure Flask-Security to use the correct I18N_DOMAIN::

app.config['SECURITY_I18N_DOMAIN'] = 'flask_security'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Please refer to the :doc:`configuration <configuration>` documentation for more information.

3. Initialize Flask-BabelEx and create a locale selector function::

from flask_babelex import Babel

# Create app
app = Flask(__name__)

# Initialize Flask-BabelEx
babel = Babel(app)
app.babel = babel

@babel.localeselector
def get_locale():
# Add your locale selection logic here
return 'de_De'