summaryrefslogtreecommitdiff
path: root/locale/de/locales.pl
blob: cc8d2be7669a68a3eb99d88ac65f449432be0325 (plain)
  1. #!/usr/bin/perl
  2. # -n do not include custom_ scripts
  3. # -a build all file
  4. # -m do not generate missing files
  5. use FileHandle;
  6. $basedir = "../..";
  7. $bindir = "$basedir/bin/mozilla";
  8. $menufile = "menu.ini";
  9. foreach $item (@ARGV) {
  10. $item =~ s/-//g;
  11. $arg{$item} = 1;
  12. }
  13. open(FH, "LANGUAGE");
  14. $language = <FH>;
  15. close(FH);
  16. chomp $language;
  17. $language =~ s/\((.*)\)/$1/;
  18. $charset = $1;
  19. opendir DIR, "$bindir" or die "$!";
  20. @progfiles = grep { /\.pl/; !/(_|^\.)/ } readdir DIR;
  21. seekdir DIR, 0;
  22. @customfiles = grep /_/, readdir DIR;
  23. closedir DIR;
  24. # put customized files into @customfiles
  25. @customfiles = () if ($arg{n});
  26. if ($arg{n}) {
  27. @menufiles = ($menufile);
  28. } else {
  29. opendir DIR, "$basedir" or die "$!";
  30. @menufiles = grep { /.*?_$menufile$/ } readdir DIR;
  31. closedir DIR;
  32. unshift @menufiles, $menufile;
  33. }
  34. if (-f "all") {
  35. eval { require "all"; };
  36. %all = %{$self{texts}};
  37. %{$self{texts}} = ();
  38. } else {
  39. # build %all file from individual files
  40. foreach $file (@progfiles) {
  41. &scanfile("$bindir/$file");
  42. }
  43. }
  44. # remove the old missing file
  45. if (-f 'missing') {
  46. unlink "missing";
  47. }
  48. foreach $file (@progfiles) {
  49. %locale = ();
  50. %submit = ();
  51. %subrt = ();
  52. @missing = ();
  53. %missing = ();
  54. &scanfile("$bindir/$file");
  55. # scan custom_{module}.pl or {login}_{module}.pl files
  56. foreach $customfile (@customfiles) {
  57. if ($customfile =~ /_$file/) {
  58. if (-f "$bindir/$customfile") {
  59. &scanfile("$bindir/$customfile");
  60. }
  61. }
  62. }
  63. # if this is the menu.pl file
  64. if ($file eq 'menu.pl') {
  65. foreach $item (@menufiles) {
  66. &scanmenu("$basedir/$item");
  67. }
  68. }
  69. $file =~ s/\.pl//;
  70. if (-f "$file.missing") {
  71. eval { require "$file.missing"; };
  72. unlink "$file.missing";
  73. for (keys %$missing) {
  74. $self{texts}{$_} ||= $missing->{$_};
  75. }
  76. }
  77. open FH, ">$file" or die "$! : $file";
  78. if ($charset) {
  79. print FH qq|\$self{charset} = '$charset';\n\n|;
  80. }
  81. print FH q|$self{texts} = {
  82. |;
  83. foreach $key (sort keys %locale) {
  84. $text = ($self{texts}{$key}) ? $self{texts}{$key} : $all{$key};
  85. $count++;
  86. $text =~ s/'/\\'/g;
  87. $text =~ s/\\$/\\\\/;
  88. $keytext = $key;
  89. $keytext =~ s/'/\\'/g;
  90. $keytext =~ s/\\$/\\\\/;
  91. if (!$text) {
  92. $notext++;
  93. push @missing, $keytext;
  94. next;
  95. }
  96. print FH qq| '$keytext'|.(' ' x (27-length($keytext))).qq| => '$text',\n|;
  97. }
  98. print FH q|};
  99. $self{subs} = {
  100. |;
  101. foreach $key (sort keys %subrt) {
  102. $text = $key;
  103. $text =~ s/'/\\'/g;
  104. $text =~ s/\\$/\\\\/;
  105. print FH qq| '$text'|.(' ' x (27-length($text))).qq| => '$text',\n|;
  106. }
  107. foreach $key (sort keys %submit) {
  108. $text = ($self{texts}{$key}) ? $self{texts}{$key} : $all{$key};
  109. next unless $text;
  110. $text =~ s/'/\\'/g;
  111. $text =~ s/\\$/\\\\/;
  112. $english_sub = $key;
  113. $english_sub =~ s/'/\\'/g;
  114. $english_sub =~ s/\\$/\\\\/;
  115. $english_sub = lc $key;
  116. $translated_sub = lc $text;
  117. $english_sub =~ s/( |-|,|\/|\.$)/_/g;
  118. $translated_sub =~ s/( |-|,|\/|\.$)/_/g;
  119. print FH qq| '$translated_sub'|.(' ' x (27-length($translated_sub))).qq| => '$english_sub',\n|;
  120. }
  121. print FH q|};
  122. 1;
  123. |;
  124. close FH;
  125. if (!$arg{m}) {
  126. if (@missing) {
  127. open FH, ">$file.missing" or die "$! : missing";
  128. print FH qq|# module $file
  129. # add the missing texts and run locales.pl to rebuild
  130. \$missing = {
  131. |;
  132. foreach $text (@missing) {
  133. $text =~ s/'/\\'/g;
  134. $text =~ s/\\$/\\\\/;
  135. print FH qq| '$text'|.(' ' x (27-length($text))).qq| => '',\n|;
  136. }
  137. print FH q|};
  138. 1;
  139. |;
  140. close FH;
  141. }
  142. }
  143. # redo the all file
  144. if ($arg{a}) {
  145. open FH, ">all" or die "$! : all";
  146. print FH q|# These are all the texts to build the translations files.
  147. # to build unique strings edit the module files instead
  148. # this file is just a shortcut to build strings which are the same
  149. |;
  150. if ($charset) {
  151. print FH qq|\$self{charset} = '$charset';\n\n|;
  152. }
  153. print FH q|
  154. $self{texts} = {
  155. |;
  156. foreach $key (sort keys %all) {
  157. $keytext = $key;
  158. $keytext =~ s/'/\\'/g;
  159. $keytext =~ s/\\$/\\\\/;
  160. $text = $all{$key};
  161. $text =~ s/'/\\'/g;
  162. $text =~ s/\\$/\\\\/;
  163. print FH qq| '$keytext'|.(' ' x (27-length($keytext))).qq| => '$text',\n|;
  164. }
  165. print FH q|};
  166. 1;
  167. |;
  168. close FH;
  169. }
  170. }
  171. $per = sprintf("%.1f", ($count - $notext) / $count * 100);
  172. print "\n$language - ${per}%\n";
  173. exit;
  174. # eof
  175. sub scanfile {
  176. my ($file, $level) = @_;
  177. my $fh = new FileHandle;
  178. open $fh, "$file" or die "$! : $file";
  179. $file =~ s/\.pl//;
  180. $file =~ s/$bindir\///;
  181. %temp = ();
  182. for (keys %{$self{texts}}) {
  183. $temp{$_} = $self{texts}{$_};
  184. }
  185. # read translation file if it exists
  186. if (-f $file) {
  187. eval { do "$file"; };
  188. for (keys %{$self{texts}}) {
  189. $all{$_} ||= $self{texts}{$_};
  190. if ($level) {
  191. $temp{$_} ||= $self{texts}{$_};
  192. } else {
  193. $temp{$_} = $self{texts}{$_};
  194. }
  195. }
  196. }
  197. %{$self{texts}} = ();
  198. for (sort keys %temp) {
  199. $self{texts}{$_} = $temp{$_};
  200. }
  201. while (<$fh>) {
  202. # is this another file
  203. if (/require\s+\W.*\.pl/) {
  204. my $newfile = $&;
  205. $newfile =~ s/require\s+\W//;
  206. $newfile =~ s/\$form->{path}\///;
  207. &scanfile("$bindir/$newfile", 1) if $newfile !~ /_/;
  208. }
  209. # is this a sub ?
  210. if (/^sub /) {
  211. ($null, $subrt) = split / +/;
  212. $subrt{$subrt} = 1;
  213. next;
  214. }
  215. my $rc = 1;
  216. while ($rc) {
  217. if (/Locale/) {
  218. if (!/^use /) {
  219. my ($null, $country) = split /,/;
  220. $country =~ s/^ +["']//;
  221. $country =~ s/["'].*//;
  222. }
  223. }
  224. if (/\$locale->text.*?\W\)/) {
  225. my $string = $&;
  226. $string =~ s/\$locale->text\(\s*['"(q|qq)]['\/\\\|~]*//;
  227. $string =~ s/\W\)+.*$//;
  228. # if there is no $ in the string record it
  229. unless ($string =~ /\$\D.*/) {
  230. # this guarantees one instance of string
  231. $locale{$string} = 1;
  232. # is it a submit button before $locale->
  233. if (/type=submit/i) {
  234. $submit{$string} = 1;
  235. }
  236. }
  237. }
  238. # exit loop if there are no more locales on this line
  239. ($rc) = ($' =~ /\$locale->text/);
  240. # strip text
  241. s/^.*?\$locale->text.*?\)//;
  242. }
  243. }
  244. close($fh);
  245. }
  246. sub scanmenu {
  247. my $file = shift;
  248. my $fh = new FileHandle;
  249. open $fh, "$file" or die "$! : $file";
  250. my @a = grep /^\[/, <$fh>;
  251. close($fh);
  252. # strip []
  253. grep { s/(\[|\])//g } @a;
  254. foreach my $item (@a) {
  255. $item =~ s/ *$//;
  256. @b = split /--/, $item;
  257. foreach $string (@b) {
  258. chomp $string;
  259. if ($string !~ /^\s*$/) {
  260. $locale{$string} = 1;
  261. }
  262. }
  263. }
  264. }