[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/phpgwapi/js/htmlarea/plugins/ -> merge_langs (source)

   1  #!/usr/bin/php -q
   2  <?php
   3  /**************************************************************************\
   4  * eGroupWare - API htmlarea translations (according to lang in user prefs) *
   5  * http: //www.eGroupWare.org                                               *
   6  * Written by Ralf Becker <RalfBecker@outdoor-training.de>                  *
   7  * --------------------------------------------                             *
   8  *  This program is free software; you can redistribute it and/or modify it *
   9  *  under the terms of the GNU General Public License as published by the   *
  10  *  Free Software Foundation; either version 2 of the License, or (at your  *
  11  *  option) any later version.                                              *
  12  \**************************************************************************/
  13  
  14  /* $Id: merge_langs 16727 2004-08-29 01:26:17Z ralfbecker $ */
  15  
  16  $plugin_dir = realpath(dirname(__FILE__));
  17  $setup_dir = realpath(dirname(__FILE__).'/../../../setup');
  18  
  19  function load_langfile($lang)
  20  {
  21      global $setup_dir;
  22      
  23      $lang_file = $setup_dir.'/phpgw_'.$lang.'.lang';
  24      
  25      $arr = array();
  26      if (file_exists($lang_file))
  27      {
  28          foreach(file($lang_file) as $line)
  29          {
  30              @list($phrase,$app,$lang,$trans) = split("[\t\n\r]",$line);
  31              $arr[$phrase] = array(
  32                  'app' => $app,
  33                  'trans' => $trans,
  34              );
  35          }
  36      }
  37      return $arr;
  38  }
  39  
  40  function save_langfile($lang,$arr)
  41  {
  42      $content = '';
  43      ksort($arr);
  44      foreach($arr as $phrase => $data)
  45      {
  46          $content .= "$phrase\t$data[app]\t$lang\t$data[trans]\n";
  47      }
  48      global $setup_dir;
  49      $lang_file = $setup_dir.'/phpgw_'.$lang.'.lang';
  50      
  51      if ($f = fopen($lang_file,'w'))
  52      {
  53          fwrite($f,$content);
  54      }
  55      fclose($f);
  56  }
  57  
  58  $d = opendir($plugin_dir);
  59  while ($plugin = readdir($d))
  60  {
  61      if (!is_dir($plugin) || $plugin == 'CVS' || $plugin == 'CSS' || $plugin[0] == '.') continue;
  62      
  63      if (!@file_exists($lang_file = $plugin_dir.'/'.$plugin.'/lang/en.js')) continue;
  64      $lang_file = file_get_contents($lang_file);
  65      
  66      if (!preg_match_all('/"([^"]+)"[ \t:]+"([^"]+)"/',$lang_file,$matches)) continue;
  67      $token2en = array();
  68      foreach($matches[1] as $n => $token)
  69      {
  70          $token2en[$token] = $matches[2][$n];
  71      }
  72      
  73      $l = opendir($plugin_dir.'/'.$plugin.'/lang');
  74      
  75      while ($lang_file = readdir($l))
  76      {
  77          if (!preg_match('/.js$/',$lang_file)) continue;
  78          
  79          $lang = substr($lang_file,0,2);
  80          $lang_file = $plugin_dir.'/'.$plugin.'/lang/'.$lang_file;
  81          echo "\nprocessing: $lang_file\n";
  82  
  83          $lang_file = file_get_contents($lang_file);
  84          
  85          if (preg_match_all('/"([^"]+)"[ \t:]+"([^"]+)"/',$lang_file,$matches))
  86          {
  87              $arr = load_langfile($lang);
  88              $needs_save = false;
  89              
  90              foreach($matches[1] as $n => $token)
  91              {
  92                  if (!isset($token2en[$token])) continue;
  93  
  94                  $phrase = strtolower($token2en[$token]);
  95                  
  96                  if (!$phrase) continue;
  97                  
  98                  if (isset($arr[$phrase]))
  99                  {
 100                      if ($arr[$phrase]['app'] != 'common' && $arr[$phrase]['app'] != 'htmlarea-'.$plugin)
 101                      {
 102                          $arr[$phrase]['app'] = 'common';
 103                      }
 104                      continue;
 105                  }                
 106                  $arr[$phrase] = array(
 107                      'app'    => 'htmlarea-'.$plugin,
 108                      'trans' => $matches[2][$n],
 109                  );
 110                  echo "adding: $phrase = ".$matches[2][$n]."\n";
 111                  $needs_save = true;
 112              }
 113              if ($needs_save) save_langfile($lang,$arr);
 114          }
 115      }
 116  }
 117  closedir($d);


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7