Skip to content

Commit

Permalink
[#3196] Add Flask-babel requirement, hook into Flask middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Aug 24, 2016
1 parent a802c13 commit c7677b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ckan/config/middleware/flask_app.py
Expand Up @@ -12,6 +12,7 @@
from werkzeug.exceptions import HTTPException
from werkzeug.routing import Rule

from flask_babel import Babel
from flask_debugtoolbar import DebugToolbarExtension

from paste.deploy.converters import asbool
Expand Down Expand Up @@ -133,6 +134,24 @@ def c_object():
'''
return dict(c=g)

# Babel
app.config[u'BABEL_TRANSLATION_DIRECTORIES'] = os.path.join(root, u'i18n')
# TODO: this relies on unpublished changes in flask-babel
app.config[u'BABEL_DOMAIN'] = 'ckan'

babel = Babel(app)

@babel.localeselector
def get_locale():
u'''
Return the value of the `CKAN_LANG` key of the WSGI environ,
set by the I18nMiddleware based on the URL.
If no value is defined, it defaults to `ckan.locale_default` or `en`.
'''
return request.environ.get(
u'CKAN_LANG',
config.get(u'ckan.locale_default', u'en'))

@app.route('/hello', methods=['GET'])
def hello_world():
return 'Hello World, this is served by Flask'
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Expand Up @@ -5,6 +5,7 @@ Beaker==1.8.0 # Needs to be pinned to a more up to date version than the Pylons
bleach==1.4.3
fanstatic==0.12
Flask==0.10.1
Flask-Babel==0.11.1
Jinja2==2.8
Markdown==2.6.6
ofs==0.4.2
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -11,6 +11,7 @@ bleach==1.4.3
decorator==4.0.6 # via pylons, sqlalchemy-migrate
fanstatic==0.12
Flask==0.10.1
Flask-Babel==0.11.1
FormEncode==1.3.0
html5lib==0.9999999 # via bleach
itsdangerous==0.24 # via flask
Expand Down

0 comments on commit c7677b9

Please sign in to comment.