Jump to content

Recommended Posts

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 those tables (app_language, app_product, app_translation, app_translation_entry).

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	
// 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>	

You may edit this file as you wish but it should be working as per example link (demo).

 

I want to build static website from above approach. 

 

Thanks in advanced for your time and input.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.