- Joined
- Feb 1, 2005
- Messages
- 257
- Reaction score
- 9
Ok , i know the way i am about to show you isn't the most efficient one, but its the easiest that came across my mind
.
First of all, create a new folder named "language' and in it a new file. Name it "eng.php", and in it type :
.
This is the English language file.
You can create as many languages files as you want.
Then create an "index.php" and in it write :
Code explanation :
"cookies.php?languages=eng&Submit=Submit "
where "eng" is the name of the language file. For pictures you can use anything you like.What this basically does is, to create the links, which lead to the part where the cookie for the selection of the language is set.
After writing the code above, write in "index.php" the following:
Code explanation :
"if (isset($_COOKIE["lang"])) { include("language/".$_COOKIE["lang"].".php"); } else {include"language/eng.php";}" checks to see if a cookie has been set, and determines the language file that is going to be used
"print News;" If you remember, in the file "eng.php" we defined the value for Home_news, to be 'news'. This basically prints that value. Remember that in all your language files, the name for each define must be the same. For example in "eng.php" we have : "define(Home_News,'news');". This in the "gr.php" must be : "define(Home_News,'νέα');
Create the "cookies.php"
All this does is to create the cookie with the language value and to redirect the user back to index.php
Well, that is all. Hope this is useful to some people
(do note that if you don't understand how php works,or at least the basics, i am not going to start explain it to you all from the beginning. You can find some tutorials on the basics here )
First of all, create a new folder named "language' and in it a new file. Name it "eng.php", and in it type :
PHP:
<?php define(Home_News,'news'); ?>
This is the English language file.
You can create as many languages files as you want.
Then create an "index.php" and in it write :
PHP:
<a href="cookies.php?languages=eng&Submit=Submit"><img src="language/gb.png" alt="" width="32" height="16" border="0"></a></a>
<a href="cookies.php?languages=gr&Submit=Submit"><img src="language/Greek.png" width="31" height="17" border="0"></a>
"cookies.php?languages=eng&Submit=Submit "
where "eng" is the name of the language file. For pictures you can use anything you like.What this basically does is, to create the links, which lead to the part where the cookie for the selection of the language is set.
After writing the code above, write in "index.php" the following:
PHP:
if (isset($_COOKIE["lang"])) { include("language/".$_COOKIE["lang"].".php"); }
else {include"language/eng.php";}
print Home_News;
"if (isset($_COOKIE["lang"])) { include("language/".$_COOKIE["lang"].".php"); } else {include"language/eng.php";}" checks to see if a cookie has been set, and determines the language file that is going to be used
"print News;" If you remember, in the file "eng.php" we defined the value for Home_news, to be 'news'. This basically prints that value. Remember that in all your language files, the name for each define must be the same. For example in "eng.php" we have : "define(Home_News,'news');". This in the "gr.php" must be : "define(Home_News,'νέα');
Create the "cookies.php"
PHP:
<?php
$getlang=stripslashes($_GET["languages"]);
setcookie("lang","$getlang");
?>
<html>
<head>
<META http-equiv="refresh" content="5; URL=index.php"></head>
<body>
Please wait while changing languages..
</body>
</html>
Well, that is all. Hope this is useful to some people
(do note that if you don't understand how php works,or at least the basics, i am not going to start explain it to you all from the beginning. You can find some tutorials on the basics here )

