source: trunk/contrib/lc_parse_strings.php @ 818

Last change on this file since 818 was 677, checked in by ray, 13 years ago

set svn:keywords property for the new files & all plugins

  • Property svn:executable set to *
  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 7.5 KB
Line 
1<?php
2die("this script is disabled for security");
3
4/**
5  * LC-Parse-Strings-Script
6  *
7  * This script parses all xinhas source-files and creates base lang-files
8  * in the lang-folders (one for base and one every plugin)
9  *
10  * How To use it: - remove the die() in line 2 (security)
11  *                - make sure all lang-folders are writeable for your webserver
12  *                - open the contrib/lc_parse_strings.php in your browser
13  *                - lang/base.js will be written
14  *                - open base.js, translate all strings into your language and save it
15  *                  as yourlangauge.js
16  *                - send the translated file to the xinha-team
17 **/
18
19
20
21error_reporting(E_ALL);
22
23$ret = array();
24$files = getFiles("../", "js$");
25foreach($files as $file)
26{
27    $fp = fopen($file, "r");
28    $data = "";
29    while(!feof($fp)) {
30        $data .= fread($fp, 1024);
31    }
32
33    preg_match_all('#_lc\("([^"]+)"\)|_lc\(\'([^\']+)\'\)#', $data, $m);
34    foreach($m[1] as $i) {
35        if(trim($i)=="") continue;
36        $ret[] = $i;
37    }
38    foreach($m[2] as $i) {
39        if(trim($i)=="") continue;
40        $ret[] = $i;
41    }
42
43    if(eregi('htmlarea\\.js$', $file)) {
44        //toolbar-buttons
45        //bold:          [ "Bold"
46        preg_match_all('#[a-z]+: *\[ * "([^"]+)"#', $data, $m);
47        foreach($m[1] as $i) {
48            if(trim($i)=="") continue;
49            $ret[] = $i;
50        }
51
52        //HTMLArea._lc({key: 'button_bold', string
53        preg_match_all('#HTMLArea\\._lc\\({key: \'([^\']*)\'#', $data, $m);
54        foreach($m[1] as $i) {
55            if(trim($i)=="") continue;
56            $ret[] = $i;
57        }
58
59        //config.fontname, fontsize and formatblock
60        $data = substr($data, strpos($data, "this.fontname = {"), strpos($data, "this.customSelects = {};")-strpos($data, "this.fontname = {"));
61        preg_match_all('#"([^"]+)"[ \t]*:[ \t]*["\'][^"\']*["\'],?#', $data, $m);
62        foreach($m[1] as $i) {
63            if(trim($i)=="") continue;
64            $ret[] = $i;
65        }
66    }
67}
68
69$files = getFiles("../popups/", "html$");
70foreach($files as $file)
71{
72    if(preg_match("#custom2.html$#", $file)) continue;
73    if(preg_match('#old_#', $file)) continue;
74    $ret = array_merge($ret, parseHtmlFile($file));
75}
76$ret = array_unique($ret);
77$langData['HTMLArea'] = $ret;
78
79
80
81$plugins = getFiles("../plugins/");
82foreach($plugins as $pluginDir)
83{
84    $plugin = substr($pluginDir, 12);
85    if($plugin=="ibrowser") continue;
86    $ret = array();
87
88    $files = getFiles("$pluginDir/", "js$");
89    $files = array_merge($files, getFiles("$pluginDir/popups/", "html$"));
90    $files = array_merge($files, getFiles("$pluginDir/", "php$"));
91    foreach($files as $file)
92    {
93        $fp = fopen($file, "r");
94        $data = "";
95        if($fp) {
96            echo "$file open...<br>";
97            while(!feof($fp)) {
98              $data .= fread($fp, 1024);
99            }
100            preg_match_all('#_lc\("([^"]+)"|_lc\(\'([^\']+)\'#', $data, $m);
101            foreach($m[1] as $i) {
102                if(trim(strip_tags($i))=="") continue;
103                $ret[] = $i;
104            }
105            foreach($m[2] as $i) {
106                if(trim(strip_tags($i))=="") continue;
107                $ret[] = $i;
108            }
109        }
110    }
111
112    if($plugin=="TableOperations")
113    {
114        preg_match_all('#options = \\[([^\\]]+)\\];#', $data, $m);
115        foreach($m[1] as $i) {
116            preg_match_all('#"([^"]+)"#', $i, $m1);
117            foreach($m1[1] as $i) {
118                $ret[] = $i;
119            }
120        }
121       
122        //["cell-delete",        "td", "Delete cell"],
123        preg_match_all('#\\["[^"]+",[ \t]*"[^"]+",[ \t]*"([^"]+)"\\]#', $data, $m);
124        foreach($m[1] as $i) {
125            $ret[] = $i;
126        }
127    }
128
129
130    $files = getFiles("$pluginDir/", "html$");
131    $files = array_merge($files, getFiles("$pluginDir/", "php$"));
132    foreach($files as $file)
133    {
134        $ret = array_merge($ret, parseHtmlFile($file, $plugin));
135    }
136   
137    $files = getFiles("$pluginDir/popups/", "html$");
138    foreach($files as $file)
139    {
140        $ret = array_merge($ret, parseHtmlFile($file, $plugin));
141    }
142    $ret = array_unique($ret);
143
144    $langData[$plugin] = $ret;
145}
146
147foreach($langData as $plugin=>$strings)
148{
149    if(sizeof($strings)==0) continue;
150   
151
152    $data = "// I18N constants\n";
153    $data .= "//\n";
154    $data .= "//LANG: \"base\", ENCODING: UTF-8\n";
155    $data .= "//Author: Translator-Name, <email@example.com>\n";
156    $data .= "// FOR TRANSLATORS:\n";
157    $data .= "//\n";
158    $data .= "//   1. PLEASE PUT YOUR CONTACT INFO IN THE ABOVE LINE\n";
159    $data .= "//      (at least a valid email address)\n";
160    $data .= "//\n";
161    $data .= "//   2. PLEASE TRY TO USE UTF-8 FOR ENCODING;\n";
162    $data .= "//      (if this is not possible, please include a comment\n";
163    $data .= "//       that states what encoding is necessary.)\n";
164    $data .= "\n";
165    $data .= "{\n";
166    sort($strings);
167    foreach($strings as $string) {
168        $string = str_replace(array('\\', '"'), array('\\\\', '\\"'), $string);
169        $data .= "  \"".$string."\": \"\",\n";
170    }
171    $data = substr($data, 0, -2);
172    $data .= "\n";
173    $data .= "}\n";
174
175    if($plugin=="HTMLArea")
176        $file = "../lang/base.js";
177    else
178        $file = "../plugins/$plugin/lang/base.js";
179   
180    $fp = fopen($file, "w");
181    if(!$fp) continue;
182    fwrite($fp, $data);
183    fclose($fp);
184    echo "$file written...<br>";
185}
186
187
188
189
190function parseHtmlFile($file, $plugin="")
191{
192    $ret = array();
193   
194    $fp = fopen($file, "r");
195    if(!$fp) {
196        die("invalid fp");
197    }
198    $data = "";
199    while(!feof($fp)) {
200        $data .= fread($fp, 1024);
201    }
202   
203    if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker") {
204        //<l10n>-tags for inline-dialog or panel-dialog based dialogs
205        $elems = array("l10n");
206    } else {
207        $elems = array("title", "input", "select", "legend", "span", "option", "td", "button", "div", "label");
208    }
209    foreach($elems as $elem) {
210        preg_match_all("#<{$elem}[^>]*>([^<^\"]+)</$elem>#i", $data, $m);
211        foreach($m[1] as $i) {
212            if(trim(strip_tags($i))=="") continue;
213            if($i=="/") continue;
214            if($plugin=="ImageManager" && preg_match('#^--+$#', $i)) continue; //skip those ------
215            if($plugin=="CharacterMap" && preg_match('#&[a-z0-9]+;#i', trim($i)) || $i=="@") continue;
216            if($plugin=="SpellChecker" && preg_match('#^\'\\.\\$[a-z]+\\.\'$#', $i)) continue;
217            $ret[] = trim($i);
218        }
219    }
220   
221    if($plugin=="FormOperations" || $plugin=="SuperClean" || $plugin=="Linker")
222    {
223        //_( for inline-dialog or panel-dialog based dialogs
224        preg_match_all('#"_\(([^"]+)\)"#i', $data, $m);
225        foreach($m[1] as $i) {
226            if(trim($i)=="") continue;
227            $ret[] = $i;
228        }
229    }
230    else
231    {
232        preg_match_all('#title="([^"]+)"#i', $data, $m);
233        foreach($m[1] as $i) {
234            if(trim(strip_tags($i))=="") continue;
235            if(strip_tags($i)==" - ") continue; //skip those - (ImageManager)
236            $ret[] = $i;
237        }
238    }
239    return($ret);
240}
241
242
243function getFiles($rootdirpath, $eregi_match='') {
244 $array = array();
245 if ($dir = @opendir($rootdirpath)) {
246   $array = array();
247   while (($file = readdir($dir)) !== false) {
248     if($file=="." || $file==".." || $file==".svn") continue;
249      if($eregi_match=="")
250        $array[] = $rootdirpath."/".$file;
251      else if(eregi($eregi_match,$file))
252        $array[] = $rootdirpath."/".$file;
253     
254   }
255   closedir($dir);
256 }
257 return $array;
258}
259
260
261
262
263
264?>
Note: See TracBrowser for help on using the repository browser.