Posted by peter on 10/13/06 12:47
> Good idear. ;-)
> I know, but do not know how. So I start with 1 page and try to change it
> into a template with texts form somewere
1 way that people do this without using a database which is in fact very
common (just look at forum softwares etc) is to have a seperate file for
each language.
For example if you have french, english and german you may have 3 files
called:-
lang_de.php
lang_en.php
lang_de.php
In these files you would have an array such as:-
$lang['hello'] = 'hello';
$lang['welcome_text'] = 'some welcome text';
$lang['goodbye'] = 'goodbye';
you would have a different line for each section of text (making sure that
each section of text had a unique key in the array, thats the thing in the
square brackets).
The other 2 languages would have exactly the same arrays in them but with
the text after (and only after) translated into the respective language.
on your pages you would need for example a pull down menu so that the person
can choose their language. when that is submitted you could either store the
result in a session or in a cookie. At which time you could then use an if
statement such as the following:-
if($_SESSION['lang'] == 'de')
{
require_once('lang_de.php')
}
elseif($_SESSION['lang'] == 'fr')
{
require_once('lang_fr.php')
}
else
{
require_once('lang_en.php')
}
the else 1 would obviously be the default language if nothing was chosen
(but of course still make it a selection in the pull down menu in case
someone changes the language and wishes to change it back).
lastly to use the language you simply place $lang['welcome_text'] for
example where you want the text that this is for to be displayed and it will
be displayed in the language the person has chosen (or the default language
if none chosen).
To fully accomplish this take a look in the manual at the following pages:-
http://uk.php.net/session_start
http://uk.php.net/array
Navigation:
[Reply to this message]
|