X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/098a79f0819ebb89b7d48df4a6b154af4560f68e..9a23a8c0a51b7ec38a96f525484134f3cb85dc7e:/WEB-INF/lib/I18n.class.php diff --git a/WEB-INF/lib/I18n.class.php b/WEB-INF/lib/I18n.class.php new file mode 100644 index 00000000..96c37438 --- /dev/null +++ b/WEB-INF/lib/I18n.class.php @@ -0,0 +1,167 @@ +keys".$str.";"); + } else { + $value = $this->keys[$kword]; + } + return $value; + } + + // TODO: refactoring ongoing down from here... + function getWeekDayName($id) { + $id = intval($id); + return $this->weekdayNames[$id]; + } + + function load($localName) { + $kw = array(); + $filename = strtolower($localName) . '.lang.php'; + $inc_filename = RESOURCE_DIR . '/' . $this->defaultLang . '.lang.php'; + + if (file_exists($inc_filename)) { + include($inc_filename); + + $this->monthNames = $i18n_months; + $this->weekdayNames = $i18n_weekdays; + + $this->weekdayShortNames = $i18n_weekdays_short; + if (defined('SHOW_HOLIDAYS') && isTrue(SHOW_HOLIDAYS)) { + $this->holidays = $i18n_holidays; + } + + foreach ($i18n_key_words as $kword=>$value) { + $pos = strpos($kword, "."); + if (!($pos === false)) { + $p = explode(".", $kword); + $str = ""; + foreach ($p as $w) { + $str .= "[\"".$w."\"]"; + } + //$value = addslashes($value); + eval("\$this->keys".$str."='".$value."';"); + } else { + $this->keys[$kword] = $value; + } + } + } + + $inc_filename = RESOURCE_DIR . '/' . $filename; + if (file_exists($inc_filename) && ($localName != $this->defaultLang)) { + require($inc_filename); + + $this->lang = $localName; + $this->monthNames = $i18n_months; + $this->weekdayNames = $i18n_weekdays; + $this->weekdayShortNames = $i18n_weekdays_short; + if (defined('SHOW_HOLIDAYS') && isTrue(SHOW_HOLIDAYS)) { + $this->holidays = $i18n_holidays; + } + foreach ($i18n_key_words as $kword=>$value) { + if (!$value) continue; + $pos = strpos($kword, "."); + if (!($pos === false)) { + $p = explode(".", $kword); + $str = ""; + foreach ($p as $w) { + $str .= "[\"".$w."\"]"; + } + //$value = addslashes($value); + eval("\$this->keys".$str."='".$value."';"); + } else { + $this->keys[$kword] = $value; + } + } + return true; + } + } + + function hasLang($lang) + { + $filename = RESOURCE_DIR . '/' . strtolower($lang) . '.lang.php'; + return file_exists($filename); + } + + function getBrowserLanguage() + { + $acclang = @$_SERVER['HTTP_ACCEPT_LANGUAGE']; + if (empty($acclang)) { + return ""; + } + $lang_prefs = explode(',', $acclang); + foreach ($lang_prefs as $lang_pref) { + $lang_pref_parts = explode(';', trim($lang_pref)); + $lang_parts = explode('-', trim($lang_pref_parts[0])); + $lang_main = $lang_parts[0]; + if ($this->hasLang($lang_main)) { + return $lang_main; + } + } + return ""; + } + + // getLangFileList() returns a list of language files. + static function getLangFileList() { + $fileList = array(); + $d = @opendir(RESOURCE_DIR); + while (($file = @readdir($d))) { + if (($file != ".") && ($file != "..")) { + if (strpos($file, ".lang.php")) { + $fileList[] = @basename($file); + } + } + } + @closedir($d); + return $fileList; + } + + static function getLangFromFilename($filename) + { + return substr($filename, 0, strpos($filename, '.')); + } +} +?> \ No newline at end of file