| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | function get_language_file_ex($name, $l, $s) |
|---|
| 4 | { |
|---|
| 5 | static $lmap = array( |
|---|
| 6 | 'zh' => 'zh-simplified', |
|---|
| 7 | 'zh-hk' => 'zh-traditional', |
|---|
| 8 | 'zh-tw' => 'zh-traditional', |
|---|
| 9 | ); |
|---|
| 10 | static $smap = array( |
|---|
| 11 | 'gbk' => 'gb2312', |
|---|
| 12 | 'gb18030' => 'gb2312', |
|---|
| 13 | ); |
|---|
| 14 | |
|---|
| 15 | if (isset($lmap[$l])) { |
|---|
| 16 | $l = $lmap[$l]; |
|---|
| 17 | } |
|---|
| 18 | if (file_exists($file = "$name-$l-$s.lang.php")) { |
|---|
| 19 | return $file; |
|---|
| 20 | } |
|---|
| 21 | if (isset($smap[$s])) { |
|---|
| 22 | $s = $smap[$s]; |
|---|
| 23 | if (file_exists($file = "$name-$l-$s.lang.php")) { |
|---|
| 24 | return $file; |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | if (file_exists($file = "$name-$l.lang.php")) { |
|---|
| 28 | return $file; |
|---|
| 29 | } |
|---|
| 30 | return null; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | function get_language_file($name) |
|---|
| 34 | { |
|---|
| 35 | global $charset, $lang; |
|---|
| 36 | $s = strtolower($charset); |
|---|
| 37 | if (isset($lang)) { |
|---|
| 38 | $l = strtolower($lang); |
|---|
| 39 | $file = get_language_file_ex($name, $l, $s); |
|---|
| 40 | if (!isset($file)) { |
|---|
| 41 | $l = strtok($l, '-'); |
|---|
| 42 | $file = get_language_file_ex($name, $l, $s); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | else if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|---|
| 46 | foreach (explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $l) { |
|---|
| 47 | $l = strtok($l, ';'); |
|---|
| 48 | $file = get_language_file_ex($name, $l, $s); |
|---|
| 49 | if (isset($file)) { |
|---|
| 50 | $lang = $l; |
|---|
| 51 | break; |
|---|
| 52 | } |
|---|
| 53 | if (strpos($l, '-') !== false) { |
|---|
| 54 | $ll = strtok($l, '-'); |
|---|
| 55 | $file = get_language_file_ex($name, $ll, $s); |
|---|
| 56 | if (isset($file)) { |
|---|
| 57 | $lang = $l; |
|---|
| 58 | break; |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | return isset($file) ? $file : "$name-en.lang.php"; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | function _T($str) |
|---|
| 67 | { |
|---|
| 68 | if (isset($GLOBALS['strings'][$str])) { |
|---|
| 69 | return $GLOBALS['strings'][$str]; |
|---|
| 70 | } |
|---|
| 71 | if (!empty($GLOBALS['show_todo_strings'])) { |
|---|
| 72 | return '<span style="color:red">' . htmlspecialchars($str) . '</span>'; |
|---|
| 73 | } |
|---|
| 74 | return $str; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | error_reporting(E_ALL); |
|---|
| 78 | ini_set('display_errors', 'On'); |
|---|
| 79 | define('REQUEST_TIME', time()); |
|---|
| 80 | |
|---|
| 81 | $charset = "UTF-8"; |
|---|
| 82 | if (file_exists("./config.php")) { |
|---|
| 83 | include("./config.php"); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | include(get_language_file("common")); |
|---|
| 87 | if (!isset($lang)) { |
|---|
| 88 | $lang = 'en-us'; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | ?> |
|---|