[ Index ]
 

Code source de Dotclear 1.2.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/inc/libs/ -> lib.l10n.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2004 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear 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  # DotClear 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 DotClear; 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  	function init()
  32      {
  33          $GLOBALS['__l10n'] = array();
  34          $GLOBALS['__l10n_files'] = array();
  35      }
  36      
  37  	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 = l10n::getPoFile($po_file)) !== false)
  48          {
  49              $GLOBALS['__l10n_files'][] = $lang_file;
  50              $GLOBALS['__l10n'] = array_merge($GLOBALS['__l10n'],$tmp);
  51          }*/
  52          elseif (($tmp = l10n::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  	function getLangFile($file)
  64      {
  65          if (!file_exists($file)) {
  66              //trigger_error('l10n file not found',E_USER_NOTICE);
  67              return false;
  68          }
  69          
  70          $f = file($file);
  71          $res = array();
  72          
  73          for ($i=0; $i<count($f); $i++) {
  74              if (substr($f[$i],0,1) == ';' && !empty($f[$i+1])) {
  75                  $res[trim(substr($f[$i],1))] = trim($f[$i+1]);
  76                  $i++;
  77              }
  78          }
  79          
  80          return $res;
  81      }
  82      
  83  	function getPoFile($file)
  84      {
  85          if (!file_exists($file)) {
  86              //trigger_error('l10n file not found',E_USER_NOTICE);
  87              return false;
  88          }
  89          
  90          $fc = implode('',file($file));
  91          
  92          $res = array();
  93          
  94          $matched = preg_match_all('/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+'.
  95          '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/',
  96          $fc, $matches);
  97          
  98          if (!$matched) {
  99              return false;
 100          }
 101          
 102          for ($i=0; $i<$matched; $i++)
 103          {
 104              $msgid = preg_replace('/\s*msgid\s*"(.*)"\s*/s','\\1',$matches[1][$i]);
 105              $msgstr= preg_replace('/\s*msgstr\s*"(.*)"\s*/s','\\1',$matches[4][$i]);
 106              $res[l10n::poString($msgid)] = l10n::poString($msgstr);
 107          }
 108          
 109          if (!empty($res[''])) {
 110              $meta = $res[''];
 111              unset($res['']);
 112          }
 113          
 114          return $res;
 115      }
 116      
 117  	function poString($string,$reverse=false)
 118      {
 119          if ($reverse) {
 120              $smap = array('"', "\n", "\t", "\r");
 121              $rmap = array('\\"', '\\n"' . "\n" . '"', '\\t', '\\r');
 122              return (string) str_replace($smap, $rmap, $string);
 123          } else {
 124              $smap = array('/"\s+"/', '/\\\\n/', '/\\\\r/', '/\\\\t/', '/\\"/');
 125              $rmap = array('', "\n", "\r", "\t", '"');
 126              return (string) preg_replace($smap, $rmap, $string);
 127          }
 128      }
 129      
 130  	function lang2po($file)
 131      {
 132          $map = l10n::getLangFile($file);
 133          
 134          if ($map === false) {
 135              return false;
 136          }
 137          
 138          $res = '';
 139          
 140          foreach ($map as $k => $v)
 141          {
 142              $res .= "\n".'msgid "'.l10n::poString($k,true).'"'."\n";
 143              $res .= 'msgstr "'.l10n::poString($v,true).'"'."\n";
 144          }
 145          
 146          return $res;
 147      }
 148      
 149  	function getHtmlFile($dir,$file,$lang,$encoding)
 150      {
 151          if ($encoding == 'UTF-8') {
 152              $lang .= '-utf8';
 153          }
 154          
 155          $f = $dir.'/'.$lang.'/'.$file;
 156          if (!file_exists($f)) {
 157              $f = $dir.'/en/'.$file;
 158          }
 159          
 160          if (!file_exists($f)) {
 161              return '<p>No file.</p>';
 162          } else {
 163              return implode('',file($f));
 164          }
 165      }
 166      
 167  	function getISOcodes($flip=false)
 168      {
 169          $res = array(
 170          'aa' => 'Afar',
 171          'ab' => 'Abkhazian',
 172          'af' => 'Afrikaans',
 173          'am' => 'Amharic',
 174          'ar' => 'Arabic',
 175          'as' => 'Assamese',
 176          'ay' => 'Aymara',
 177          'az' => 'Azerbaijani',
 178          'ba' => 'Bashkir',
 179          'be' => 'Byelorussian',
 180          'bg' => 'Bulgarian',
 181          'bh' => 'Bihari',
 182          'bi' => 'Bislama',
 183          'bn' => 'Bengali',
 184          'bo' => 'Tibetan',
 185          'br' => 'Breton',
 186          'ca' => 'Catalan',
 187          'co' => 'Corsican',
 188          'cs' => 'Czech',
 189          'cy' => 'Welsh',
 190          'da' => 'Danish',
 191          'de' => 'German',
 192          'dz' => 'Bhutani',
 193          'el' => 'Greek',
 194          'en' => 'English',
 195          'eo' => 'Esperanto',
 196          'es' => 'Spanish',
 197          'et' => 'Estonian',
 198          'eu' => 'Basque',
 199          'fa' => 'Persian',
 200          'fi' => 'Finnish',
 201          'fj' => 'Fiji',
 202          'fo' => 'Faeroese',
 203          'fr' => 'French',
 204          'fy' => 'Frisian',
 205          'ga' => 'Irish',
 206          'gd' => 'Gaelic',
 207          'gl' => 'Galician',
 208          'gn' => 'Guarani',
 209          'gu' => 'Gujarati',
 210          'ha' => 'Hausa',
 211          'hi' => 'Hindi',
 212          'hr' => 'Croatian',
 213          'hu' => 'Hungarian',
 214          'hy' => 'Armenian',
 215          'ia' => 'Interlingua',
 216          'ie' => 'Interlingue',
 217          'ik' => 'Inupiak',
 218          'in' => 'Indonesian',
 219          'is' => 'Icelandic',
 220          'it' => 'Italian',
 221          'iw' => 'Hebrew',
 222          'ja' => 'Japanese',
 223          'ji' => 'Yiddish',
 224          'jw' => 'Javanese',
 225          'ka' => 'Georgian',
 226          'kk' => 'Kazakh',
 227          'kl' => 'Greenlandic',
 228          'km' => 'Cambodian',
 229          'kn' => 'Kannada',
 230          'ko' => 'Korean',
 231          'ks' => 'Kashmiri',
 232          'ku' => 'Kurdish',
 233          'ky' => 'Kirghiz',
 234          'la' => 'Latin',
 235          'ln' => 'Lingala',
 236          'lo' => 'Laothian',
 237          'lt' => 'Lithuanian',
 238          'lv' => 'Latvian',
 239          'mg' => 'Malagasy',
 240          'mi' => 'Maori',
 241          'mk' => 'Macedonian',
 242          'ml' => 'Malayalam',
 243          'mn' => 'Mongolian',
 244          'mo' => 'Moldavian',
 245          'mr' => 'Marathi',
 246          'ms' => 'Malay',
 247          'mt' => 'Maltese',
 248          'my' => 'Burmese',
 249          'na' => 'Nauru',
 250          'ne' => 'Nepali',
 251          'nl' => 'Dutch',
 252          'no' => 'Norwegian',
 253          'oc' => 'Occitan',
 254          'om' => 'Oromo',
 255          'or' => 'Oriya',
 256          'pa' => 'Punjabi',
 257          'pl' => 'Polish',
 258          'ps' => 'Pashto',
 259          'pt' => 'Portuguese',
 260          'qu' => 'Quechua',
 261          'rm' => 'Rhaeto-Romance',
 262          'rn' => 'Kirundi',
 263          'ro' => 'Romanian',
 264          'ru' => 'Russian',
 265          'rw' => 'Kinyarwanda',
 266          'sa' => 'Sanskrit',
 267          'sd' => 'Sindhi',
 268          'sg' => 'Sangro',
 269          'sh' => 'Serbo-Croatian',
 270          'si' => 'Singhalese',
 271          'sk' => 'Slovak',
 272          'sl' => 'Slovenian',
 273          'sm' => 'Samoan',
 274          'sn' => 'Shona',
 275          'so' => 'Somali',
 276          'sq' => 'Albanian',
 277          'sr' => 'Serbian',
 278          'ss' => 'Siswati',
 279          'st' => 'Sesotho',
 280          'su' => 'Sudanese',
 281          'sv' => 'Swedish',
 282          'sw' => 'Swahili',
 283          'ta' => 'Tamil',
 284          'te' => 'Tegulu',
 285          'tg' => 'Tajik',
 286          'th' => 'Thai',
 287          'ti' => 'Tigrinya',
 288          'tk' => 'Turkmen',
 289          'tl' => 'Tagalog',
 290          'tn' => 'Setswana',
 291          'to' => 'Tonga',
 292          'tr' => 'Turkish',
 293          'ts' => 'Tsonga',
 294          'tt' => 'Tatar',
 295          'tw' => 'Twi',
 296          'uk' => 'Ukrainian',
 297          'ur' => 'Urdu',
 298          'uz' => 'Uzbek',
 299          'vi' => 'Vietnamese',
 300          'vo' => 'Volapuk',
 301          'wo' => 'Wolof',
 302          'xh' => 'Xhosa',
 303          'yo' => 'Yoruba',
 304          'zh' => 'Chinese',
 305          'zu' => 'Zulu'
 306          );
 307          
 308          if ($flip) {
 309              $res = array_flip($res);
 310              ksort($res);
 311          }
 312          
 313          return $res;
 314      }
 315  }
 316  
 317  ?>


Généré le : Fri Feb 23 21:40:15 2007 par Balluche grâce à PHPXref 0.7