Multi-language function

4 posts by 2 authors in: Forums > CMS Builder
Last Post: May 15, 2014   (RSS)

By ht1080z - May 7, 2014

Dear interactiveTools Team,

I use a custom php function to control the languages in our websites. In the following example in Greek and English.

inc/languages.php :

<?php
    $a = session_id();
    if ($a == '') session_start();
    if (!isset($_SESSION['language'])) {
        session_regenerate_id(true);
        $_SESSION['language'] = "gr";
    }
    $_SESSION['sessionid'] = session_id();
?>

in every page header :

  require_once 'inc/languages.php';
  if (@$_REQUEST['lang']) { 
    if (@$_REQUEST['lang'] == "en") { $_SESSION['language'] = "en"; }
    elseif (@$_REQUEST['lang'] == "gr") { $_SESSION['language'] = "gr"; }
  }

and for each language i get content from the database :

<?php echo $blogRecord['title_'.$_SESSION['language']]; ?>

for i previously create title_en and title_gr in the related tables in the cms.

The above solution is working, but maybe you have any suggestion to improve / upgrade it.

Thank you in advance,
Karls

By Damon - May 9, 2014

Hi Karls,

Although it may not be necessary, I would add the htmlspecialchars function to the session output:

<?php echo $blogRecord['title_'.htmlspecialchars($_SESSION['language'])]; ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Damon - May 15, 2014

Hi Karls,

Here is a forum thread that discusses multi-language options and ideas:
http://www.interactivetools.com/forum/forum-posts.php?postNum=2193269#post2193269

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/