I see many lava sites try to add multi languages, but i daresay they doin it in an old fashioned manner. So since ive been baking mG 2 (as demanded) i wrote a PHP 5 framework on which im baking mG 2. This is the i18n library i use. Note php 5 only.
Added after 8 minutes:
Added after 8 minutes:
PHP Code:
<?php (!defined('I18N_PATH')) AND die('Direct script access is forbidden.');
/**
* i18n Class ported from Lypid PHP framework.
*
* @package Lypid Core
* @subpackage mGiGS Core
* @author Neo Ighodaro
* @copyright (c) CreativityKills Networks
*/
class i18n {
// translations
public static $translations = array();
// active locale
public static $locale = 'en-us';
// singleton instance
public static $instance;
public static function instance()
{
if(i18n::$instance !== NULL)
return i18n::instance;
return i18n::instance = new i18n;
}
// set the locale
public function set_locale($locale = null)
{
i18n::$locale = $locale;
return i18n::$instance;
}
public function load()
{
if(isset(i18n::$translations[i18n::$locale]))
return i18n::$translations[i18n::$locale];
$path = I18N_PATH.i18n::$locale.'.php';
if(is_file($path) AND (is_readable($path))
{
$translations = array();
require $path;
return i18n::$translations[i18n::$locale] = $translations;
}
else
{
trigger_error('i18n file '.$path.' not found.', E_USER_WARNING);
return FALSE;
}
}
public static function gettext($line)
{
return isset(i18n::$translations[i18n::$locale][$line]) ? i18n::$translations[i18n::$locale][$line] : null;
}
}
function __($text, $vals = null)
{
return is_array($vals) ? strtr(i18n::gettext($text), $vals) : $text;
}
Comment