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

 

 

Link to comment
Share on other sites

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, ..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.