[dev-gnome-web] Add Babel configuration



commit 0d1c72cb1731e5b2c0512885748331bc5f1e433a
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date:   Thu Jan 28 12:06:53 2016 +0100

    Add Babel configuration

 babel.cfg        |    3 +++
 server/app.py    |   10 +++++++++-
 server/config.py |    1 +
 3 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/babel.cfg b/babel.cfg
new file mode 100644
index 0000000..58701bf
--- /dev/null
+++ b/babel.cfg
@@ -0,0 +1,3 @@
+[python: server/**.py]
+[jinja2: client/**.html]
+extensions=jinja2.ext.autoescape,jinja2.ext.with_
diff --git a/server/app.py b/server/app.py
index f12423b..aac4b4b 100644
--- a/server/app.py
+++ b/server/app.py
@@ -4,7 +4,8 @@ Contains the main Flask application.
 
 from os.path import abspath, dirname, join
 
-from flask import Flask
+from flask import Flask, request
+from flask_babel import Babel
 
 current_path = dirname(__file__)
 client_path = abspath(join(current_path, '..', 'client'))
@@ -14,3 +15,10 @@ app = Flask(__name__,
             static_folder=client_path,
             template_folder=client_path)
 app.config.from_object('server.config')
+
+babel = Babel(app)
+
+
+ babel localeselector
+def get_locale():
+    return request.accept_languages.best_match(app.config['LANGUAGES'])
diff --git a/server/config.py b/server/config.py
index a8dd49e..5e8ef1a 100644
--- a/server/config.py
+++ b/server/config.py
@@ -4,3 +4,4 @@ This file contains configuration options for the server side application.
 
 BABEL_DEFAULT_LOCALE = 'en'
 BABEL_DEFAULT_TIMEZONE = 'UTC'
+LANGUAGES = {'en'}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]