. */ /** * plugin_i18n classe pour gerer l'internationnalisation * @author Mika * @link http://mkf.mkdevs.com/ */ class plugin_i18n { private static $tLangue; public static function start() { self::load(_root::getConfigVar('language.default')); } /** * charge le fichier de langue situe dans la section [path], valeur de i18n * @access public static * @param string $sLang (doit etre present dans le fichier de config [language] allow separer par des virgules */ public static function load($sLang) { $tAllowed = preg_split('/,/', _root::getConfigVar('language.allow')); if (!in_array($sLang, $tAllowed) and $sLang != _root::getConfigVar('language.default')) { throw new Exception('Lang not allowed, list allow:' . _root::getConfigVar('language.allow')); } include_once _root::getConfigVar('path.i18n') . $sLang . '.php'; self::$tLangue = _root::getConfigVar('tLangue'); } /** * retourne la traduction du tag $sTag * @access public static * @param string $sTag tag du mot a traduire */ public static function get($sTag) { if (!isset(self::$tLangue[$sTag])) { return $sTag . '(need translation)'; } return self::$tLangue[$sTag]; } public static function add($tLangue) { foreach ($tLangue as $sKey => $sVal) { self::$tLangue[$sKey] = $sVal; } } public static function getList() { return self::$tLangue; } } function tr($sText) { return plugin_i18n::get($sText); } function trR($sText, $tReplace) { return str_replace(array_keys($tReplace), array_values($tReplace), tr($sText)); }