Adding google translation to any page in html/php using Google Translation
Create span element for flags :-
|
<span class="flags"> <span class="flag_click eng" data-val = 'en'><flag-img></span> <span class="flag_click spn" data-val = 'es'><flag-img></span> |
|
Add following Script below this :-
|
<script> function changeLang(someth) { var nLang = someth;//someth.value, evt = document.createEvent("HTMLEvents"); evt.initEvent("change", false, true); jQuery('.goog-te-combo').val(nLang)[0].dispatchEvent(evt); }
jQuery('document').ready(function () { jQuery('.flag_click').click(function () { var va = jQuery(this).attr('data-val'); changeLang(va); }); }); </script> <div class="translator_div" style="display:none;">
<div id="google_translate_element"></div><script type="text/javascript"> function googleTranslateElementInit() { new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'en,es', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL}, 'google_translate_element'); } </script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> </div>
|
|
No comments:
Post a Comment