1 | #! /usr/bin/perl -w
|
---|
2 |
|
---|
3 | # extract_text.pl extracts the text from macro files, install scripts
|
---|
4 | # etc. for translation.
|
---|
5 |
|
---|
6 | # output is currently to a tab separated list, suitable for importing into
|
---|
7 | # excel.
|
---|
8 |
|
---|
9 |
|
---|
10 | BEGIN {
|
---|
11 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
12 | }
|
---|
13 |
|
---|
14 | my $installsh = "$ENV{'GSDLHOME'}/Install.sh";
|
---|
15 | my $macrosdir = "$ENV{'GSDLHOME'}/macros";
|
---|
16 |
|
---|
17 | my $texthash = {};
|
---|
18 |
|
---|
19 | # first extract all the itextn variables from Install.sh
|
---|
20 | open (INSTALLSH, $installsh) || die;
|
---|
21 | undef $/;
|
---|
22 | my $file = <INSTALLSH>;
|
---|
23 | $/ = "\n";
|
---|
24 | close INSTALLSH;
|
---|
25 |
|
---|
26 | $texthash->{'install_sh'} = {};
|
---|
27 | while ($file =~ s/^(itext\d+)=\"(.*?)(?<!\\)\"//sm) {
|
---|
28 | my $key = $1;
|
---|
29 | my $value = $2;
|
---|
30 | $value =~ s/\n+/ /gs;
|
---|
31 | if (defined ($texthash->{'install_sh'}->{$key})) {
|
---|
32 | print STDERR "ERROR: $1 already defined\n";
|
---|
33 | }
|
---|
34 | $texthash->{'install_sh'}->{$key} = $value;
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | # now grab the text from the macro files
|
---|
39 | $texthash->{'macros'} = {};
|
---|
40 |
|
---|
41 | # english.dm
|
---|
42 | &grab_macros("$macrosdir/english.dm");
|
---|
43 | # english2.dm
|
---|
44 | &grab_macros("$macrosdir/english2.dm");
|
---|
45 |
|
---|
46 | # print out the result
|
---|
47 | foreach my $type (keys (%$texthash)) {
|
---|
48 | print STDOUT "type:\t$type\n";
|
---|
49 | foreach my $key (sort keys (%{$texthash->{$type}})) {
|
---|
50 | print STDOUT "$key\t$texthash->{$type}->{$key}\n";
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | sub grab_macros {
|
---|
55 | my ($filename) = @_;
|
---|
56 |
|
---|
57 | my $line = "";
|
---|
58 | my $pack = "Global";
|
---|
59 | my $macroname = "";
|
---|
60 | my $macrovalue = "";
|
---|
61 | open (FILE, $filename) || die;
|
---|
62 | while (defined ($line = <FILE>)) {
|
---|
63 | if ($line =~ /^package (\w+)/) {
|
---|
64 | $pack = $1;
|
---|
65 | $macroname = "";
|
---|
66 | $macrovalue = "";
|
---|
67 | next;
|
---|
68 | }
|
---|
69 |
|
---|
70 | if ($line =~ /^_([^_\s]+)_\s*(?:\[[^\]]*\])?\s*\{(.*)$/s) {
|
---|
71 | die "ERROR 1\n" if ($macroname ne "" || $macrovalue ne "");
|
---|
72 | $macroname = $1;
|
---|
73 | $macrovalue = $2 if defined $2;
|
---|
74 | if ($macrovalue =~ s/^(.*?)(?<!\\)\}/$1/) {
|
---|
75 | &addmacro($pack, \$macroname, \$macrovalue);
|
---|
76 | }
|
---|
77 | } elsif ($macroname ne "") {
|
---|
78 | if ($line =~ /^(.*?)(?<!\\)\}/) {
|
---|
79 | $macrovalue .= $1 if defined $1;
|
---|
80 | &addmacro($pack, \$macroname, \$macrovalue);
|
---|
81 | } else {
|
---|
82 | $macrovalue .= $line;
|
---|
83 | }
|
---|
84 | } elsif ($line =~ /^\#\# \"([^\"]+)\" \#\# \w+ \#\# (\w+) \#\#/) {
|
---|
85 | my $imagename = "image:$2";
|
---|
86 | my $imagetext = $1;
|
---|
87 | &addmacro($pack, \$imagename, \$imagetext);
|
---|
88 | }
|
---|
89 | }
|
---|
90 | close FILE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | sub addmacro {
|
---|
94 | my ($pack, $nameref, $valref) = @_;
|
---|
95 |
|
---|
96 | if ($$nameref !~ /^(httpicon|width|height)/) {
|
---|
97 |
|
---|
98 | my $name = "$pack:$$nameref";
|
---|
99 |
|
---|
100 | if (defined ($texthash->{'macros'}->{$name})) {
|
---|
101 | print STDERR "ERROR: $name already defined\n";
|
---|
102 | }
|
---|
103 |
|
---|
104 | $$valref =~ s/\n+/ /gs;
|
---|
105 | $texthash->{'macros'}->{$name} = $$valref;
|
---|
106 | }
|
---|
107 |
|
---|
108 | else {
|
---|
109 | # print STDERR "ignoring $$nameref\n";
|
---|
110 | }
|
---|
111 |
|
---|
112 | $$nameref = "";
|
---|
113 | $$valref = "";
|
---|
114 | }
|
---|