[mod] ui localization init - new dependency: flask-babel

This commit is contained in:
asciimoo 2014-01-22 00:15:23 +01:00
parent 7295df30e1
commit 598535b24a
4 changed files with 15 additions and 2 deletions

View File

@ -1,4 +1,5 @@
flask flask
flask-babel
grequests grequests
lxml lxml
pyyaml pyyaml

View File

@ -21,14 +21,17 @@ import json
import cStringIO import cStringIO
import os import os
from searx import settings
from flask import Flask, request, render_template from flask import Flask, request, render_template
from flask import url_for, Response, make_response, redirect 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.engines import search, categories, engines, get_engines_stats
from searx.utils import UnicodeWriter from searx.utils import UnicodeWriter
from flask import send_from_directory
from searx.utils import highlight_content, html_to_text from searx.utils import highlight_content, html_to_text
from flask.ext.babel import Babel
app = Flask( app = Flask(
__name__, __name__,
@ -38,6 +41,8 @@ app = Flask(
app.secret_key = settings['server']['secret_key'] app.secret_key = settings['server']['secret_key']
babel = Babel(app)
#TODO configurable via settings.yml #TODO configurable via settings.yml
favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud', favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
'twitter', 'stackoverflow', 'github'] 'twitter', 'stackoverflow', 'github']
@ -56,6 +61,11 @@ opensearch_xml = '''<?xml version="1.0" encoding="utf-8"?>
''' '''
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(settings['languages'].keys())
def get_base_url(): def get_base_url():
if settings['server']['base_url']: if settings['server']['base_url']:
hostname = settings['server']['base_url'] hostname = settings['server']['base_url']

View File

@ -30,6 +30,7 @@ setup(
zip_safe=False, zip_safe=False,
install_requires=[ install_requires=[
'flask', 'flask',
'flask-babel',
'grequests', 'grequests',
'lxml', 'lxml',
'pyyaml', 'pyyaml',

View File

@ -1,5 +1,6 @@
[versions] [versions]
Flask = 0.10.1 Flask = 0.10.1
Flask-Babel = 0.9
Jinja2 = 2.7.2 Jinja2 = 2.7.2
MarkupSafe = 0.18 MarkupSafe = 0.18
WebOb = 1.3.1 WebOb = 1.3.1