Commits

Anonymous committed 3b6ec5a

Use flask "before_request" feature to extract the language from the request.

Comments (0)

Files changed (1)

     app.languages[language] = t
 app.languages["en"] = NullTranslations()
 
-def extract_request_language(func):
-	def innerfunc(*args, **kwargs):
-		"""Extracts the preferred language of the browser from the request."""
-		header_value = request.headers.get("Accept-Language")
-		language_weights = header_value.split(",")
-		request.translation = app.languages["en"]
-		for language_weight in language_weights:
-			language = language_weight.split(";q=")[0].replace("-", "_")
-			if language in app.languages:
-				request.translation = app.languages[language]
-				print "language:", language
-				break
-		return func(*args, **kwargs)
-	innerfunc.__name__ = func.__name__
-	return innerfunc
+def extract_request_language():
+    """Extracts the preferred language of the browser from the request."""
+    header_value = request.headers.get("Accept-Language")
+    language_weights = header_value.split(",")
+    request.translation = app.languages["en"]
+    for language_weight in language_weights:
+        language = language_weight.split(";q=")[0].replace("-", "_")
+        if language in app.languages:
+            request.translation = app.languages[language]
+            break
 
 def needs_login(func):
     def innerfunc(*args, **kwargs):
     return redirect(url_for("index"))
 
 @app.route("/create_game", methods=['GET', 'POST'])
-@extract_request_language
 @needs_login
 def create_game(): # XXX check for at most 10 sets
     if request.method == 'POST':
 def before_request():
     if "username" in session and session["username"] not in app.users:
         app.users[session["username"]] = {"games": {}}
+    extract_request_language()
 
 
 def restore_game(filename):