3 # Program : COPS localization string generator
6 # Author : Sébastien Lucas
16 # Load php files looking for strings to localize
18 opendir (my($dirhandle), "../") or die ("Directory not found\n");
19 for (readdir ($dirhandle)) {
20 next if (-d $_ ); # skip directories
21 next if (/^[.]/); # skip dot-files
22 next if not (/(.+)[.]php$/);
24 my $file = "../" . $_;
25 debug ("text file: " . $_ . "\n");
26 my $content = loadFile ($file);
28 while ($content =~ /localize\s*\("([\w\.]*?)"\)/igs) {
33 while ($content =~ /localize\s*\("([\w\.]*?)"\s*,/igs) {
34 $allstrings{$1 . ".none"} = "";
35 $allstrings{$1 . ".one"} = "";
36 $allstrings{$1 . ".many"} = "";
42 @strings = sort (keys (%allstrings));
44 # Load existing json files with strings and values
46 opendir (my($dirhandle), "../lang") or die ("Directory not found\n");
47 for (readdir ($dirhandle)) {
48 next if (-d $_ ); # skip directories
49 next if (/^[.]/); # skip dot-files
50 next if not (/(.+)[.]json$/);
52 my $file = "../lang/" . $_;
53 (my $lang = $_) =~ s/Localization_(\w\w)\.json/$1/;
54 debug ("language file: $_ / $lang \n");
56 my $content = loadFile ($file);
58 while ($content =~ /"(.*?)"\:"(.*?)",/igs) {
60 $values{$lang}{$1} = $2;
64 open OUTPUT, ">$file.new";
67 foreach my $name (@strings) {
68 print OUTPUT "\"$name\":\"$values{$lang}{$name}\",\n";
70 print OUTPUT "\"end\":\"end\"\n";
85 my $content = <INPUT>;
94 #uncomment next line for debug messages