How to reset Google languages from Firefox search, manipulating the URL

The problem

I am English speaking, and prefer my Google search results to be from google.com rather than google.fr when from France. But each time I use the Firefox search box, from a French IP, Google redirects to the French site, and I mostly end up with French results, when I would prefer english results.

Here is what the search URL looks like when searching from Firefox:

http://www.google.fr/search?q=linux
   &ie=utf-8
   &oe=utf-8
   &aq=t
   &rls=com.ubuntu:en-US:official
   &client=firefox-a

This leads to French results, in this case the first one being the Wikipedia French page for Linux.

How to get English results?

Two parameters are related to languages: hl and lr. According to this Google page and this PDF document, hl controls the language for the interface of the Google page, and lr restricts the results to one or more languages.

So if I add hl=en in the query string, I get the english interface, as well as English results:

http://www.google.fr/search?q=linux
   &ie=utf-8
   &oe=utf-8
   &aq=t
   &rls=com.ubuntu:en-US:official
   &client=firefox-a
   &hl=en 

I then get this results page, the first result being the linux.org site, in English.

Similarly, if I add lr=lang_en in the query string, I get the english results, but with the interface in local language:

http://www.google.fr/search?q=linux
   &ie=utf-8
   &oe=utf-8
   &aq=t
   &rls=com.ubuntu:en-US:official
   &client=firefox-a
   &lr=lang_en 

I get this results page, the first result being the linux.org site, in English.

Weirdly enough. the results are almost the same with either parameters. Your mileage may vary.

Note that you can use hl and lr together, so to have have English results with a French interface, or French results with an English interface. Here are a few tests which show the effect of each of the language settings, and describe the results that you get from google.fr:
- hl=en: Results and interface in English, same as google.com
- lr=lang_en: Results in English, and interface in French
- hl=fr: Results and interface in French
- lr=lang_fr: Results and interface in French, same as above
- lr=lang_fr&hl=en: Results in French, and interface in English
- lr=lang_en&hl=fr: Results in English, and interface in French

How to do it?

The goal is to change Firefox default query string for Google searches.

According to Mozilla wiki, the query string is created as following:

q=MY+IMPORTANT+SEARCH : Search term
ie=utf-8 : Input encoding
oe=utf-8 : Output encoding
client=firefox-a : Used when Google ships as the default search engine
client=firefox : Used when Google ships as the non-default search engine
rls=org.mozilla:en-US:official : Will vary based on locale
aq=t : Identifies the query as coming from a suggest-enabled searchbox

You can change these parameters, although it is rather hidden into Firefox. Under Linux, open the following file /usr/share/firefox/searchplugins/google.xml (it may also be /usr/lib/firefox-addons/searchplugins/google.xml, /usr/lib64/firefox-x.x.x/searchplugins/google.xml). In newer versions of Firefox, the xml file may be in a language subdirectory, for instance /usr/share/firefox/searchplugins/en-US/google.xml

<Url type="text/html" method="GET" template="http://www.google.com/search">
  <Param name="q" value="{searchTerms}"/>
  <Param name="ie" value="utf-8"/>
  <Param name="oe" value="utf-8"/>
  <Param name="aq" value="t"/>
  <!-- Dynamic parameters -->
  <Param name="rls" value="{moz:distributionID}:{moz:locale}:{moz:official}"/>
  <MozParam name="client" condition="defaultEngine" trueValue="firefox-a" falseValue="firefox"/>
</Url>

Simply add the following line in the list of parameters:

<Param name="hl" value="en"/>

Or if you prefer to use lr:

<Param name="lr" value="lang_en"/>

I prefer to use hl, which yields best results as far as I am concerned. However, lr has an important advantage: you can mix languages to retrieve results from pages in several languages. For instance, you can get English and German results if you set lr to lang_en|lang_de.

I guess you can also remove the parameters client, rls and aq, but I wouldn't recommend it. Some people say that the results change when the search is performed from Firefox search box, but keep in mind that the Mozilla Fundation receives some money from Google depending on the searches made from inside the Firefox search box. So...

Making it stick

Each time you'll update Firefox, you will have to re-apply your changes to the XML file. So it is generally easier to just duplicate the google.xml file as for instance google_en.xml. In the new XML file, add the hl parameter, and change the name of the search engine. Then, in Firefox, select your new search engine. Being a custom search engine, it will not be erased by an update of Firefox. Here below is my google_en.xml:

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Google EN</ShortName>
<Description>Google Search English</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAaRJREFUeNpiVIg5JRURw0A0YAHio943kYV%2B%2Ff33%2BdvvX7%2F%2FMjEx8nKycrGzwKXOiPKzICvdeezLhCV3jp15%2Bfv%2FX0YGhv8MDDxMX2qKTIw0RK10eYD6QYqATvoPBkt3f5K0W9Ew4fjTFz%2F%2Bw8Dm3W8UPeZxqFa%2BevsFyD0twgfVsOfkRxHrtfV9u5BVQ8Crd98%2FffkGYQM1QJ20%2FfSPv79eNxQGYfpSVJADmcvEAHbr7oOX2dj%2FERNKIA2%2F%2F%2Fz%2FxfCDhYVoDUDw5P6vf9%2B5iY0HVmZGQWm%2BN3fff%2Fn2k4eLHS739x%2FDiRs%2Ff%2F%2F5x8HO%2FOHzN3djfqgNjIwMgc6qzLx%2Fpy47j2zY%2Feff06tXhOUucgxeun33AUZGpHh4%2Bvo7t8EyIJqz%2FhpasD59%2B5dNrqdnznZIsEL9ICXCsWuBCwvTv%2FymS5PWPP32ExEALz%2F%2BB5r848cPCJcRaMP9xaYQzofPPzfuvrnj0Jst%2B5%2F8%2Bc4sLPeDkYlRgJc93VPE18NIXkYUmJYQSQMZ%2FP3379uPH7%2F%2F%2FEETBzqJ0WqLGvFpe2LCC4AAAwAyjg7ENzDDWAAAAABJRU5ErkJggg%3D%3D</Image>
<Url type="application/x-suggestions+json" method="GET" template="http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl={moz:locale}&q={searchTerms}"/>
<Url type="text/html" method="GET" template="http://www.google.com/search">
  <Param name="q" value="{searchTerms}"/>
  <Param name="ie" value="utf-8"/>
  <Param name="oe" value="utf-8"/>
  <Param name="aq" value="t"/>
  <Param name="hl" value="en"/>
  <!-- Dynamic parameters -->
  <Param name="rls" value="{moz:distributionID}:{moz:locale}:{moz:official}"/>
  <MozParam name="client" condition="defaultEngine" trueValue="firefox-a" falseValue="firefox"/>
</Url>
<SearchForm>http://www.google.com/firefox</SearchForm>
</SearchPlugin>

Anything else?

Michael sent me a few more tips.

You can use search plugins to add a word that you search for frequently together with other words. You can for instance use it to find sites about local stuff by adding +London.

<Param name="q" value="{searchTerms} +London"/>

You can use the setting as_qdr to search for recent pages. For instance, to get results from the past month only, add:

<Param name="as_qdr" value="1m" />

You'll save yourself a lot of time by adding the following, to give you 40 hits per pages:

<Param name="num" value="40"/>

If you're savvy about using tabs, you can get every search result to open in a new tab (I prefer the Tab Mix Plus extension):

<Param name="newwindow" value="1"/>

You can exclude an TLD (or only include it) using as_dt and as_sitesearch together. To exclude .info TLD, add:

<Param name="as_dt" value="e" />
<Param name="as_sitesearch" value="info" />
To include only .info TLD, add:

<Param name="as_dt" value="i" />
<Param name="as_sitesearch" value="info" />

With add-ons

Two Firefox add-ons can also force the language for Google results:

If you have any comments or other tips, email me!