Jump to content

what will be the best way to add multiple languages to site?


xcoderx

Recommended Posts

i got this coding below, how and what would be the best way to use it to my site without affecting seo and along with exsisting logged in user data?

 

how would you do it?

 

<?php
session_start();
header('Cache-control: private'); // 

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;
?>

 

 

Create your website as if you were to create it in ONE language. Afterwards translate it using a SINGLE database table.

 

translations (key, message)

 

<a href="#"><?php print _('Login'); ?></a>

 

Shows Login for English (default language), Aanmelden for Dutch, ..

is it necessary to use database or its ok to store the languages in a variable?

 

It would be better if you used a database as you inevitably will end up using one.  Remember: those files in which you store your data (eg XML) is also a database. This has the advantage that you don't have multiple sources that hold translation data.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.