Commit ee966c12 authored by Serge S. Koval's avatar Serge S. Koval

Doc updates

parent 2aee0041
...@@ -9,6 +9,7 @@ Flask-Admin is simple and extensible administrative interface framework for `Fla ...@@ -9,6 +9,7 @@ Flask-Admin is simple and extensible administrative interface framework for `Fla
quickstart quickstart
django_migration django_migration
templates templates
localization
tips tips
db db
form_rules form_rules
......
Localization
============
Flask-Admin uses the `Flask-BabelEx <http://github.com/mrjoes/flask-babelex/>`_ package to handle translations.
Flask-BabelEx is a fork of Flask-Babel with following features:
1. It is API-compatible with Flask-Babel
2. It allows distribution of translations with Flask extensions
3. Much more configurable
If Flask-Admin can not import Flask-BabelEx, it disables localization support completely.
How to enable localization
--------------------------
1. Initialize Flask-BabelEx by creating instance of `Babel` class::
from flask import app
from flask.ext.babelex import Babel
app = Flask(__name__)
babel = Babel(app)
2. Create locale selector function::
@babel.localeselector
def get_locale():
# Put your logic here. Application can store locale in
# user profile, cookie, session, etc.
return 'en'
3. Initialize Flask-Admin as usual.
You can check `babel` example to see localization in action. To change locale, add *?en=<locale name>* to the URL. For example, URL
can look like: `http://localhost:5000/admin/userview/?lang=fr <http://localhost:5000/admin/userview/?lang=fr>`_.
...@@ -64,7 +64,7 @@ if __name__ == '__main__': ...@@ -64,7 +64,7 @@ if __name__ == '__main__':
# Create admin # Create admin
admin = admin.Admin(app, 'Simple Models') admin = admin.Admin(app, 'Simple Models')
admin.locale_selector(get_locale) #admin.locale_selector(get_locale)
# Add views # Add views
admin.add_view(sqla.ModelView(User, db.session)) admin.add_view(sqla.ModelView(User, db.session))
......
...@@ -476,9 +476,6 @@ class Admin(object): ...@@ -476,9 +476,6 @@ class Admin(object):
# Add predefined index view # Add predefined index view
self.add_view(self.index_view) self.add_view(self.index_view)
# Localizations
self.locale_selector_func = None
# Register with application # Register with application
if app is not None: if app is not None:
self._init_extension() self._init_extension()
...@@ -507,37 +504,6 @@ class Admin(object): ...@@ -507,37 +504,6 @@ class Admin(object):
""" """
self._menu_links.append(link) self._menu_links.append(link)
def locale_selector(self, f):
"""
Installs a locale selector for the current ``Admin`` instance.
Example::
def admin_locale_selector():
return request.args.get('lang', 'en')
admin = Admin(app)
admin.locale_selector(admin_locale_selector)
It is also possible to use the ``@admin`` decorator::
admin = Admin(app)
@admin.locale_selector
def admin_locale_selector():
return request.args.get('lang', 'en')
Or by subclassing the ``Admin``::
class MyAdmin(Admin):
def locale_selector(self):
return request.args.get('lang', 'en')
"""
if self.locale_selector_func is not None:
raise Exception(u'Can not add locale_selector second time.')
self.locale_selector_func = f
def _add_view_to_menu(self, view): def _add_view_to_menu(self, view):
""" """
Add a view to the menu tree Add a view to the menu tree
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment