root/trunk/uploadr/strings_extract.php

Revision 138, 1.9 kB (checked in by rcrowley, 2 years ago)

Made script case-insensitive for string names.

Line 
1 <?
2
3     # Aaaand back to the way it was
4     $dir = dirname(__FILE__);
5     $locale = "$dir/MacUploadr.app/Contents/Resources/chrome/locale/en-US";
6
7     # Gotta have a project name
8     if (!isset($argv[1])) {
9         die("Usage: $argv[0] <project>\n");
10     }
11     $project = $argv[1];
12
13     #
14     # find files we care about
15     #
16
17     $dh = opendir($locale);
18     while (($file = readdir($dh)) !== false){
19
20         if (preg_match('!\.dtd!', $file)){ do_dtd($file); }
21         if (preg_match('!\.properties!', $file)){ do_props($file); }
22     }
23     closedir($dh);
24
25     ##############################################################################################
26
27     function do_dtd($file){
28
29         global $locale, $str_hash, $dir, $project;
30
31         $content = implode(file("$locale/$file"));
32
33         $str_hash = array();
34
35         $content = preg_replace_callback('!ENTITY ([A-Za-z0-9._]+) "([^"]+)"!', 'markup_dtd',
36             $content);
37
38         $content .= "\n\n";
39
40         foreach ($str_hash as $k => $v){
41
42             $v = implode('{TOKEN}', $v);
43             $content .= "<!ENTITY $k.joined \"<!! dev=\"$project\">$v</!!>\">\n";
44         }
45
46         $fh = fopen("$dir/ext_uploadr3_{$file}.txt", 'w');
47         fwrite($fh, $content);
48         fclose($fh);
49
50         echo "wrote $dir/ext_uploadr3_{$file}.txt\n";
51     }
52
53     function markup_dtd($m){
54
55         global $project;
56
57         if (preg_match('!^(.*)\.(\d+)$!', $m[1], $m2)){
58
59             if ($m2[2] < 10){
60
61                 $GLOBALS[str_hash][$m2[1]][$m2[2]] = $m[2];
62
63                 return "ENTITY $m[1] \"$m[2]\"";
64             }
65         }
66
67         return "ENTITY $m[1] \"<!! dev=\"$project\">$m[2]</!!>\"";
68     }
69
70     ##############################################################################################
71
72     function do_props($file){
73
74         global $locale, $dir, $project;
75
76         $content = implode(file("$locale/$file"));
77
78         $content = preg_replace('!^([a-z0-9._]+)=(.*)$!im', "$1=<!! dev=\"$project\">$2</!!>",
79             $content);
80
81         $fh = fopen("$dir/ext_uploadr3_{$file}.txt", 'w');
82         fwrite($fh, $content);
83         fclose($fh);
84
85         echo "wrote $dir/ext_uploadr3_{$file}.txt\n";
86     }
87
88     ##############################################################################################
89
90 ?>
91
Note: See TracBrowser for help on using the browser.