Ticket #3445: 0001-Use-user-s-LANG-for-search-results-SL-3445.patch

File 0001-Use-user-s-LANG-for-search-results-SL-3445.patch, 1.8 KB (added by humitos, 12 years ago)
  • browser.py

    From ab577e372f4ad9583ce5b0c76a03ef2c40bd2cfc Mon Sep 17 00:00:00 2001
    Message-Id: <ab577e372f4ad9583ce5b0c76a03ef2c40bd2cfc.1336135082.git.humitos@gmail.com>
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Fri, 4 May 2012 09:37:48 -0300
    Subject: [PATCH Browse v2] 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>
    ---
     browser.py |   12 +++++++++---
     1 files changed, 9 insertions(+), 3 deletions(-)
    
    diff --git a/browser.py b/browser.py
    index 6b744a3..bdea4b2 100644
    a b class TabbedView(BrowserNotebook): 
    134134                pass
    135135
    136136        if soup_uri is None and not _NON_SEARCH_REGEX.match(url):
     137            # Get the user's LANG to use as default language of
     138            # the results
     139            locale = os.environ.get('LANG', '')
     140            language_location = locale.split('.', 1)[0].lower()
     141            language = language_location.split('_')[0]
    137142            # If the string doesn't look like an URI, let's search it:
    138             url_search = \
    139                 _('http://www.google.com/search?q=%s&ie=UTF-8&oe=UTF-8')
     143            url_search = 'http://www.google.com/search?' \
     144                'q=%(query)s&ie=UTF-8&oe=UTF-8&hl=%(language)s'
    140145            query_param = Soup.form_encode_hash({'q': url})
    141146            # [2:] here is getting rid of 'q=':
    142             effective_url = url_search % query_param[2:]
     147            effective_url = url_search % {'query': query_param[2:],
     148                                          'language': language}
    143149        else:
    144150            if has_web_scheme(url):
    145151                effective_url = url