openerp /web/js/xinha/contrib/lc_parse_strings.php

Language PHP Lines 265
MD5 Hash 02dcaf2343b0d1be1176542ed22828f8 Estimated Cost $4,986 (why?)
Repository https://openerp.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
//die("this script is disabled for security");

/**
  * LC-Parse-Strings-Script
  *
  * This script parses all xinhas source-files and creates base lang-files
  * in the lang-folders (one for base and one every plugin)
  *
  * How To use it: - remove the die() in line 2 (security)
  *                - make sure all lang-folders are writeable for your webserver
  *                - open the contrib/lc_parse_strings.php in your browser
  *                - lang/base.js will be written
  *                - open base.js, translate all strings into your language and save it
  *                  as yourlangauge.js
  *                - send the translated file to the xinha-team
 **/



error_reporting(E_ALL);

$ret = array();
$files = getFiles("../", "js$");
foreach($files as $file)
{
    $fp = fopen($file, "r");
    $data = "";
    while(!feof($fp)) {
        $data .= fread($fp, 1024);
    }

    preg_match_all('#_lc\("([^"]+)"\)|_lc\(\'([^\']+)\'\)#', $data, $m);
    foreach($m[1] as $i) {
        if(trim($i)=="") continue;
        $ret[] = $i;
    }
    foreach($m[2] as $i) {
        if(trim($i)=="") continue;
        $ret[] = $i;
    }

    if(eregi('htmlarea\\.js$', $file)) {
        //toolbar-buttons
        //bold:          [ "Bold"
        preg_match_all('#[a-z]+: *\[ * "([^"]+)"#', $data, $m);
        foreach($m[1] as $i) {
            if(trim($i)=="") continue;
            $ret[] = $i;
        }

        //HTMLArea._lc({key: 'button_bold', string
        preg_match_all('#HTMLArea\\._lc\\({key: \'([^\']*)\'#', $data, $m);
        foreach($m[1] as $i) {
            if(trim($i)=="") continue;
            $ret[] = $i;
        }

        //config.fontname, fontsize and formatblock
        $data = substr($data, strpos($data, "this.fontname = {"), strpos($data, "this.customSelects = {};")-strpos($data, "this.fontname = {"));
        preg_match_all('#"([^"]+)"[ \t]*:[ \t]*["\'][^"\']*["\'],?#', $data, $m);
        foreach($m[1] as $i) {
            if(trim($i)=="") continue;
            $ret[] = $i;
        }
    }
}

$files = getFiles("../popups/", "html$");
foreach($files as $file)
{
    if(preg_match("#custom2.html$#", $file)) continue;
    if(preg_match('#old_#', $file)) continue;
    $ret = array_merge($ret, parseHtmlFile($file));
}
$ret = array_unique($ret);
$langData['HTMLArea'] = $ret;



$plugins = getFiles("../plugins/");
foreach($plugins as $pluginDir)
{
    $plugin = substr($pluginDir, 12);
    if($plugin=="ibrowser") continue;
    $ret = array();

    $files = getFiles("$pluginDir/", "js$");
    $files = array_merge($files, getFiles("$pluginDir/popups/", "html$"));
    $files = array_merge($files, getFiles("$pluginDir/", "php$"));
    foreach($files as $file)
    {
        $fp = fopen($file, "r");
        $data = "";
        if($fp) {
            echo "$file open...<br>";
            while(!feof($fp)) {
              $data .= fread($fp, 1024);
            }
            preg_match_all('#_lc\("([^"]+)"|_lc\(\'([^\']+)\'#', $data, $m);
            foreach($m[1] as $i) {
                if(trim(strip_tags($i))=="") continue;
                $ret[] = $i;
            }
            foreach($m[2] as $i) {
                if(trim(strip_tags($i))=="") continue;
                $ret[] = $i;
            }
        }
    }

    if($plugin=="TableOperations")
    {
        preg_match_all('#options = \\[([^\\]]+)\\];#', $data, $m);
        foreach($m[1] as $i) {
            preg_match_all('#"([^"]+)"#', $i, $m1);
            foreach($m1[1] as $i) {
                $ret[] = $i;
            }
        }
        
        //["cell-delete",        "td", "Delete cell"],
        preg_match_all('#\\["[^"]+",[ \t]*"[^"]+",[ \t]*"([^"]+)"\\]#', $data, $m);
        foreach($m[1] as $i) {
            $ret[] = $i;
        }
    }


    $files = getFiles("$pluginDir/", "html$");
    $files = array_merge($files, getFiles("$pluginDir/", "php$"));
    foreach($files as $file)
    {
        $ret = array_merge($ret, parseHtmlFile($file, $plugin));
    }
    
    $files = getFiles("$pluginDir/popups/", "html$");
    foreach($files as $file)
    {
        $ret = array_merge($ret, parseHtmlFile($file, $plugin));
    }
    $ret = array_unique($ret);

    $langData[$plugin] = $ret;
}

foreach($langData as $plugin=>$strings)
{
    if(sizeof($strings)==0) continue;
    

    $data = "// I18N constants\n";
    $data .= "//\n";
    $data .= "//LANG: \"base\", ENCODING: UTF-8\n";
    $data .= "//Author: Translator-Name, <email@example.com>\n";
    $data .= "// FOR TRANSLATORS:\n";
    $data .= "//\n";
    $data .= "//   1. PLEASE PUT YOUR CONTACT INFO IN THE ABOVE LINE\n";
    $data .= "//      (at least a valid email address)\n";
    $data .= "//\n";
    $data .= "//   2. PLEASE TRY TO USE UTF-8 FOR ENCODING;\n";
    $data .= "//      (if this is not possible, please include a comment\n";
    $data .= "//       that states what encoding is necessary.)\n";
    $data .= "\n";
    $data .= "{\n";
    sort($strings);
    foreach($strings as $string) {
        $string = str_replace(array('\\', '"'), array('\\\\', '\\"'), $string);
        $data .= "  \"".$string."\": \"\",\n";
    }
    $data = substr($data, 0, -2);
    $data .= "\n";
    $data .= "}\n";

    if($plugin=="HTMLArea")
        $file = "../lang/base.js";
    else
        $file = "../plugins/$plugin/lang/base.js";
    
    $fp = fopen($file, "w");
    if(!$fp) continue;
    fwrite($fp, $data);
    fclose($fp);
    echo "$file written...<br>";
}




function parseHtmlFile($file, $plugin="")
{
    $ret = array();
    
    $fp = fopen($file, "r");
    if(!$fp) {
        die("invalid fp");
    }
    $data = "";
    while(!feof($fp)) {
        $data .= fread($fp, 1024);
    }
    
    if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker") {
        //<l10n>-tags for inline-dialog or panel-dialog based dialogs
        $elems = array("l10n");
    } else {
        $elems = array("title", "input", "select", "legend", "span", "option", "td", "button", "div", "label");
    }
    foreach($elems as $elem) {
        preg_match_all("#<{$elem}[^>]*>([^<^\"]+)</$elem>#i", $data, $m);
        foreach($m[1] as $i) {
            if(trim(strip_tags($i))=="") continue;
            if($i=="/") continue;
            if($plugin=="ImageManager" && preg_match('#^--+$#', $i)) continue; //skip those ------
            if($plugin=="CharacterMap" && preg_match('#&[a-z0-9]+;#i', trim($i)) || $i=="@") continue;
            if($plugin=="SpellChecker" && preg_match('#^\'\\.\\$[a-z]+\\.\'$#', $i)) continue;
            $ret[] = trim($i);
        }
    }
    
    if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker")
    {
        //_( for inline-dialog or panel-dialog based dialogs
        preg_match_all('#"_\(([^"]+)\)"#i', $data, $m);
        foreach($m[1] as $i) {
            if(trim($i)=="") continue;
            $ret[] = $i;
        }
    }
    else
    {
        preg_match_all('#title="([^"]+)"#i', $data, $m);
        foreach($m[1] as $i) {
            if(trim(strip_tags($i))=="") continue;
            if(strip_tags($i)==" - ") continue; //skip those - (ImageManager)
            $ret[] = $i;
        }
    }
    return($ret);
}


function getFiles($rootdirpath, $eregi_match='') {
 $array = array();
 if ($dir = @opendir($rootdirpath)) {
   $array = array();
   while (($file = readdir($dir)) !== false) {
     if($file=="." || $file==".." || $file==".svn") continue;
      if($eregi_match=="")
        $array[] = $rootdirpath."/".$file;
      else if(eregi($eregi_match,$file))
        $array[] = $rootdirpath."/".$file;
      
   }
   closedir($dir);
 }
 return $array;
}





?>
Back to Top