Hello,
I have used Single Translation Table Approach to make multilanguage site in PHP. You may see here
The current index page is not working.
My objective is to have one example to use these tables and display one working page. For example: It should work like this by using these tables.
What i did so far on my home page:
<!DOCTYPE html>
<?php session_start();
$_SESSION['current_language'] = "fr";
$con = mysql_connect("localhost","worksite","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("worksite", $con);
?>
<?php
echo '<a href="./index.php?lang=fr">Français</a> | ';
echo '<a href="./index.php?lang=en">Anglais</a> | ';
$languages = array('en', 'fr');
// handle language selection
if(in_array($_GET['lang'], $languages))
{
$_SESSION['lang'] = $_GET['lang'];
}
// define LANG constant only if it exists in $languages array, otherwise default to EN
define('LANG', in_array($_SESSION['lang'], $languages) ? $_SESSION['lang'] : 'fr');
define('LANG', in_array($_SESSION['lang'], $languages) ? $_SESSION['lang'] : 'en');
// display language options
foreach($languages as $language) {
echo '<a href="?lang='.$language.'">'.$language.'</a>';
}
$sql = "SELECT p.*, l.name as language_name, te.field_text as title
FROM `app_product` p
INNER JOIN `app_translation_entry` te ON p.title = te.translation_id
INNER JOIN `app_language` l ON te.language_code = l.code
WHERE p.id = 1";
if($result = mysql_query($sql)){
while($row = mysql_fetch_assoc($result)){
echo "Language (".$row["language_name"]."): ".$row["title"]."<br>";
}
}
// Retrieve appropriate title according to the chosen language in the system
$sql = "SELECT p.*, l.name as language_name, te.field_text as title
FROM `app_product` p
INNER JOIN `app_translation_entry` te ON p.title = te.translation_id
INNER JOIN `app_language` l ON te.language_code = l.code
WHERE p.id = 1 AND
te.language_code = '".$_SESSION['current_language']."'";
if($result = mysql_query($sql)){
if($row = mysql_fetch_assoc($result)){
echo "Current Language: ".$row["title"];
}
}
?>
</body>
</html>
THANKS IN ADVANCED for your time and input.