From 598535b24a8f2ce290dfda9842fb063e41c4770e Mon Sep 17 00:00:00 2001 From: asciimoo Date: Wed, 22 Jan 2014 00:15:23 +0100 Subject: [PATCH] [mod] ui localization init - new dependency: flask-babel --- requirements.txt | 1 + searx/webapp.py | 14 ++++++++++++-- setup.py | 1 + versions.cfg | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2ff135f16..0f69bc883 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ flask +flask-babel grequests lxml pyyaml diff --git a/searx/webapp.py b/searx/webapp.py index 7bb9f0c8d..e042443b4 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -21,14 +21,17 @@ import json import cStringIO import os -from searx import settings from flask import Flask, request, render_template from flask import url_for, Response, make_response, redirect +from flask import send_from_directory + +from searx import settings from searx.engines import search, categories, engines, get_engines_stats from searx.utils import UnicodeWriter -from flask import send_from_directory from searx.utils import highlight_content, html_to_text +from flask.ext.babel import Babel + app = Flask( __name__, @@ -38,6 +41,8 @@ app = Flask( app.secret_key = settings['server']['secret_key'] +babel = Babel(app) + #TODO configurable via settings.yml favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud', 'twitter', 'stackoverflow', 'github'] @@ -56,6 +61,11 @@ opensearch_xml = ''' ''' +@babel.localeselector +def get_locale(): + return request.accept_languages.best_match(settings['languages'].keys()) + + def get_base_url(): if settings['server']['base_url']: hostname = settings['server']['base_url'] diff --git a/setup.py b/setup.py index ed18cd99a..64c317a9c 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ setup( zip_safe=False, install_requires=[ 'flask', + 'flask-babel', 'grequests', 'lxml', 'pyyaml', diff --git a/versions.cfg b/versions.cfg index dd1b610d1..906a69908 100644 --- a/versions.cfg +++ b/versions.cfg @@ -1,5 +1,6 @@ [versions] Flask = 0.10.1 +Flask-Babel = 0.9 Jinja2 = 2.7.2 MarkupSafe = 0.18 WebOb = 1.3.1