Register for your free account! | Forgot your password?

Go Back   elitepvpers > Popular Games > Metin2 > Metin2 Private Server > Metin2 PServer Guides & Strategies
You last visited: Today at 21:34

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[How-To]Multi-language Support to a PHP Website

Discussion on [How-To]Multi-language Support to a PHP Website within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.

Reply
 
Old   #1
 
TraxWall's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 178
Received Thanks: 86
Smile [How-To]Multi-language Support to a PHP Website

Are you interested in having a multilingual website? This is a tutorial that shows you how you can do that in PHP.

The first thing we need to do is to create a couple of files that will contain the text for each of the languages that will be supported by the website. For demo purpose I have chosen English, Spanish and German. Make a directory named “directory”. In this directory create 3 files: lang.de.php, lang.en.php, and lang.es.php. In our main file (index.php) we will include a file (common.php) containing a piece of code that gets the requested language. Here’s the content of those 3 language files:

lang.en.php

Code:
<?php
/*
------------------
Language: English
------------------
*/
 
$lang = array();
 
$lang['PAGE_TITLE'] = 'My website page title';
$lang['HEADER_TITLE'] = 'My website header title';
$lang['SITE_NAME'] = 'My Website';
$lang['SLOGAN'] = 'My slogan here';
$lang['HEADING'] = 'Heading';

// Menu

$lang['MENU_HOME'] = 'Home';
$lang['MENU_ABOUT_US'] = 'About Us';
$lang['MENU_OUR_PRODUCTS'] = 'Our products';
$lang['MENU_CONTACT_US'] = 'Contact Us';
$lang['MENU_ADVERTISE'] = 'Advertise';
$lang['MENU_SITE_MAP'] = 'Site Map';
?>

As you can notice, some constants are created using the define() function. In every file the defined constants have the same name, bu the values is different. We will output the values of the constants inside the index.php file. Therefore we will see different text every time we will call other language file.
Determine the right language

Let’s analyze the common.php file:

Code:
<?php
session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];

// register the session and set the cookie
$_SESSION['lang'] = $lang;

setcookie('lang', $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'en';
}

switch ($lang) {
  case 'en':
  $lang_file = 'lang.en.php';
  break;

  case 'de':
  $lang_file = 'lang.de.php';
  break;

  case 'es':
  $lang_file = 'lang.es.php';
  break;

  default:
  $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;
?>
After we determine the value of $lang, we use switch() to compare its value with some different values, and execute a different piece of code depending on which value it equals to. After the value of the $lang_file is determined, the script will include the necessary language file. As you can see I have used sessions to register the value of $lang. This way users can navigate through the whole site and see the content in the chosen language (lang=[language here] does not need to be passed in every URL). Additionally, I have used cookies to store the selected language in users computer for 30 days. When the visitor will come back he will see the site in the language that he previously selected.
How if the website’s language requested?

In this demo I have chosen to use some image flags, each image having a link to index.php?lang=[LANG HERE]. So, to see the site in german we will use the German image flag which links to index.php?lang=de.

Lastly, the constants values should be outputted in the page. Examples:


for document title

Code:
<title><?php echo $lang['PAGE_TITLE']; ?></title>
for header menu
Code:
<ul>
     <li><a href="/"><?php echo $lang['MENU_HOME']; ?></a></li>
     <li><a href="about_us"><?php echo $lang['MENU_ABOUT_US']; ?></a></li>
  <li><a href="our_products"><?php echo $lang['MENU_OUR_PRODUCTS']; ?></a></li>
     <li><a href="contact_us"><?php echo $lang['MENU_CONTACT_US']; ?></a></li>
     <li><a href="advertise"><?php echo $lang['MENU_ADVERTISE']; ?></a></li>	
     <li><a href="sitemap"><?php echo $lang['MENU_SITE_MAP']; ?></a></li>
   </ul>

Thank you for checking on my topic.
If you liked hit a thank-

TraxWall is offline  
Thanks
11 Users
Old 02/09/2013, 09:19   #2


 
elite*gold: 0
Join Date: Feb 2010
Posts: 7,221
Received Thanks: 6,758
And why u post it at this section?
#SoNiice is offline  
Thanks
1 User
Old 02/09/2013, 10:06   #3
 
TraxWall's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 178
Received Thanks: 86
Metin2 sites and so perfect.
Also if you do not belong here ... you can then move to a moderator
TraxWall is offline  
Old 02/09/2013, 11:47   #4
 
-TÜRK-'s Avatar
 
elite*gold: 0
Join Date: Jan 2010
Posts: 328
Received Thanks: 434
Good Tutorial. Thank You. I can use on MT2GS CMS.
-TÜRK- is offline  
Thanks
1 User
Old 02/09/2013, 12:21   #5
 
elite*gold: 252
Join Date: Mar 2008
Posts: 3,111
Received Thanks: 3,911
Please give the source of this tutorial. I don't think you wrote it yourself.
.Alessa is offline  
Thanks
1 User
Old 02/09/2013, 12:33   #6
 
TraxWall's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 178
Received Thanks: 86
Yes, I did not write but do not have the above side epvp
The page where you can find it was no longer there because 2 years Description ....

Only this is not what I wrote but was made public.
Only what I have written, and the system you call your own.
Just what I met many pages there are no more language options, and so I published the source code
TraxWall is offline  
Old 02/09/2013, 13:12   #7
 
elite*gold: 252
Join Date: Mar 2008
Posts: 3,111
Received Thanks: 3,911
Then write down that you didn't made the tutorial.

Quote:
Thank you for checking on my topic.
This is clearly misleading. You can get "Thanks" (for whatever you need them) for publishing this tutorial here but make CLEAR that you didn't wrote it.
.Alessa is offline  
Old 02/09/2013, 13:12   #8
 
©NewProject's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 55
Received Thanks: 11
O nice danke
©NewProject is offline  
Thanks
1 User
Old 02/09/2013, 13:48   #9
 
elite*gold: 0
Join Date: Feb 2012
Posts: 190
Received Thanks: 44
Quote:
Originally Posted by .Alessa View Post
Then write down that you didn't made the tutorial.


This is clearly misleading. You can get "Thanks" (for whatever you need them) for publishing this tutorial here but make CLEAR that you didn't wrote it.
Alessa, what is your problem? I didn't knew this language thingy, and i'm sure more do. This is helpfull for people which are using an cms or some sort of site. As for you and the other flamers, haters or w.e. Just ignore and shutup?


Greetings
Interception is offline  
Thanks
1 User
Old 02/09/2013, 14:02   #10
 
TraxWall's Avatar
 
elite*gold: 0
Join Date: Oct 2010
Posts: 178
Received Thanks: 86
I'm sorry for my mother because it was trying to help people so ....
I'm sorry for swearing but I hate that kind of thing that, how to connect it to another ...

sorry for the bad translation text.
TraxWall is offline  
Old 02/09/2013, 14:26   #11

 
elite*gold: 0
Join Date: Jul 2009
Posts: 2,471
Received Thanks: 5,622
Just use
.Alpha. is offline  
Thanks
1 User
Old 02/09/2013, 14:26   #12
 
Red Firestar's Avatar
 
elite*gold: 0
The Black Market: 185/0/0
Join Date: Jul 2012
Posts: 5,520
Received Thanks: 1,350
Good Tutorial Thanks *-*
Red Firestar is offline  
Old 02/09/2013, 14:51   #13
 
elite*gold: 0
Join Date: Feb 2012
Posts: 190
Received Thanks: 44
btw, for the people which are not familiar with the include option:

Code:
<?php include("common.php"); ?>
on top of your php file
Interception is offline  
Old 12/28/2013, 03:44   #14
 
elite*gold: 0
Join Date: Dec 2013
Posts: 1
Received Thanks: 0
Please give credits >_<
Here's the source
V3X0RE is offline  
Reply

Tags
metin2, multilaguange, php, website


Similar Threads Similar Threads
mybb multi forum website
07/04/2012 - EO PServer Hosting - 0 Replies
Dear users maybe this belongs in the general chat , but as i spend most of my time in here do i think that this is a good place to :D anyway most private servers need a forum , i see differend webmasters use a freehost provider and also a free forum so now i released a new system to get your own mybb forum for free the script is still in alpha stage , so i am working on it to improve as needed
Website doesn't filter all language?
01/14/2012 - Off Topic - 0 Replies
Hello, Well I've pressed the USA link as I do not speak German and it doesn't filter it all. Only noticed the main page is filtered and some posts when reading are in English but not alot. All info etc is German, any idea's?
how to make isro client support multi language type?
07/21/2011 - SRO Private Server - 4 Replies
hi all im wondering how to make isro client support multi language input? like chinese/kr language type thanks everyoneXD
Website Support
06/21/2010 - Technical Support - 3 Replies
Hey guys, I wanna know If someone of you knows how to get such a chatroom: The Colorless: Chat (Dollars/Durarara!!) I really want it like this .... like in Durarara but dunno how ......



All times are GMT +1. The time now is 21:34.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.