Friday, May 1, 2009

Easy Multi-Language for your website

Hi Friends & Techies,
I came after a long back time with more tips & i'll share you more frequently in coming months. Now in the post i'll start sharing about how to create Multi-language website using php.

First we must plan for the multilingual website
1) Every time when we add new language it should support the website without anymore alteration in the Web pages
2) Must have unique variable for each & every page for the content [so there wont be redeclaring].
3) For more user friendly use more text and design your pages with css. Avoid using images [Until you need it].
4) After designing your template, put all the contents in main language. Make it aligned and look out for browser compatibility
5) Going for Multi-language option
6) Create a file called "defines.php"
7) In the defines.php you define language for file
if($_COOKIE['language']==""){
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];//Detecting Default Browser language
}
else {
$lang = $_COOKIE['language'];//Detecting if cookie was set
}
switch($lang){
case "en":
require("lang/english.php"); // where the content in english is stored
break;
case "cn":
require("lang/chinese.php"); // where the content in chinese is stored
break;
case "zh-CN":
require("lang/chinese.php");
break;
case "zh-cn":
require("lang/chinese.php");
break;
default:
require("lang/english.php");
break;
}
8) Include the above file in all the webpages in your website

include('includes/defines.php');

9) In all the webpages you must change/add the meta tag information
<1meta http-equiv="content-type" content="text/html; charset=UTF-8"> //Remove 1 in the meta tag

10) for creating a new language you must save the file in UTF-8 format.
Follow the steps to save it in UTF-8
a. Open the notepad (start->run->type "notepad")
b. Save the file as "chinese.php".
c. In the save option Enter file name as "chinese.php" , Save as Type as "All Files", In encoding as "UTF-8" ;
11) Now with as usual PHP Syntax create some unique variable.
12) For chinese translation Go to Google Translation.
13) Copy the translated text and paste it in notepad for a particular variable.
14) Create a webpage, include the defines.php file, print the variable defined in chinese.php file

For Demo: Multilingual Website

Thats it, you've created multilingual website. If you've any doubt, just comment to this post i'll reply as soon as possible.

6 comments:

Anonymous said...

I am new to to php

Can I see a example of what this will be in step 11?
PHP Syntax create some unique variable.

thanks

Sathish Kumar said...

Hi,
Unique variable means if you're using $country = "India" means you should not use declare another variable $country = "Pakistan" you can use $country = "India" in english language $country = "some french word" in french.php.

Никола said...

Hi Your Guide isn`t Correct.
I can`t Understand Deffline are you using or what, can You make new guide with full steps what exacly to do please

Damir said...

How to change language without load page? (where is the ajax script for this?)

thank's

nike said...

jsr solutions a software development company is organising a test in quest univercity Mohali(landra) on the basis of apttitude and gernal knowledge.The top 50 students who pass this test have to be taken for you can register your roll no here free B-tech Training on free

Vijaya Kumar S said...

See this link for multi language website,
http://www.vijayakumar.org/easy-multilangual-english-tamil-website-creation-using-php.html