<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jquery Archives - gj</title>
	<atom:link href="https://blog.gaiterjones.com/tag/jquery-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/tag/jquery-2/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Wed, 09 Nov 2011 11:53:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Magento Create a Customer Product Pop Up Message Based on Location / IP Address</title>
		<link>https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/</link>
					<comments>https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Wed, 09 Nov 2011 11:16:03 +0000</pubDate>
				<category><![CDATA[Country Specific]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Product Popup]]></category>
		<category><![CDATA[jquery]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=576</guid>

					<description><![CDATA[I had the requirement this week to provide a popup message to customers from a particular country viewing a particular product page in a Magento store. I initially thought of...<a class="more-link" href="https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="hang-2-column     alignnone" title="Magento Country Specific Product Popup" src="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup1.jpg" alt="Magento Country Specific Product Popup" width="247" height="186" />I had the requirement this week to provide a popup message to customers from a particular country viewing a particular product page in a Magento store.</p>
<p>I initially thought of detecting the browser language or using available PHP Geo IP tools. Detecting the browser language is a simple solution but does not necessarily mean the customer is physically in the country that the browser language is set to. I also thought that using a full blown Geo database would be overkill and too much of an overhead when performing lookups.</p>
<p>The simple solution was to match the customers IP address against the IP Allocation for the required country and create the Popup message when both product and IP Allocation match.</p>
<p>I used an <a href="http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/ " target="_blank">existing PHP function</a> capable of taking an array IP addresses in various formats and returning a true / false match against supplied address, and a simple Growl type jquery popup box function called <a href="http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/ " target="_blank">Gritter</a>..</p>
<p>First determine the IP addresses allocated to the country you want to target, you can obtain these from various websites e.g. <a href="http://www.ipaddresslocation.org/">http://www.ipaddresslocation.org</a></p>
<p>Download the PHP and Gritter jQuery files <a href="https://blog.gaiterjones.com/dev/extension.php?id=c4a40fd9c157a7ca9de7cc0852482ce1">here </a>and copy the Gritter folder to your magento /js folder.</p>
<p>Copy the php files to a suitable location on your system, they will be included from Magento. Open ip_allocation.php and paste in the range of addresses you want to use in the the array.</p>
<pre class="brush:php">&lt;?php

/*
 * ip__allocation.php
 *
 */

	$MyClient=FALSE;
	if (isset($_SERVER['REMOTE_ADDR']))
	{
		include 'ip_in_range.php';
		$clientIP=$_SERVER["REMOTE_ADDR"];
		$IPAllocation = array(
			'192.168.1.0-192.168.1.255',
			'192.168.2.0-192.168.2.255',
		);

			foreach ($IPAllocation as $addressRange) {

				if (ip_in_range($clientIP, $addressRange))
				{
					$MyClient=TRUE;
					break;
				}
			}
	}
?&gt;</pre>
<p>In the example our address ranges are 192.168.1.0-192.168.1.255 and 192.168.2.0-192.168.2.255. When you download the range of addresses from <a href="http://www.ipaddresslocation.org/">www.ipaddresslocation.org</a> you will have a list of perhaps hundreds of address ranges. Open them in Excel so that you can format them correctly for our PHP script. I.e. remove any unwanted spaces and add the quotes and comma so that you can just paste the addresses straight into the php array correctly formatted. i.e. <strong>&#8216;192.168.3.0-192.168.3.255&#8217;,</strong></p>
<p>Save the PHP file.</p>
<p>In Magento edit the head.phtml template file and add the following at the beginning of the file modifying the include path to point to the path and folder where you have save the files.</p>
<pre class="brush:applescript">// detect if client is from specific country based on IP and show popup on specific product page.
if (Mage::registry('current_product') &amp;&amp; Mage::registry('current_product')-&gt;getId() === "XXXX")
{
	include '/home/www/php/ip_allocation.php';
}
?&gt;</pre>
<p>This code will include our IP allocation PHP scripts if the current page is a product page and the product ID matches XXX, enter your product ID here for the product or products you want to match.</p>
<p>Further down in head.phtml we need to add the Gritter jQuery code. If you already are <a title="Automatic jQuery Translator for Magento" href="https://blog.gaiterjones.com/automatic-google-jquery-translator-for-magento/">using jQuery in your Magento shop</a> this should come after the getIncludes statement and you should remove the javascript links to the google jQuery source.</p>
<pre class="brush:php">&lt;?php if (Mage::registry('current_product')) : ?&gt;
&lt;?php if(Mage::registry('current_product')-&gt;getId() === "XXX"):?&gt;
&lt;?php if($MyClient): ?&gt;
&lt;link rel="stylesheet" type="text/css" href="/js/gritter/css/jquery.gritter.css" /&gt;
&lt;script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;google.load('jquery', '1.5');&lt;/script&gt;
&lt;script type="text/javascript" src="/js/gritter/js/jquery.gritter.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
jQuery(document).ready(function($){
	 $.gritter.add({
		// (string | mandatory) the heading of the notification
		title: '&lt;br /&gt;Are you a customer&lt;br /&gt;from the United Kingdom?&lt;br /&gt;',
		// (string | mandatory) the text inside the notification
		text: '&lt;br /&gt;&lt;br /&gt;You can save shipping costs and order our &lt;?php echo trim(Mage::registry('current_product')-&gt;getName())?&gt; directly from one of our partners, click &lt;a href="/partners?utm_source=Country&amp;utm_medium=Partners&amp;utm_campaign=MyCampaign"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt; for more information.&lt;br /&gt;&lt;br /&gt;',
		// (string | optional) the image to display on the left
		image: '/js/gritter/images/uk-flag.jpg',
		// (bool | optional) if you want it to fade out on its own or just sit there
		sticky: true
	 });}
 )
//]]&gt;
&lt;/script&gt;
&lt;?php endif ?&gt;
&lt;?php endif ?&gt;
&lt;?php endif ?&gt;</pre>
<p>Again we are checking for a match on a product page, and our specific product as well as a TRUE value for our IP address check returned by the variable $MyClient. When true, the Gritter jQeury code will be added to the page to create the popup box. You can see we are displaying a message for UK customers including a custom image.</p>
<p>Refresh your store cache and browse to the defined product page to test the code. You will need to add an entry for your current IP address in the allocation array to ensure a match if you are not in the country you are targeting!</p>
<figure id="attachment_584" aria-describedby="caption-attachment-584" style="width: 620px" class="wp-caption alignnone"><img fetchpriority="high" decoding="async" class="size-large wp-image-584" title="Magento Country Specific Product Popup" src="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2-620x343.jpg" alt="Magento Country Specific Product Popup" width="620" height="343" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2-620x343.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2-440x243.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-country-specific-popup2.jpg 844w" sizes="(max-width: 620px) 100vw, 620px" /><figcaption id="caption-attachment-584" class="wp-caption-text">Magento Country Specific Product Popup</figcaption></figure>
<p>&nbsp;</p>
<p>The Gritter example code is linking to a relatively old version of jQuery, in a Magento 1.3 shop this was no problem, in 1.6.1 I had to use a newer version.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-create-a-customer-product-pop-up-message-based-on-location/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>Automatic jQuery Translator for Magento</title>
		<link>https://blog.gaiterjones.com/automatic-google-jquery-translator-for-magento/</link>
					<comments>https://blog.gaiterjones.com/automatic-google-jquery-translator-for-magento/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Thu, 26 May 2011 10:21:57 +0000</pubDate>
				<category><![CDATA[Google Translation]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[translator]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=402</guid>

					<description><![CDATA[GOOGLE API DEPRECATED Google announced on the 26th of May 2011 (the day I blogged about this solution!) that the translation API used by the jQuery plugin is now deprecated and will...<a class="more-link" href="https://blog.gaiterjones.com/automatic-google-jquery-translator-for-magento/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<h1>GOOGLE API DEPRECATED</h1>
<p>Google <a href="http://code.google.com/apis/language/translate/overview.html">announced on the 26th of May 2011</a> (the day I blogged about this solution!) that the translation API used by the jQuery plugin is now <em><strong>deprecated </strong></em>and will be <em>shut off completely </em>in December 2011. The author of the jQuery plugin will develop it to use the <a href="http://msdn.microsoft.com/en-us/library/ff512404.aspx">Microsoft translation API</a>. Google are shutting down the API due to &#8220;extensive abuse&#8221; and recommend using the <a title="Magento Google Element Translation Tool Implementation in 5 Minutes" href="https://blog.gaiterjones.com/magento-google-translation-tool-implementation/">Google Translate Element</a>. Whether the Microsoft translation service will be as good as Google we will need to wait and see. The author of the plugin <a href="http://code.google.com/p/jquery-translate/issues/detail?id=70">comments </a>&#8220;&#8230; <em>the Microsoft API provides a method for array translation (just as Google&#8217;s v2 API), which eliminates almost all bugs with this plugin, and will make it a bit faster too. The quality of the translation is not any worse I think, so there&#8217;s <span style="text-decoration: underline;">nothing to worry about.</span></em>&#8221; If you want to implement this solution bear in mind that changes to the plugin will take place at some point and the Google API will certainly stop working in December 2011.</p>
<p>&nbsp;</p>
<h1>Automatic jQuery Translator for Magento</h1>
<p>Having looked at integrating the <a title="Magento Google Element Translation Tool Implementation in 5 Minutes" href="https://blog.gaiterjones.com/magento-google-translation-tool-implementation/">Google element translation tool</a> into Magento to provide a <em>quick fix</em> content translation service I wanted to improve this tool by automatically translating content based on visitor browser language without the visitor having to manually select a language on every page.  <img decoding="async" class="hang-1-column        alignnone" title="Automatic Google jQuery Translator for Magento" src="https://blog.gaiterjones.com/wp-content/uploads/2011/05/jquery-magento-translator.jpg" alt="Automatic Google jQuery Translator for Magento" width="348" height="158" /> Despite spending a lot of time looking at ways to manipulate the Google element translator code I couldn&#8217;t come up with a good solution until I came across the<a href="http://code.google.com/p/jquery-translate/"> jQuery dynamic google translation plugin</a> which integrates the Google Ajax Language API to jQuery and provides a really flexible and powerful method of dynamically translating content.  Using jQuery and the jQuery translation plugin we can create an automatic language translation service for Magento that detects the visitors browser language and automatically translates every Magento page to that language when it is loaded, or alternatively does the same when a new language is manually selected from the language drop down selector.  This is quite an easy solution to implement but should be thoroughly tested on your development platform as it requires some changes to existing javascript libraries as well as the addition of new jQuery libraries and plugins.  I have included the new jQuery libraries and plugin files required to implement this solution in a <a href="https://blog.gaiterjones.com/dev/extension.php?id=eb4bee963f22f61f7c865960f1359b62">download which you can access here</a>. Download and extract the files, copy them to your Magento installation folder and then follow the instructions below to implement automatic jQuery Google translations in your Magento store.</p>
<p><span style="font-weight: bold; line-height: 15px; text-transform: uppercase;">jQUERY &amp; script.aculo.us<br />
</span>According to <a href="http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/javascript_related/how_to_use_jquery_1.2.6_lastest_with_prototype">this Magento blog post</a> jQuery should have no problems working with other javascript frameworks and should &#8220;<em>work out of the box</em>&#8221; with Magento but doesn&#8217;t due to a conflict with an older version of scriptaculous.The Magento conflict lies with the code in <em>effects.js</em> which we will upgrade to the latest <a href="http://script.aculo.us/downloads">version</a> (<strong>1.9.0</strong> as of <strong>December 23, 2010</strong>).</p>
<h1>jQuery, jQuery Translator plugin and UIBlock plugin</h1>
<p>The other libraries required are the <a href="http://jquery.com/">jQuery library</a> which provides the jQuery framework, the <a href="http://code.google.com/p/jquery-translate/">jQuery Translator plugin</a> which currently integrates with the Google API to do the translations and the <a href="http://jquery.malsup.com/block/">UIblock plugin</a> which I&#8217;ve used to provide a neat way of updating the user interface when translations are taking place. These are included in the <a href="https://blog.gaiterjones.com/dev/extension.php?id=eb4bee963f22f61f7c865960f1359b62">download package</a>.  After copying the new libraries across to the Magento /js folder we need to update the page layout XML in Magento so that the new libraries are loaded. Locate <em>page.xml</em> in the layout folder of your Magento stores theme and open it for editing.</p>
<h1>Installation</h1>
<p>First find the XML that loads the existing scriptaculous <em>effects.js</em> file and modify the line that loads the effects.js library and change it to load the new upgraded version as shown below. Double click the code box and use CTRL C to copy.</p>
<pre class="brush:xml"> &lt;action method="addJs"&gt;&lt;script&gt;scriptaculous/effects-1.9.js&lt;/script&gt;&lt;/action&gt;</pre>
<p>Next we need to add some new XML to tell Magento to use the new jQuery library and plugins, add the following three lines before the existing line of XML that loads the <em>prototype</em> library in page.xml</p>
<pre class="brush:xml">&lt;action method="addJs"&gt;&lt;script&gt;jquery/jquery-1.2.6.noConflict.min.js&lt;/script&gt;&lt;/action&gt;
&lt;action method="addJs"&gt;&lt;script&gt;jquery/jquery.translate-1.4.7.js&lt;/script&gt;&lt;/action&gt;
&lt;action method="addJs"&gt;&lt;script&gt;jquery/jquery.blockUI.js&lt;/script&gt;&lt;/action&gt;</pre>
<p>Save the modified page.xml file.  The dynamic translation jQuery code can be placed in the <em>footer.phtml</em> template file of your Magento theme so that it runs when the page is fully loaded, this file is usually located in the <em>template/page/html </em>folder of your theme. Locate the file, open it for editing and append the following code at the bottom:</p>
<pre class="brush:php">	&lt;?php
	/**
	 * Automatic jquery translator for Magento
	 * blog.gaiterjones.com
	 * v0.3
	 *
	 */
	?&gt;
	&lt;script type="text/javascript"&gt;
	//&lt;![CDATA[
	jQuery(function($){

			var defaultLang = '&lt;?php echo substr(Mage::app()-&gt;getLocale()-&gt;getDefaultLocale(), 0, 2) ?&gt;';

			$('#langSelect').change(function() {
				var pathname = window.location.pathname;
				window.location = pathname + '?translateTo=' + $('#langSelect').val();
				if ($('#langSelect').val() == defaultLang) {
					$.blockUI({
					message: '&lt;h1&gt;Language is being reset to default...&lt;/h1&gt;',
					timeout: 2000
					});
				}
			});

			function doTranslateTo( destLang ){
			$('body').translate(defaultLang, destLang, {
			  not: '.doTranslate',
              start:     function(){   $.blockUI({ message: '&lt;h1&gt;Translating, please wait...&lt;br /&gt;(' + defaultLang + ' &gt; ' + destLang + ')&lt;/h1&gt;' })   },
              complete:  function(){   $.unblockUI()  },
			  error:  	 function(){   $.growlUI('Translation Error', 'An error occured during translation...');   },
			  toggle: true
			});
	}

		&lt;?php

		$defaultLang=substr(Mage::app()-&gt;getLocale()-&gt;getDefaultLocale(), 0, 2); // default store language

		// determine browser langugage
		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
			// get languages from server header and assign quality rating
			foreach (explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $accept) {
				if (preg_match("!([a-z-]+)(;q=([0-9.]+))?!", trim($accept), $found)) {
					$langs[] = $found[1];
					$quality[] = (isset($found[3]) ? (float) $found[3] : 1.0);
				}
			}
			// Order the codes by quality
			array_multisort($quality, SORT_NUMERIC, SORT_DESC, $langs);
			$browserLang=substr($langs[0],0,2);

		} else {
			$browserLang=$defaultLang;
		}

		$requestedLang=Mage::app()-&gt;getRequest()-&gt;getParam('translateTo');
		//$requestedLang=$_REQUEST["translateTo"];
		$storeCode=Mage::app()-&gt;getStore()-&gt;getCode(); // store code
		$cookieName=$storeCode. "-". $defaultLang. "-jquery-translateTo"; // derive cookie name

		echo "// defaultlang - ". $defaultLang. "\n";
		echo "// requestedLang - ". $requestedLang. "\n";
		echo "// browserLang - ". $browserLang. "\n";
		echo "// storeCode - ". $storeCode. "\n";
		echo "// cookieName - ". $cookieName. "\n";
		echo "// langfromcookie - ". Mage::getModel('core/cookie')-&gt;get($cookieName). "\n"; 

		if(!empty($requestedLang)) // check for language setting in REQUEST key
		{
			if (strtolower($requestedLang) !== strtolower($defaultLang)) { // translate if requested language != to store default
				if (!empty($requestedLang))
				{
					echo "// translating to requested language from url variable.\n";
					echo "doTranslateTo('". $requestedLang. "');\n"; // Translate and write cookie data
					Mage::getModel('core/cookie')-&gt;set($cookieName, $requestedLang, time()+36000);
				} else {
					echo "// Requested Language not detected.\n";
				}
			} else {
				Mage::getModel('core/cookie')-&gt;set($cookieName, strtolower($defaultLang), time()+36000); // set cookie i.e. keep default lang when default selected
				//Mage::getModel('core/cookie')-&gt;delete($cookieName); // remove cookie i.e. revert to browser lang when default selected

			}
		} else { // check for language data in cookie

			$langFromCookie = Mage::getModel('core/cookie')-&gt;get($cookieName); // read cookie

			if (!empty($langFromCookie))
			{
				if (strtolower($langFromCookie) !== strtolower($defaultLang)) { // translate if language data in cookie != to store default
					echo "// translating to requested language from cookie data.\n";
					echo "doTranslateTo('". $langFromCookie. "')\n";
				} else {
					echo "// cookie requesed language same as store default language - no translation required.\n";
				}
			} else { // no cookie	

				if (strtolower($browserLang) !== strtolower($defaultLang)) { // translate to browser language and set cookie
					if (!empty($browserLang))
					{
						echo "// setting language to browser language.\n";
						echo "doTranslateTo('". $browserLang. "');\n";
						Mage::getModel('core/cookie')-&gt;set($cookieName, strtolower($browserLang), time()+36000); // set cookie
					} else {
						echo "// Browser language not detected.\n";
					}
				} else {
					Mage::getModel('core/cookie')-&gt;set($cookieName, strtolower($browserLang), time()+36000); // set cookie
				}
			}
		}
		?&gt;			

	})
	//]]&gt;
	&lt;/script&gt;</pre>
<p>The code includes two jQuery functions, one that performs the jQuery automatic translation, and the other that monitors the language dropdown box used to manually change the page translation. The PHP code controls the automatic translation of pages based on the visitors browser language, using a cookie to store the visitors language which is subsequently used to translate every visited page to the browser language, or the language selected from the select Language dropdown box which is passed to the script via a URL request variable. Note that the code detects the default locale for the Magento store and uses this as the default language for translations.</p>
<p>To add the dropdown box, locate the <em>languages.phtml</em> file in the <em>template/page/switch</em> folder of your theme. Make a backup of the original file and then edit it to add the Language selector drop down box, replacing the contents of the file with the following code which includes all the languages supported by Google. This file is also included in the download package.</p>
<p>The language dropdown has been updated to show the current language as selected in the drop down list.</p>
<pre class="brush:php">&lt;?php
/**
 * Language switcher for jQuery Automatic Translator for Magento
 * blog.gaiterjones.com
 *
 */

$defaultLang=substr(Mage::app()-&gt;getLocale()-&gt;getDefaultLocale(), 0, 2); // default store language
$storeCode=Mage::app()-&gt;getStore()-&gt;getCode(); // store code
$cookieName=$storeCode. "-". $defaultLang. "-jquery-translateTo"; // derive cookie name
$langFromCookie = Mage::getModel('core/cookie')-&gt;get($cookieName); // read cookie
$requestedLang=Mage::app()-&gt;getRequest()-&gt;getParam('translateTo');

if (!empty($requestedLang))
{
	$languageSelected=$requestedLang;
} else {
	$languageSelected=$langFromCookie;
}

$languagesSelection =
		array(''=&gt;'Select Language',
				substr(Mage::app()-&gt;getLocale()-&gt;getDefaultLocale(), 0, 2)=&gt;'Default Language',
				'af'=&gt;'Afrikaans',
				'sq'=&gt;'Albanian',
				'ar'=&gt;'Arabic',
				'be'=&gt;'Belarusian',
				'bg'=&gt;'Bulgarian',
				'ca'=&gt;'Catalan',
				'zh-CN'=&gt;'Chinese (Simplified)',
				'zh-TW'=&gt;'Chinese (Traditional)',
				'hr'=&gt;'Croatian',
				'cs'=&gt;'Czech',
				'da'=&gt;'Danish',
				'nl'=&gt;'Dutch',
				'et'=&gt;'Estonian',
				'tl'=&gt;'Filipino',
				'fi'=&gt;'Finnish',
				'fr'=&gt;'French',
				'gl'=&gt;'Galician',
				'de'=&gt;'German',
				'el'=&gt;'Greek',
				'ht'=&gt;'Haitian Creole',
				'iw'=&gt;'Hebrew',
				'hi'=&gt;'Hindi',
				'hu'=&gt;'Hungarian',
				'is'=&gt;'Icelandic',
				'id'=&gt;'Indonesian',
				'ga'=&gt;'Irish',
				'it'=&gt;'Italian',
				'ja'=&gt;'Japanese',
				'ko'=&gt;'Korean',
				'lv'=&gt;'Latvian',
				'lt'=&gt;'Lithuanian',
				'mk'=&gt;'Macedonian',
				'ms'=&gt;'Malay',
				'mt'=&gt;'Maltese',
				'no'=&gt;'Norwegian',
				'fa'=&gt;'Persian',
				'pl'=&gt;'Polish',
				'pt'=&gt;'Portuguese',
				'ro'=&gt;'Romanian',
				'ru'=&gt;'Russian',
				'sr'=&gt;'Serbian',
				'sk'=&gt;'Slovak',
				'sl'=&gt;'Slovenian',
				'es'=&gt;'Spanish',
				'sw'=&gt;'Swahili',
				'sv'=&gt;'Swedish',
				'th'=&gt;'Thai',
				'tr'=&gt;'Turkish',
				'uk'=&gt;'Ukrainian',
				'vi'=&gt;'Vietnamese',
				'cy'=&gt;'Welsh',
				'yi'=&gt;'Yiddish');
?&gt;
&lt;div class="form-language"&gt;
	&lt;div class="language-switcher"&gt;
		&lt;select id="langSelect" &gt;
&lt;?php
	foreach($languagesSelection as $langCode=&gt;$LangName)
	{
		if ($languageSelected === $langCode)
		{
			echo '&lt;option selected value="'. $langCode. '"&gt;'. $LangName. '&lt;/option&gt;';
		} else {
			echo '&lt;option value="'. $langCode. '"&gt;'.$LangName. '&lt;/option&gt;';
		}
	}
?&gt;
		&lt;/select&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<p>Save the file and refresh the Magento cache to load the new jQuery libraries and modified template files.</p>
<h1>Testing</h1>
<p>Now refresh your Magento front end and you should see the new language dropdown selector in the header of your page. This is where it appears in the default theme.</p>
<figure id="attachment_405" aria-describedby="caption-attachment-405" style="width: 345px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="hang-1-column        " title="Automatic Google jQuery Translator for Magento" src="https://blog.gaiterjones.com/wp-content/uploads/2011/05/jquery-magento-translator1.jpg" alt="Automatic Google jQuery Translator for Magento" width="345" height="373" /><figcaption id="caption-attachment-405" class="wp-caption-text">Drop down language selector</figcaption></figure>
<p>If your browser language differs from your stores default language then the page should automatically translate. If your browser language is the same as your stores, then perform a manual translation by selecting a language from the select language box. You will notice that a new request variable is appended to the site URL which triggers the dynamic translation. Navigate to other pages which should also become dynamically translated as the code reads the selected language from the cookie file. To turn off the automatic translation select the stores default language from the drop down, or select the second &#8220;default&#8221; option from the language dropdown list.</p>
<figure id="attachment_406" aria-describedby="caption-attachment-406" style="width: 496px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="hang-1-column        " title="Automatic Google jQuery Translator for Magento" src="https://blog.gaiterjones.com/wp-content/uploads/2011/05/jquery-magento-translator2-620x351.jpg" alt="Automatic Google jQuery Translator for Magento" width="496" height="281" /><figcaption id="caption-attachment-406" class="wp-caption-text">User interface is updated during translation using the UIBlock jQuery plugin.</figcaption></figure>
<figure id="attachment_407" aria-describedby="caption-attachment-407" style="width: 620px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/05/jquery-magento-translator3.jpg"><img loading="lazy" decoding="async" class="hang-2-column          " title="Automatic jQuery Google Translation for Magento" src="https://blog.gaiterjones.com/wp-content/uploads/2011/05/jquery-magento-translator3-620x158.jpg" alt="Automatic jQuery Google Translation for Magento" width="620" height="158" /></a><figcaption id="caption-attachment-407" class="wp-caption-text">Manual language selection is passed as a URL request variable and stored as a cookie.</figcaption></figure>
<p>To manually link to a specific language for your site, specifiy the translation request variable in the URL with the two letter language code as shown above. i.e. for a German translation use <strong>http://www.webshop.com/?translateTo=de</strong></p>
<figure id="attachment_423" aria-describedby="caption-attachment-423" style="width: 503px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/05/jquery-magento-translator4.jpg"><img loading="lazy" decoding="async" class="hang-1-column         " title="Automatic jQuery Google Translation for Magento" src="https://blog.gaiterjones.com/wp-content/uploads/2011/05/jquery-magento-translator4.jpg" alt="Automatic jQuery Google Translation for Magento" width="503" height="231" /></a><figcaption id="caption-attachment-423" class="wp-caption-text">Returning to default language turns automatic translations off.</figcaption></figure>
<p>Tested with Magento community editions v1.3.x and 1.5.x  Please provide feedback if you experience any problems, have successfully implemented this solution or if you have any other ideas for further development.</p>
<h1>Resources used in creating this solution</h1>
<p><a href="http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/javascript_related/how_to_use_jquery_1.2.6_lastest_with_prototype">http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/javascript_related/how_to_use_jquery_1.2.6_lastest_with_prototype</a></p>
<p lang="de">h<a href="http://code.google.com/p/jquery-translate/">ttp://code.google.com/p/jquery-translate/</a></p>
<p lang="de"><a href="http://jquery.malsup.com/block/">http://jquery.malsup.com/block/</a></p>
<p lang="de"><a href="http://jsbin.com/ozenu/1007/edit">http://jsbin.com/ozenu/1007/edit</a></p>
<h1 lang="de">Update Links</h1>
<p><a href="http://code.google.com/apis/language/translate/overview.html">http://code.google.com/apis/language/translate/overview.html</a></p>
<p>http://msdn.microsoft.com/en-us/library/ff512404.aspx</p>
<p>&nbsp;</p>
<p lang="de">&nbsp;</p>
<p lang="de">Blogged in <a href="http://www.kempinski.com/de/berlinadlon/Seiten/Welcome.aspx">Berlin</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/automatic-google-jquery-translator-for-magento/feed/</wfw:commentRss>
			<slash:comments>46</slash:comments>
		
		
			</item>
	</channel>
</rss>
