Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-05-04 12:37:48 (GMT)
committer Manuel QuiƱones <manuq@laptop.org>2012-05-04 13:43:21 (GMT)
commitebb013347fcf777401c589a557c50fae8b7eb7e7 (patch)
tree48420fe6b28f5daec1daeb5eb1f2deda45c93b40 /browser.py
parent8057d68dda9808485cd8e36482d01eff33e2e8c9 (diff)
Use user's LANG for search results SL #3445
When the user types a string that is not like an url, we use Google to search that string with the results in the language defined by LANG environment variable. Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Acked-by: Manuel QuiƱones <manuq@laptop.org> Acked-by: Simon Schampijer <simon@laptop.org>
Diffstat (limited to 'browser.py')
-rw-r--r--browser.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/browser.py b/browser.py
index 4fd3b1a..0334e6b 100644
--- a/browser.py
+++ b/browser.py
@@ -134,12 +134,18 @@ class TabbedView(BrowserNotebook):
pass
if soup_uri is None and not _NON_SEARCH_REGEX.match(url):
+ # Get the user's LANG to use as default language of
+ # the results
+ locale = os.environ.get('LANG', '')
+ language_location = locale.split('.', 1)[0].lower()
+ language = language_location.split('_')[0]
# If the string doesn't look like an URI, let's search it:
- url_search = \
- _('http://www.google.com/search?q=%s&ie=UTF-8&oe=UTF-8')
+ url_search = 'http://www.google.com/search?' \
+ 'q=%(query)s&ie=UTF-8&oe=UTF-8&hl=%(language)s'
query_param = Soup.form_encode_hash({'q': url})
# [2:] here is getting rid of 'q=':
- effective_url = url_search % query_param[2:]
+ effective_url = url_search % {'query': query_param[2:],
+ 'language': language}
else:
if has_web_scheme(url):
effective_url = url