Help with changing language PHP, e.g. french/english?


I am just wondering how it is possible change language for an existing site so that people have an option to select different language - e.g. from a drop down at the top of the page etc.

This should do ya

john, thanks for this should work… but i am wondering did you implement it on an entire webpage/site or just sections?

are you grabbing the entire body content and translating…? what about headers?

do you have an example code…?


You could look into using gettext(). Be aware that setting up a multilingual site is quite a lot of work :slight_smile:

Here is the script I use to load the Google JavaScript:

// get/set in my included config file
$_SESSION['translate'] = isset($_SESSION['translate']) ? $_SESSION['translate'] : FALSE;

/* GOOGLE TRANSLATE LINK in common included menu.php */
if( ! LOCALHOST) && ($_SESSION['translate'])
  echo "<span class='fll'>&nbsp; <strong>";
  echo anchor('google-translate/' .$this->uri->uri_string(), 'Google Translate');
  echo '</strong></span>';

// _google_translate.php
<script type='text/javascript'>
	function googleTranslateElementInit() {
	  new google.translate.TranslateElement({
	    pageLanguage: 'en',
	    includedLanguages: 'af,sq,ar,hy,az,eu,be,bg,ca,zh-CN,zh-TW,hr,cs,da,nl,en,et,tl,fi,fr,gl,ka,de,el,ht,iw,hi,hu,is,id,ga,it,ja,ko,lv,lt,mk,ms,mt,no,fa,pl,pt,ro,ru,sr,sk,sl,es,sw,sv,th,tr,uk,ur,vi,cy,yi',
	    autoDisplay: false,
	    gaTrack: true,
	    layout: google.translate.TranslateElement.InlineLayout.SIMPLE
	  }, 'google_translate_element');
<script type='text/javascript' src="">

It may seem a bit of a long-winded way of calling the file, the reason is that the Google script is quite large, slow to load and by using this method it is only loaded as and when required.


Take a look at:

I use it one one of my sites. I call it from a link because the additional script slows the page and is not required for all users.