Skip to content

Commit

Permalink
Merge 1709c98 into 46f2829
Browse files Browse the repository at this point in the history
  • Loading branch information
slint committed Mar 5, 2020
2 parents 46f2829 + 1709c98 commit ee0de2b
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 23 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Expand Up @@ -10,8 +10,6 @@
notifications:
email: false

sudo: false

language: python

cache:
Expand All @@ -23,8 +21,8 @@ env:
- REQUIREMENTS=devel

python:
- "2.7"
- "3.5"
- "3.6"
- "3.7"

matrix:
fast_finish: true
Expand Down Expand Up @@ -56,5 +54,5 @@ deploy:
distributions: "compile_catalog sdist bdist_wheel"
on:
tags: true
python: "2.7"
python: "3.6"
condition: $REQUIREMENTS = release
9 changes: 7 additions & 2 deletions CHANGES.rst
Expand Up @@ -8,13 +8,18 @@
Changes
=======

Version 1.1.2 (released 2020-03-05)

- Bumps Flask-BabelEx support latest Flask/Werkzeug.
- Replaces Flask dependency with ``invenio-base``.

Version 1.1.1 (released 2018-12-12)

- Fix an incorrect JS import.
- Fix an incorrect JS import.

Version 1.1.0 (released 2018-11-06)

- Introduce webpack support.
- Introduce webpack support.

Version 1.0.0 (released 2018-03-23)

Expand Down
2 changes: 2 additions & 0 deletions examples/app.py
Expand Up @@ -46,6 +46,7 @@
from flask_babelex import lazy_gettext as _

from invenio_i18n import InvenioI18N
from invenio_i18n.views import create_blueprint_from_app

# Create Flask application
app = Flask(__name__)
Expand All @@ -55,6 +56,7 @@
I18N_LANGUAGES=[('da', _('Danish')), ('es', _('Spanish'))],
)
InvenioI18N(app)
app.register_blueprint(create_blueprint_from_app(app))


@app.route('/')
Expand Down
2 changes: 2 additions & 0 deletions invenio_i18n/__init__.py
Expand Up @@ -24,7 +24,9 @@
>>> app = Flask('myapp')
>>> app.config['I18N_LANGUAGES'] = [('cs', _('Czech')), ('da', _('Danish'))]
>>> from invenio_i18n import InvenioI18N
>>> from invenio_i18n.views import create_blueprint_from_app
>>> i18n = InvenioI18N(app)
>>> app.register_blueprint(create_blueprint_from_app(app))
You can now use the Flask-BabelEx localization features:
Expand Down
8 changes: 0 additions & 8 deletions invenio_i18n/ext.py
Expand Up @@ -109,14 +109,6 @@ def init_app(self, app):
if self.entry_point_group:
self.domain.add_entrypoint(self.entry_point_group)

# Register default routes if URL is set.
register_default_routes = app.config['I18N_SET_LANGUAGE_URL'] \
and app.config['I18N_LANGUAGES']
app.register_blueprint(
create_blueprint(register_default_routes=register_default_routes),
url_prefix=app.config['I18N_SET_LANGUAGE_URL']
)

# Register Jinja2 template filters for date formatting (Flask-Babel
# already installs other filters).
app.add_template_filter(filter_to_utc, name='toutc')
Expand Down
4 changes: 2 additions & 2 deletions invenio_i18n/version.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
# Copyright (C) 2015-2020 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -14,4 +14,4 @@

from __future__ import absolute_import, print_function

__version__ = '1.1.1'
__version__ = '1.1.2'
18 changes: 17 additions & 1 deletion invenio_i18n/views.py
Expand Up @@ -52,11 +52,12 @@ def set_lang(lang_code=None):
return redirect(target)


def create_blueprint(register_default_routes=True):
def create_blueprint(register_default_routes=True, url_prefix=None):
"""Create Invenio-I18N blueprint."""
blueprint = Blueprint(
'invenio_i18n',
__name__,
url_prefix=url_prefix,
template_folder='templates',
static_folder='static',
)
Expand All @@ -67,3 +68,18 @@ def create_blueprint(register_default_routes=True):
methods=['GET'])

return blueprint


def create_blueprint_from_app(app):
"""Create Invenio-I18N blueprint from a Flask application.
:params app: A Flask application.
:returns: Configured blueprint.
"""
# Register default routes if URL is set.
register_default_routes = app.config['I18N_SET_LANGUAGE_URL'] \
and app.config['I18N_LANGUAGES']
return create_blueprint(
register_default_routes=register_default_routes,
url_prefix=app.config['I18N_SET_LANGUAGE_URL'],
)
3 changes: 2 additions & 1 deletion requirements-devel.txt
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
# Copyright (C) 2015-2020 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

-e git+https://github.com/mrjoes/flask-babelex.git#egg=Flask-BabelEx
-e git+https://github.com/inveniosoftware/invenio-base.git#egg=invenio-base
10 changes: 6 additions & 4 deletions setup.py
Expand Up @@ -17,9 +17,9 @@
history = open('CHANGES.rst').read()

tests_require = [
'Flask-Login>=0.3.0',
'check-manifest>=0.25',
'coverage>=4.0',
'invenio-accounts[sqlite]>=1.1.3',
'invenio-assets>=1.0.0',
'isort>=4.3.0',
'pydocstyle>=1.0.0',
Expand All @@ -45,9 +45,8 @@
]

install_requires = [
'Flask>=0.11.1',
'Flask-BabelEx>=0.9.2',
'flask-webpackext>=1.0.0',
'invenio-base>=1.2.2',
'Flask-BabelEx>=0.9.4',
]

packages = find_packages()
Expand Down Expand Up @@ -79,6 +78,9 @@
'invenio_base.apps': [
'invenio_i18n = invenio_i18n:InvenioI18N',
],
'invenio_base.blueprints': [
'invenio_i18n = invenio_i18n.views:create_blueprint_from_app',
],
'invenio_i18n.translations': [
'messages = invenio_i18n',
],
Expand Down
3 changes: 3 additions & 0 deletions tests/test_views.py
Expand Up @@ -14,6 +14,7 @@
from flask_babelex import get_locale

from invenio_i18n import InvenioI18N
from invenio_i18n.views import create_blueprint_from_app


def test_lang_view(app):
Expand All @@ -24,6 +25,7 @@ def test_lang_view(app):
SECRET_KEY='CHANGEME',
)
InvenioI18N(app)
app.register_blueprint(create_blueprint_from_app(app))

@app.route("/")
def index():
Expand Down Expand Up @@ -65,6 +67,7 @@ def test_lang_view_redirect(app):
SECRET_KEY='CHANGEME',
)
InvenioI18N(app)
app.register_blueprint(create_blueprint_from_app(app))

@app.route("/page/")
def page():
Expand Down

0 comments on commit ee0de2b

Please sign in to comment.