My multilingual website with basic php (without zend_translate, gettext, etc.) Will I have problems in the future?

I tried gettext, but my free hosting does not allow this. I was thinking about Zend_translate, but I didn’t want to use elements from the frameworks, since my page is mostly static.

So, I finished this tutorial:

http://www.bitrepository.com/php-how-to-add-multi-language-support-to-a-website.html

If the author uses only the basic php (not sure) and it seems to work, but I'm not quite sure if this is a good (or normal) practice or if this may cause me problems in the future (adding and removing a bunch of code).

There he is:

common.php

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

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.es.php';
  break;

  default:
  $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;
?>

Languages ​​/lang.en.php:

<?php
/* 
-----------------
Language: English
-----------------
*/

define('GREETING, Hello World');
?>

Languages ​​/lang.es.php:

<?php
/* 
-----------------
Language: Espanol
-----------------
*/

define('GREETING, Hola Mundo');
?>

index.php:

include_once 'common.php';
<p><?php echo LANG_TEST; ?></p>

, , : ?lang=es URL ( index.php)

+1
1

, .

define('GREETING', 'Hello World').

PHP define.

-, - . . . .

Zend_Translate ( ) gettext, , . - :

$lang = array(
    'greeting'  => 'Hello World'
    'something' => 'else'
);

:

<h1><?php echo $lang['greeting'] ?></h1>

, , $lang .

, .

<h1><?php echo t('Hello World') ?></h1>

t , . , .

$lang = array(
    'Hello World' => 'Hola Mundo'
);

, , $lang['Hello World']. . , - :

$lang = array(
    'currentTime' => 'The current time is %s'
);

<h1><?php echo t('currentTime', date('H:i:s')) ?></h1>
+7

All Articles