wiki:Linux/Ubuntu/Firefox3ChangeGoogleSearchEngineCountry

Firefox Change Google Search Engine Country

The searchplugin in the top-right of the Firefox window has a drop-down list of search engines. The default URLs to search are specified in the firefox-3.0 package in the file /usr/lib/firefox-addons/searchplugins/google.xml. The default is the US-centric " http://google.com/search" for English language at least.

The file looks like this:

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
  <ShortName>Google</ShortName>
  <Description>Google Search</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&amp;client=firefox&amp;hl={moz:locale}&amp;q={searchTerms}"/>
  <Url type="text/html" method="GET" template="http://www.google.co.uk/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>
  <SearchForm>http://www.google.com/firefox</SearchForm>
</SearchPlugin>

Changing the default

The values that need changing are:

  • Url text/html template (and possibly additional Param values)
  • SearchForm
  • ShortName - Unique Firefox name for the search engine (can't have multiple occurances of "Google" in the list)
  • Description

First, obtain the URL of template of the search engine for the country you prefer. The way to do this is to do a manual search from the Google web search page of the country you prefer.

Let's take Spain as an example. The web search page is  http://www.google.es/. Do a manual search and copy the new address bar:

http://www.google.es/search?hl=es&q=Hol%C3%A1&btnG=Buscar+con+Google&meta=

The first part, http://www.google.es/search, is the replacement Url template You'll notice there's an additional parameter, hl=es, which looks to mean home language = español

Now check to see if there is a country-specific Firefox landing page. Take the web search page URL and add "firefox":

http://www.google.es/firefox

Yes, that works.

Now the google.xml file can be re-named google-es.xml and re-written thus:

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
  <ShortName>Google España</ShortName>
  <Description>Google España Buscar</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&amp;client=firefox&amp;hl=es&amp;q={searchTerms}"/>
  <Url type="text/html" method="GET" template="http://www.google.es/search">
    <Param name="q" value="{searchTerms}"/>
    <Param name="hl" value="es"/>
    <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}:es:{moz:official}"/>
    <MozParam name="client" condition="defaultEngine" trueValue="firefox-a" falseValue="firefox"/>
  </Url>
  <SearchForm>http://www.google.es/firefox</SearchForm>
</SearchPlugin>

You'll notice several instances where the home language (hl or {mozlocale}) was specified have been changed too. To make it clearer here are the lines that changed:

  <ShortName>Google España</ShortName>
  <Description>Google España Buscar</Description>
  <Url type="application/x-suggestions+json" method="GET" template="http://suggestqueries.google.com/complete/search?output=firefox&amp;client=firefox&amp;hl=es&amp;q={searchTerms}"/>
  <Url type="text/html" method="GET" template="http://www.google.es/search">
    <Param name="hl" value="es"/>
    <Param name="rls" value="{moz:distributionID}:es:{moz:official}"/>
  <SearchForm>http://www.google.es/firefox</SearchForm>

Save the new file to /usr/lib/firefox-addons/searchplugins/ and restart Firefox and it will be available to select in the drop-down list of search engines.