Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial]How to create a simple multilanguage website.

Experienced Elementalist
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 :p.

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>
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:
PHP:
if (isset($_COOKIE["lang"])) { include("language/".$_COOKIE["lang"].".php"); }
else {include"language/eng.php";}
print Home_News;
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"
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>
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 :p

(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 )
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
sage

Apache already has a mechanism to do this.

See page 54 of the Apache server manual.
 
Divine Celestial
Loyal Member
Joined
Jul 7, 2004
Messages
853
Reaction score
5
Probably; read the manual and come to your own conclusion.
 
Back
Top