| [ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of Clearbricks. 4 # Copyright (c) 2006 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # Clearbricks is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Clearbricks is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Clearbricks; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 24 function __($str) 25 { 26 return (!empty($GLOBALS['__l10n'][$str])) ? $GLOBALS['__l10n'][$str] : $str; 27 } 28 29 class l10n 30 { 31 public static function init() 32 { 33 $GLOBALS['__l10n'] = array(); 34 $GLOBALS['__l10n_files'] = array(); 35 } 36 37 public static function set($file) 38 { 39 $lang_file = $file.'.lang'; 40 $po_file = $file.'.po'; 41 $php_file = $file.'.lang.php'; 42 43 if (file_exists($php_file)) 44 { 45 require $php_file; 46 } 47 elseif (($tmp = self::getPoFile($po_file)) !== false) 48 { 49 $GLOBALS['__l10n_files'][] = $lang_file; 50 $GLOBALS['__l10n'] = array_merge($GLOBALS['__l10n'],$tmp); 51 } 52 elseif (($tmp = self::getLangFile($lang_file)) !== false) 53 { 54 $GLOBALS['__l10n_files'][] = $lang_file; 55 $GLOBALS['__l10n'] = array_merge($GLOBALS['__l10n'],$tmp); 56 } 57 else 58 { 59 return false; 60 } 61 } 62 63 public static function getLangFile($file) 64 { 65 if (!file_exists($file)) { 66 return false; 67 } 68 69 $fp = @fopen($file,'r'); 70 71 if ($fp === false) { 72 return false; 73 } 74 75 $res = array(); 76 while ($l = fgets($fp)) 77 { 78 $l = trim($l); 79 # Comment 80 if (substr($l,0,1) == '#') { 81 continue; 82 } 83 84 # Original text 85 if (substr($l,0,1) == ';' && ($t = fgets($fp)) !== false && trim($t) != '') { 86 $res[$l] = trim($t); 87 } 88 89 } 90 fclose($fp); 91 92 return $res; 93 } 94 95 public static function getPoFile($file) 96 { 97 if (!file_exists($file)) { 98 return false; 99 } 100 101 $fc = implode('',file($file)); 102 103 $res = array(); 104 105 $matched = preg_match_all('/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+'. 106 '(msgstr\s+("([^"]|\\\\")*?(?<!\\\)"\s*)+)/', 107 $fc, $matches); 108 109 if (!$matched) { 110 return false; 111 } 112 113 for ($i=0; $i<$matched; $i++) 114 { 115 $msgid = preg_replace('/\s*msgid\s*"(.*)"\s*/s','\\1',$matches[1][$i]); 116 $msgstr= preg_replace('/\s*msgstr\s*"(.*)"\s*/s','\\1',$matches[4][$i]); 117 118 $msgstr = self::poString($msgstr); 119 120 if ($msgstr) { 121 $res[self::poString($msgid)] = $msgstr; 122 } 123 } 124 125 if (!empty($res[''])) { 126 $meta = $res['']; 127 unset($res['']); 128 } 129 130 return $res; 131 } 132 133 private static function poString($string,$reverse=false) 134 { 135 if ($reverse) { 136 $smap = array('"', "\n", "\t", "\r"); 137 $rmap = array('\\"', '\\n"' . "\n" . '"', '\\t', '\\r'); 138 return trim((string) str_replace($smap, $rmap, $string)); 139 } else { 140 $smap = array('/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\\"/'); 141 $rmap = array('', "\n", "\r", "\t", '"'); 142 return trim((string) preg_replace($smap, $rmap, $string)); 143 } 144 } 145 146 public static function getFilePath($dir,$file,$lang) 147 { 148 $f = $dir.'/'.$lang.'/'.$file; 149 if (!file_exists($f)) { 150 $f = $dir.'/en/'.$file; 151 } 152 153 return file_exists($f) ? $f : false; 154 } 155 156 public static function getISOcodes($flip=false) 157 { 158 $res = array( 159 'aa' => 'Afar', 160 'ab' => 'Abkhazian', 161 'af' => 'Afrikaans', 162 'am' => 'Amharic', 163 'ar' => 'Arabic', 164 'as' => 'Assamese', 165 'ay' => 'Aymara', 166 'az' => 'Azerbaijani', 167 'ba' => 'Bashkir', 168 'be' => 'Byelorussian', 169 'bg' => 'Bulgarian', 170 'bh' => 'Bihari', 171 'bi' => 'Bislama', 172 'bn' => 'Bengali', 173 'bo' => 'Tibetan', 174 'br' => 'Breton', 175 'ca' => 'Catalan', 176 'co' => 'Corsican', 177 'cs' => 'Czech', 178 'cy' => 'Welsh', 179 'da' => 'Danish', 180 'de' => 'German', 181 'dz' => 'Bhutani', 182 'el' => 'Greek', 183 'en' => 'English', 184 'eo' => 'Esperanto', 185 'es' => 'Spanish', 186 'et' => 'Estonian', 187 'eu' => 'Basque', 188 'fa' => 'Persian', 189 'fi' => 'Finnish', 190 'fj' => 'Fiji', 191 'fo' => 'Faeroese', 192 'fr' => 'French', 193 'fy' => 'Frisian', 194 'ga' => 'Irish', 195 'gd' => 'Gaelic', 196 'gl' => 'Galician', 197 'gn' => 'Guarani', 198 'gu' => 'Gujarati', 199 'ha' => 'Hausa', 200 'hi' => 'Hindi', 201 'hr' => 'Croatian', 202 'hu' => 'Hungarian', 203 'hy' => 'Armenian', 204 'ia' => 'Interlingua', 205 'ie' => 'Interlingue', 206 'ik' => 'Inupiak', 207 'in' => 'Indonesian', 208 'is' => 'Icelandic', 209 'it' => 'Italian', 210 'iw' => 'Hebrew', 211 'ja' => 'Japanese', 212 'ji' => 'Yiddish', 213 'jw' => 'Javanese', 214 'ka' => 'Georgian', 215 'kk' => 'Kazakh', 216 'kl' => 'Greenlandic', 217 'km' => 'Cambodian', 218 'kn' => 'Kannada', 219 'ko' => 'Korean', 220 'ks' => 'Kashmiri', 221 'ku' => 'Kurdish', 222 'ky' => 'Kirghiz', 223 'la' => 'Latin', 224 'ln' => 'Lingala', 225 'lo' => 'Laothian', 226 'lt' => 'Lithuanian', 227 'lv' => 'Latvian', 228 'mg' => 'Malagasy', 229 'mi' => 'Maori', 230 'mk' => 'Macedonian', 231 'ml' => 'Malayalam', 232 'mn' => 'Mongolian', 233 'mo' => 'Moldavian', 234 'mr' => 'Marathi', 235 'ms' => 'Malay', 236 'mt' => 'Maltese', 237 'my' => 'Burmese', 238 'na' => 'Nauru', 239 'ne' => 'Nepali', 240 'nl' => 'Dutch', 241 'no' => 'Norwegian', 242 'oc' => 'Occitan', 243 'om' => 'Oromo', 244 'or' => 'Oriya', 245 'pa' => 'Punjabi', 246 'pl' => 'Polish', 247 'ps' => 'Pashto', 248 'pt' => 'Portuguese', 249 'qu' => 'Quechua', 250 'rm' => 'Rhaeto-Romance', 251 'rn' => 'Kirundi', 252 'ro' => 'Romanian', 253 'ru' => 'Russian', 254 'rw' => 'Kinyarwanda', 255 'sa' => 'Sanskrit', 256 'sd' => 'Sindhi', 257 'sg' => 'Sangro', 258 'sh' => 'Serbo-Croatian', 259 'si' => 'Singhalese', 260 'sk' => 'Slovak', 261 'sl' => 'Slovenian', 262 'sm' => 'Samoan', 263 'sn' => 'Shona', 264 'so' => 'Somali', 265 'sq' => 'Albanian', 266 'sr' => 'Serbian', 267 'ss' => 'Siswati', 268 'st' => 'Sesotho', 269 'su' => 'Sudanese', 270 'sv' => 'Swedish', 271 'sw' => 'Swahili', 272 'ta' => 'Tamil', 273 'te' => 'Tegulu', 274 'tg' => 'Tajik', 275 'th' => 'Thai', 276 'ti' => 'Tigrinya', 277 'tk' => 'Turkmen', 278 'tl' => 'Tagalog', 279 'tn' => 'Setswana', 280 'to' => 'Tonga', 281 'tr' => 'Turkish', 282 'ts' => 'Tsonga', 283 'tt' => 'Tatar', 284 'tw' => 'Twi', 285 'uk' => 'Ukrainian', 286 'ur' => 'Urdu', 287 'uz' => 'Uzbek', 288 'vi' => 'Vietnamese', 289 'vo' => 'Volapuk', 290 'wo' => 'Wolof', 291 'xh' => 'Xhosa', 292 'yo' => 'Yoruba', 293 'zh' => 'Chinese', 294 'zu' => 'Zulu' 295 ); 296 297 if ($flip) { 298 $res = array_flip($res); 299 ksort($res); 300 } 301 302 return $res; 303 } 304 } 305 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |