2 # Convert words in lang/en files from UK to US spelling.
3 # Create lang/en_GB files containing words that are different.
5 if ($ARGV[0] eq "--svn" || $ARGV[0] eq "-svn") {
10 chdir("/usr/local/webadmin");
17 foreach $d (readdir(DIR)) {
18 push(@modules, $d) if (-r "$d/module.info");
24 open(MAPPING, "english-mappings.txt") ||
25 die "Failed to open english-mappings.txt";
29 my ($us, $uk) = split(/\t+/, $_);
31 push(@us_mappings, [ $us, $uk ]);
35 @uk_mappings = map { [ $_->[1], $_->[0] ] } @us_mappings;
36 print STDERR "Found ",scalar(@uk_mappings)," mappings\n";
38 # Do all the given modules
40 foreach $m (@modules) {
41 print STDERR "Doing module $m\n";
42 push(@rv, &fix_english_file("$m/lang/en", "$m/lang/en_GB", 1));
43 push(@rv, &fix_english_file("$m/config.info",
44 "$m/config.info.en_GB", 1));
45 opendir(HELP, "$m/help");
46 foreach $h (readdir(HELP)) {
47 if ($h =~ /^([^\.]+)\.html$/) {
48 push(@rv, &fix_english_file("$m/help/$h",
49 "$m/help/$1.en_GB.html", 0));
55 # Print and commit the files
59 ($dir, $rest) = split(/\//, $f, 2);
60 system("cd $dir ; svn add $rest ; svn commit -m '$svn' $rest");
66 local ($us, $uk, $linefmt) = @_;
67 return ( ) if (!-r $us);
70 # Webmin = separated line file
72 # First fix up any UK spellings in the US file
74 &read_file($us, \%uslines);
76 foreach my $k (keys %uslines) {
78 $usv = &convert_to_us($v);
85 &write_file($us, \%uslines);
89 # Then create a UK file with only lines that need changing
91 &read_file($uk, \%uklines);
93 foreach my $k (keys %uslines) {
95 $ukv = &convert_to_uk($v);
96 if ($ukv ne $v && $uklines{$k} ne $ukv) {
102 &write_file($uk, \%uklines);
109 # First fix up any UK spellings in the US file
110 local $ustext = &read_file_contents($us);
111 $usv = &convert_to_us($ustext);
112 if ($usv ne $ustext) {
113 &write_file_contents($us, $usv);
117 # Then create a UK file
118 $uktext = &read_file_contents($uk);
119 $ukv = &convert_to_uk($usv);
120 if ($uktext ne $ukv && $ukv ne $usv) {
121 &write_file_contents($uk, $ukv);
131 return &convert_mapping($str, \@uk_mappings);
137 return &convert_mapping($str, \@us_mappings);
142 local ($str, $fromto) = @_;
143 foreach my $w (@$fromto) {
144 my ($from, $to) = @$w;
145 $str =~ s/(\s|^)\Q$from\E(\s|$)/$1$to$2/g;
146 $from = ucfirst($from);
148 $str =~ s/(\s|^)\Q$from\E(\s|$)/$1$to$2/g;
153 # read_file(file, &assoc, [&order], [lowercase])
154 # Fill an associative array with name=value pairs from a file
157 open(ARFILE, $_[0]) || return 0;
160 if (!/^#/ && /^([^=]+)=(.*)$/) {
161 $_[1]->{$_[3] ? lc($1) : $1} = $2;
162 push(@{$_[2]}, $1) if ($_[2]);
165 push(@{$_[2]}, undef) if ($_[2]);
172 # write_file(file, array)
173 # Write out the contents of an associative array as name=value lines
177 &read_file($_[0], \%old, \@order);
178 open(ARFILE, ">$_[0]");
179 foreach $k (@order) {
183 elsif (exists($_[1]->{$k})) {
184 print ARFILE $k,"=",$_[1]->{$k},"\n";
187 foreach $k (keys %{$_[1]}) {
188 print ARFILE $k,"=",$_[1]->{$k},"\n" if (!exists($old{$k}));
193 sub read_file_contents
195 open(FILE, $_[0]) || return undef;
202 sub write_file_contents
204 open(FILE, ">$_[0]") || return undef;