diff --git a/hiboo/__init__.py b/hiboo/__init__.py index 34b28e90b0e4b10a8760b708c8a9ecf31ef97a36..6aa69bb6550545d080ab18c1e8ca724fe4bbebdc 100644 --- a/hiboo/__init__.py +++ b/hiboo/__init__.py @@ -14,7 +14,7 @@ def create_app_from_config(config): config.init_app(app) models.db.init_app(app) utils.limiter.init_app(app) - utils.babel.init_app(app) + utils.translation.init_app(app) utils.login.init_app(app) utils.login.user_loader(models.User.get) utils.migrate.init_app(app, models.db) diff --git a/hiboo/translations/en/LC_MESSAGES/messages.po b/hiboo/translations/en_US/LC_MESSAGES/messages.po similarity index 100% rename from hiboo/translations/en/LC_MESSAGES/messages.po rename to hiboo/translations/en_US/LC_MESSAGES/messages.po diff --git a/hiboo/translations/fr/LC_MESSAGES/messages.po b/hiboo/translations/fr_FR/LC_MESSAGES/messages.po similarity index 100% rename from hiboo/translations/fr/LC_MESSAGES/messages.po rename to hiboo/translations/fr_FR/LC_MESSAGES/messages.po diff --git a/hiboo/translations/nl/LC_MESSAGES/messages.po b/hiboo/translations/nl_NL/LC_MESSAGES/messages.po similarity index 100% rename from hiboo/translations/nl/LC_MESSAGES/messages.po rename to hiboo/translations/nl_NL/LC_MESSAGES/messages.po diff --git a/hiboo/utils.py b/hiboo/utils.py index f24b72b13e22589b586b4d9837d7df1c70529170..c6ea608057bb707081c3e0e203808bec4e72725c 100644 --- a/hiboo/utils.py +++ b/hiboo/utils.py @@ -4,6 +4,7 @@ import flask_migrate import flask_babel import flask_limiter import flask_redis +import babel from werkzeug.contrib import fixers from werkzeug import routing @@ -100,12 +101,14 @@ limiter = flask_limiter.Limiter(key_func=lambda: current_user.id) # Application translation -babel = flask_babel.Babel() +translation = flask_babel.Babel() -@babel.localeselector +@translation.localeselector def get_locale(): - translations = list(map(str, babel.list_translations())) - return flask.request.accept_languages.best_match(translations) + return babel.negotiate_locale( + [l.replace('-', '_') for l in flask.request.accept_languages.values()], + list(map(str, translation.list_translations())) + ) # Data migrate