[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/inc/ -> traduire.php (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2007                                                *
   7   *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
   8   *                                                                         *
   9   *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
  10   *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
  11  \***************************************************************************/
  12  
  13  if (!defined("_ECRIRE_INC_VERSION")) return;
  14  
  15  //
  16  // Charger un fichier langue
  17  //
  18  // http://doc.spip.org/@chercher_module_lang
  19  function chercher_module_lang($module, $lang = '') {
  20      if ($lang)
  21          $lang = '_'.$lang;
  22  
  23      // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
  24      if ($f = include_spip('lang/'.$module.$lang, false))
  25          return $f;
  26  
  27      // 2) directement dans le chemin (old style)
  28      return include_spip($module.$lang, false);
  29  }
  30  
  31  // http://doc.spip.org/@charger_langue
  32  function charger_langue($lang, $module = 'spip') {
  33      if ($lang AND $fichier_lang = chercher_module_lang($module, $lang)) {
  34          $GLOBALS['idx_lang']='i18n_'.$module.'_'.$lang;
  35          include_once($fichier_lang);
  36      } else {
  37          // si le fichier de langue du module n'existe pas, on se rabat sur
  38          // la langue par defaut du site -- et au pire sur le francais, qui
  39          // *par definition* doit exister, et on copie le tableau dans la
  40          // var liee a la langue
  41          $l = $GLOBALS['meta']['langue_site'];
  42          if (!$fichier_lang = chercher_module_lang($module, $l))
  43              $fichier_lang = chercher_module_lang($module, 'fr');
  44  
  45          if ($fichier_lang) {
  46              $GLOBALS['idx_lang']='i18n_'.$module.'_' .$l;
  47              include($fichier_lang);
  48              $GLOBALS['i18n_'.$module.'_'.$lang]
  49                  = &$GLOBALS['i18n_'.$module.'_'.$l];
  50              #spip_log("module de langue : ${module}_$l.php");
  51          }
  52      }
  53  }
  54  
  55  //
  56  // Surcharger le fichier de langue courant avec un autre (tordu, hein...)
  57  //
  58  // http://doc.spip.org/@surcharger_langue
  59  function surcharger_langue($fichier) {
  60  
  61      $idx_lang_normal = $GLOBALS['idx_lang'];
  62      $idx_lang_surcharge = $GLOBALS['idx_lang'].'_temporaire';
  63      $GLOBALS['idx_lang'] = $idx_lang_surcharge;
  64      include($fichier);
  65      if (is_array($GLOBALS[$idx_lang_surcharge])) {
  66          $GLOBALS[$idx_lang_normal] = array_merge(
  67              $GLOBALS[$idx_lang_normal],
  68              $GLOBALS[$idx_lang_surcharge]
  69          );
  70      }
  71      unset ($GLOBALS[$idx_lang_surcharge]);
  72      $GLOBALS['idx_lang'] = $idx_lang_normal;
  73  }
  74  
  75  //
  76  // Traduire une chaine internationalisee
  77  //
  78  // http://doc.spip.org/@inc_traduire_dist
  79  function inc_traduire_dist($ori, $lang) {
  80  
  81      static $deja_vu = array();
  82    
  83      if (isset($deja_vu[$lang][$ori])) {
  84            return $deja_vu[$lang][$ori];
  85      }
  86  
  87      // modules demandes explicitement
  88  
  89      if (preg_match(",^([a-z0-9/]+):(.*)$,", $ori, $regs)) {
  90              $modules = explode("/",$regs[1]);
  91              $code = $regs[2];
  92      } else     {$modules = array('spip', 'ecrire'); $code = $ori;}
  93  
  94      $text = '';
  95      // parcourir tous les modules jusqu'a ce qu'on trouve
  96      foreach ($modules as $module) {
  97          $var = "i18n_".$module."_".$lang;
  98          if (empty($GLOBALS[$var])) {
  99              charger_langue($lang, $module);
 100  
 101              // surcharge perso -- on cherche (lang/)local_xx.php ...
 102              if ($f = chercher_module_lang('local', $lang))
 103                  surcharger_langue($f);
 104              // ... puis (lang/)local.php
 105              if ($f = chercher_module_lang('local'))
 106                  surcharger_langue($f);
 107          }
 108          if (isset($GLOBALS[$var][$code])) {
 109              $text = $GLOBALS[$var][$code];
 110              break;
 111          }
 112      }
 113  
 114      // filet pour traduction pas finies 
 115      if (($lang<>'fr') AND ereg("^<(NEW|MODIF)>", $text))
 116            $text = inc_traduire_dist($ori, 'fr');
 117      $deja_vu[$lang][$code] = $text;
 118  
 119      return $text;
 120  }
 121  ?>


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics