| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: |
|
| 15: |
|
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: |
|
| 25: | function _t($str)
|
| 26: | {
|
| 27: | global $lc_lang;
|
| 28: | global $lc_translation;
|
| 29: | global $lc_translationEnabled;
|
| 30: |
|
| 31: | $args = func_get_args();
|
| 32: | $str = array_shift($args);
|
| 33: | $str = trim($str);
|
| 34: |
|
| 35: | if ($lc_translationEnabled == false) {
|
| 36: | return (count($args)) ? vsprintf($str, $args) : $str;
|
| 37: | }
|
| 38: |
|
| 39: | $po = session_get('po');
|
| 40: | if (!is_array($po)) {
|
| 41: | $po = array();
|
| 42: | }
|
| 43: | $po[$str] = '';
|
| 44: |
|
| 45: | if (isset($lc_translation[$lc_lang])) {
|
| 46: |
|
| 47: | $lowerStr = strtolower($str);
|
| 48: | if (isset($lc_translation[$lc_lang][$lowerStr]) && !empty($lc_translation[$lc_lang][$lowerStr])) {
|
| 49: | $translated = $lc_translation[$lc_lang][$lowerStr];
|
| 50: | $str = (is_array($translated)) ? $translated[0] : $translated;
|
| 51: | }
|
| 52: | }
|
| 53: |
|
| 54: | if (isset($translated)) {
|
| 55: | $po[$str] = $translated;
|
| 56: | }
|
| 57: | return (count($args)) ? vsprintf($str, $args) : $str;
|
| 58: | }
|
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: |
|
| 67: | function _tc($fileName, $args = array())
|
| 68: | {
|
| 69: | global $lc_defaultLang;
|
| 70: | global $lc_lang;
|
| 71: |
|
| 72: | $langs = array($lc_lang, $lc_defaultLang);
|
| 73: | foreach ($langs as $lng) {
|
| 74: | $file = I18N . 'ctn/' . $lng . '/' . $fileName . '.' . $lng;
|
| 75: | if (is_file($file) && file_exists($file)) {
|
| 76: | $content = file_get_contents($file);
|
| 77: | if (count($args)) {
|
| 78: | foreach ($args as $key => $value) {
|
| 79: | $regex = '/'.$key.'\b/i';
|
| 80: | $content = preg_replace($regex, $value, $content);
|
| 81: | }
|
| 82: | }
|
| 83: | return $content;
|
| 84: | }
|
| 85: | }
|
| 86: | return '';
|
| 87: | }
|
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: |
|
| 95: | function __i18n_load()
|
| 96: | {
|
| 97: | global $lc_lang;
|
| 98: | global $lc_translation;
|
| 99: | global $lc_translationEnabled;
|
| 100: |
|
| 101: | if ($lc_translationEnabled == false) {
|
| 102: | return false;
|
| 103: | }
|
| 104: |
|
| 105: | $filename = I18N . $lc_lang.'.po';
|
| 106: | if (!file_exists($filename)) {
|
| 107: | return false;
|
| 108: | }
|
| 109: |
|
| 110: |
|
| 111: | if (!$file = fopen($filename, 'r')) {
|
| 112: | session_delete("i18n.{$lc_lang}");
|
| 113: | return false;
|
| 114: | }
|
| 115: |
|
| 116: |
|
| 117: | if ($translations = session_get("i18n.{$lc_lang}")) {
|
| 118: | return $lc_translation[$lc_lang] = $translations;
|
| 119: | }
|
| 120: |
|
| 121: |
|
| 122: | session_delete("i18n.{$lc_lang}");
|
| 123: |
|
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: |
|
| 130: | $type = 0;
|
| 131: | $translations = array();
|
| 132: | $translationKey = '';
|
| 133: | $plural = 0;
|
| 134: | $header = '';
|
| 135: |
|
| 136: | do {
|
| 137: | $line = trim(fgets($file));
|
| 138: | if ($line === '' || $line[0] === '#') {
|
| 139: | continue;
|
| 140: | }
|
| 141: | if (preg_match("/msgid[[:space:]]+\"(.+)\"$/i", $line, $regs)) {
|
| 142: | $type = 1;
|
| 143: | $translationKey = strtolower(stripcslashes($regs[1]));
|
| 144: | } elseif (preg_match("/msgid[[:space:]]+\"\"$/i", $line, $regs)) {
|
| 145: | $type = 2;
|
| 146: | $translationKey = '';
|
| 147: | } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && ($type == 1 || $type == 2 || $type == 3)) {
|
| 148: | $type = 3;
|
| 149: | $translationKey .= strtolower(stripcslashes($regs[1]));
|
| 150: | } elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
|
| 151: | $translations[$translationKey] = stripcslashes($regs[1]);
|
| 152: | $type = 4;
|
| 153: | } elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
|
| 154: | $type = 4;
|
| 155: | $translations[$translationKey] = '';
|
| 156: | } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 4 && $translationKey) {
|
| 157: | $translations[$translationKey] .= stripcslashes($regs[1]);
|
| 158: | } elseif (preg_match("/msgid_plural[[:space:]]+\".*\"$/i", $line, $regs)) {
|
| 159: | $type = 6;
|
| 160: | } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 6 && $translationKey) {
|
| 161: | $type = 6;
|
| 162: | } elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
|
| 163: | $plural = $regs[1];
|
| 164: | $translations[$translationKey][$plural] = stripcslashes($regs[2]);
|
| 165: | $type = 7;
|
| 166: | } elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
|
| 167: | $plural = $regs[1];
|
| 168: | $translations[$translationKey][$plural] = '';
|
| 169: | $type = 7;
|
| 170: | } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 7 && $translationKey) {
|
| 171: | $translations[$translationKey][$plural] .= stripcslashes($regs[1]);
|
| 172: | } elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && $type == 2 && !$translationKey) {
|
| 173: | $header .= stripcslashes($regs[1]);
|
| 174: | $type = 5;
|
| 175: | } elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && !$translationKey) {
|
| 176: | $header = '';
|
| 177: | $type = 5;
|
| 178: | } elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 5) {
|
| 179: | $header .= stripcslashes($regs[1]);
|
| 180: | } else {
|
| 181: | unset($translations[$translationKey]);
|
| 182: | $type = 0;
|
| 183: | $translationKey = '';
|
| 184: | $plural = 0;
|
| 185: | }
|
| 186: | } while (!feof($file));
|
| 187: | fclose($file);
|
| 188: |
|
| 189: | $merge[''] = $header;
|
| 190: | $lc_translation[$lc_lang] = array_merge($merge, $translations);
|
| 191: |
|
| 192: | session_set("i18n.{$lc_lang}", $lc_translation[$lc_lang]);
|
| 193: |
|
| 194: | return $lc_translation;
|
| 195: | }
|
| 196: | |