00001 <?php
00017 require_once 'Zend/Translate.php';
00018 require_once 'Zend/Locale.php';
00019
00029 class I18n
00030 {
00031 const LANGUAGE_PATH_1 = "languages";
00032 const LANGUAGE_PATH_2 = "LC_MESSAGES";
00033 const DEFAULT_LANGUAGE = DEFAULT_LANGUAGE;
00034
00035 protected static $_langData;
00036 protected static $_langCode;
00037
00038 public static function t($text, $key=null, $module)
00039 {
00040
00041
00042
00043 if (!I18n::loadLangData($module))
00044 return $text;
00045
00046 if ($key && isset(I18n::$_langData[$module][$key]))
00047 return I18n::$_langData[$module][$key];
00048
00049 $key = strtoupper('STRING_'.md5($text));
00050 if ($key && isset(I18n::$_langData[$module][$key]))
00051 return I18n::$_langData[$module][$key];
00052
00053
00054 if ($module != '_system')
00055 return self::t($text, $key, '_system');
00056
00057 return $text;
00058 }
00059
00060 protected static function loadLangData($module)
00061 {
00062 if (isset(I18n::$_langData[$module])) {
00063 return true;
00064 }
00065
00066
00067 $langCode = I18n::getCurrentLangCode();
00068
00069
00070 if ($module == '_system') $filename = 'system.ini';
00071 else $filename = "mod.$module.ini";
00072 $langFile = LANGUAGE_PATH."/$langCode/$filename";
00073
00074 if (!file_exists($langFile)) return false;
00075
00076
00077 $inidata = parse_ini_file($langFile, false);
00078
00079 I18n::$_langData[$module] = $inidata;
00080
00081 return true;
00082 }
00083
00084 public static function AddLangData($from_module,$to_module=null)
00085 {
00086 if($to_module==null){
00087 $to_module = $from_module;
00088 }
00089 $langCode = I18n::getCurrentLangCode();
00090 $filename = "mod.$from_module.ini";
00091 $langFile = LANGUAGE_PATH."/$langCode/$filename";
00092 if (!file_exists($langFile)) return false;
00093 $inidata = parse_ini_file($langFile, false);
00094 if(is_array(I18n::$_langData[$to_module])){
00095 I18n::$_langData[$to_module] = array_merge(I18n::$_langData[$to_module],$inidata);
00096 }else{
00097 I18n::$_langData[$to_module] = $inidata;
00098 }
00099 return true;
00100 }
00101
00102 public static function getCurrentLangCode ()
00103 {
00104 if (I18n::$_langCode != null)
00105 return I18n::$_langCode;
00106 $currentLanguage = BizSystem::sessionContext()->getVar("LANG");
00107
00108 if ($currentLanguage == ""){
00109 $currentLanguage = BizSystem::getUserPreference("language");
00110
00111 }
00112 if($currentLanguage == ""){
00113 $currentLanguage = I18n::DEFAULT_LANGUAGE;
00114 }
00115
00116 if (isset($_GET['lang'])){
00117 $currentLanguage = $_GET['lang'];
00118 BizSystem::sessionContext()->setVar("LANG",$currentLanguage );
00119 }
00120
00121
00122
00123 BizSystem::sessionContext()->setVar("LANG", $currentLanguage);
00124 I18n::$_langCode = $currentLanguage;
00125
00126 return $currentLanguage;
00127 }
00128 }
00129 ?>