View Full Version : Different language conversion

01-03-2006, 05:43 PM

i am trying to change some text which is written in default language
i,e english language now i am want to change it language
like Deutsch ,English (UK),Italiano,Français etc.Is it possible
with the help of php?.

01-03-2006, 10:36 PM
This topic should be in the PHP section, and not the PHP Snippet section. Perhaps you misunderstood this sections name meaning. If you could, change your topic title to include (Move This) or something.

Anyway, you would need to creat seperate files, containing an array of phrases in each language, for example:

// Array of phrases on language.en.inc
$phrase['good_afternoon'] = "Good Afternoon!";
$phrase['good_evening'] = "Good Evening!";
// ... etc.

// Array of phrases on language.de.inc
$phrase['good_afternoon'] = "Guten Tag!";
$phrase['good_evening'] = "Guten Abend!";
// ... etc.

And then based by either a $_GET superglobal, or cookies, you would set the default language, like 'de' or 'en' then include the appropriate file... a simple example:


$valid_languages = array('en', 'de');
if(isset($_GET['lng']) && in_array($_GET['lng'], $valid_languages)) {
} else {

echo $phrase['good_evening'];


Then you could test it by going to http://example.com/index.php?lng=de (Not a working example; an example URL of how it would beb used on your site.)

01-03-2006, 11:15 PM
Why reinvent the wheel?

01-04-2006, 12:22 AM
Because some people use english windows and speak dutch or so i guess

Velox Letum
01-04-2006, 12:28 AM
Why reinvent the wheel?

Gettext is a PHP extension that must be added or compiled in...it's not enabled by default. You can emulate the functions, but thats slower, and without writing wrapper functions to test for the functions, and if they don't exist emulate them isn't worth the effort in most cases. I prefer to use language files or store the language in the database myself.

01-04-2006, 12:47 AM
Not having the access to add the extension is a fair point I guess, no idea what diod meant (if it was a reply to me...)
If multi-language is really that important, then the effort of finding a host with it installed would probably be less than doing what was suggested :|

01-04-2006, 12:55 AM
I mean that if im correct about the function of gettext, is that it checks what language your windows is; But if you have a english windows, then gettext thinks that u r english speaking, while u could be dutch speaking or so

01-04-2006, 01:25 AM
You're not correct
You tell it what language you want to use in the script (so could be based on a DB value, or a $_GET var etc.)