Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
ee966c12
Commit
ee966c12
authored
Oct 20, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doc updates
parent
2aee0041
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
35 deletions
+38
-35
index.rst
doc/index.rst
+1
-0
localization.rst
doc/localization.rst
+36
-0
simple.py
examples/babel/simple.py
+1
-1
base.py
flask_admin/base.py
+0
-34
No files found.
doc/index.rst
View file @
ee966c12
...
@@ -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
...
...
doc/localization.rst
0 → 100644
View file @
ee966c12
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>`_.
examples/babel/simple.py
View file @
ee966c12
...
@@ -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
))
...
...
flask_admin/base.py
View file @
ee966c12
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment