root/trunk/uploadr/strings_extract.php

Revision 76, 2.1 kB (checked in by rcrowley, 2 years ago)

Untablified the metadata panes, better copy in all three places for 'Who can see this photo?', changes string extractor to always use the same filename but different project attributes.

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