From: Christopher Allan Webber Date: Sat, 15 Oct 2011 21:57:45 +0000 (-0500) Subject: Support for older webobs and newer webobs both in accept language mess :) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=471509197034e8aa3a2f4d3fa41e86212b543082;p=mediagoblin.git Support for older webobs and newer webobs both in accept language mess :) --- diff --git a/mediagoblin/tools/translate.py b/mediagoblin/tools/translate.py index f2990867..b99c4aa4 100644 --- a/mediagoblin/tools/translate.py +++ b/mediagoblin/tools/translate.py @@ -74,8 +74,17 @@ def get_locale_from_request(request): target_lang = request.session['target_lang'] # Pull the first acceptable language or English else: - target_lang = request.accept.best_match( - request.accept_language, 'en') + # WebOb recently changed how it handles determining best language. + # Here's a compromise commit that handles either/or... + if hasattr(request.accept_language, "best_matches"): + accept_lang_matches = request.accept_language.best_matches() + if accept_lang_matches: + target_lang = accept_lang_matches[0] + else: + target_lang = 'en' + else: + target_lang = request.accept.best_match( + request.accept_language, 'en') return locale_to_lower_upper(target_lang)