Forum Moderators: coopster

Message Too Old, No Replies

Languages system

How can create in the PHP?

         

romzinho2k7

7:38 am on May 5, 2006 (gmt 0)

10+ Year Member



Hey friends, all right?

It would like to know there is some function in php so that I can put my site in several languages. I saw a tutorial, but I lost him of my favorites, he taught to do that, he replaced the files by the person's language using.. [#CODE#] Eg:

It puts [#house#] in layout => Then, it was "translated" house in English and casa in Spanish

And in this tutorial had a folder /lang in which I was put the files en.php ( for English ) es.php for Spanish etc...

Anybody had known about anything +/- this way, or some tutorial of how to create layouts for multilanguages?

Obs: It did not want to use Class FastTemplate.php because do not understand a lot of class and I wanted to learn to do that multilanguages system, without using a ready.

Sorry my bad english.

Thanks at once
Robson

omoutop

10:41 am on May 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Dont know if the following will be of any help for large applications, but here goes:

Have a file included in each page of yours, lets say languages.php

Inside have something like:

if ($language=="english")
{
$var1 = "Hello world";
$var2 = "This is in english";
}
else if ($language=="funny_language")
{
$var1 = "Greetings in Funny Language";
$var2 = "This is indeed a funny language";
}
// and so on

Now on your pages, instead of typing your text, have a simple echo of the appropirate $var(x) and pass/declare $language in each page yuo want your text to change dynamically.

As i said before, not a great idea for large scale applications

taps

11:40 am on May 5, 2006 (gmt 0)

10+ Year Member



I built up an array $lang. As keys I use the words in my own language like

$lang['house']

Depending from the language I fill up that array from one of the ini-Files I have prepared, let's say lang_en.ini and lang_sp.ini.

Choosing english I have

$lang['house'] = 'House';

Coosing spanish I have

$lang['house'] = 'Casa';

Filling up Arrays from an ini-File is pretty easy. Check the php documentation for parse_ini_file().

romzinho2k7

8:35 pm on May 5, 2006 (gmt 0)

10+ Year Member



Thanks my friends

Good suggestions

Thank you very much