HI frnds..

i need a help from u..
now i am going to do a ecommerce gifts website.
here i need to change total site from english to french,italie...based on selected language from select box
how can i do this..plz help me asap..
is there any software or any procedure plz tell me..

thanks & regards
Saritha....

Member Avatar for diafol

There are a few solutions. You can use off-the-shelf solution e.g. open source CMS Joomla with Joomfish, or design your own. I prefer to design my own as it gives a greater degree of flexibility.

Here's my method:
1. I create a i18n folder and create my language files by placing the static phrases as arrays, e.g.

/i18n/
cy.inc.php
en.inc.php
it.inc.php

2. Into these files place the static text array:

$iTxt = array(
'index_title'=>'Croeso i\'m Hafan',
'index_preamble'=>'Dyma\'r wefan orau yn y byd',
'index_main_title'=>'Ceilliau\'r Gath',
       [etc, etc.]
);

3. Include the correct language file into your pages (before the DTD) by using your current language variable (e.g. $lang). include($_SERVER['DOCUMENT_ROOT'] . "/i18n/{$lang}.inc.php"); 4. Insert placeholders into your HTML

<h1><?=$iTxt['index_title'];?></h1>
<p><?=$iTxt['index_preamble'];?></p>
<h2><?=$iTxt['index_main_title'];?></h2>

You may find that an Model-View-Control/Templating system like Smarty may be useful here.

Also, your $lang variable must carry forward from page to page either as a cookie or $_SESSION variable or as a database value.

You can retrieve the language from a dropdown and $_POST variable:

<select id="lang" name="lang">
  <option value="cy">Cymraeg</option>
  <option value="en">English</option>
</select>

In your form handler:

$lang = addslashes(htmlentities($_POST['lang']));
$_SESSION['lang'] = $lang;

My database tables are listed so that they contain language-labelled fields, e.g.
desc_cy, desc_en
for
description Welsh, description English.
This is probably not the most efficient way of doing things, but the mysql calls are extremely easy to manipulate:

$sql = mysql_query("SELECT desc_{$lang} FROM mytable WHERE ...");

Alternatively, you could look at gettext and po/pot files using PoEdit. I haven't used this yet, but it looks promising. Keeping track of changes to different language files is very difficult, so an indexing system like this should be good.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.