source: branches/2.3/tools/replace.php @ 28890

Last change on this file since 28890 was 5295, checked in by nikrou, 15 years ago

Fixed missing keys in nbm
replace script must use language/templates files and not english

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/usr/bin/php -qn
2<?php
3if (isset($_SERVER['argc']) && $_SERVER['argc']<=1) 
4{
5  echo "\n";
6  echo 'usage : ', basename($_SERVER['argv'][0]), " <filename>\n";
7  echo "\n";
8  exit(1);
9}
10
11$filename = trim($_SERVER['argv'][1]);
12$lines = file($filename);
13$content = file_get_contents($filename);
14
15$n = 0;
16$nbLines = count($lines);
17
18$pattern = "`(.*{')(.*)('\|@translate}.*)`Um";
19$replace = "'{\''.keyReplace('\\1').'\'|@translate}'";
20
21include "language/templates/common.lang.php";
22include "language/templates/admin.lang.php";
23include "language/templates/upgrade.lang.php";
24include "language/templates/install.lang.php";
25
26while ($n < $nbLines) {
27  preg_match_all($pattern, $lines[$n], $matches);
28  echo str_replace($matches[2], keyReplace($matches[2]), $lines[$n]);
29  $n++;
30}
31
32function keyReplace($key) {
33  global $lang;
34
35  if (is_array($key)) {
36    $translation = array();
37    foreach ($key as $i => $k) {
38      if (isset($lang[$k])) {
39        $translation = addslashes($lang[$k]);
40      } else {
41        $translation = "$k";
42      }     
43    }
44  } else {
45    if (isset($lang[$key])) {
46      $translation = addslashes($lang[$key]);
47    } else {
48      $translation = "$key";
49    }
50  }
51  return $translation;
52}
53?>
Note: See TracBrowser for help on using the repository browser.