Complain if use asks for page that's not archived
[lhc/web/wiklou.git] / maintenance / checktrans2.php
1 <?
2
3 # Checks translation of all language files
4
5 function wfLocalUrl() { return "";}
6 function wfLocalUrle() { return "";}
7
8 function check($arrayname, $lang, $text)
9 {
10 $arraynameprinted = 0;
11
12 global $count, $total;
13
14 $msgarray = $arrayname . ucfirst( $lang );
15 $msgarrayen = $arrayname . "En";
16
17 eval( $text );
18 if ( !is_array( $$msgarrayen ) ) {
19 print "\nArray '$msgarrayen' not present\n";
20 return;
21 } elseif ( !is_array( $$msgarray ) ) {
22 print "\nArray '$msgarray' not present\n";
23 return;
24 }
25
26 foreach ( $$msgarrayen as $code => $msg ) {
27 ++$total;
28
29 if ( ! array_key_exists( $code, $$msgarray ) ) {
30 if (!$arraynameprinted) {
31 print("\nIn array '$msgarray':\n");
32 $arraynameprinted = 1;
33 }
34
35 if ( is_numeric( $code ) ) {
36 print "$code ($msg)\n";
37 } else {
38 print "{$code}\n";
39 }
40 ++$count;
41 }
42 }
43 }
44
45 function getLanguage( $lang )
46 {
47 $fileName = "../languages/Language" . ucfirst( $lang ) . ".php";
48 $file = fopen( $fileName, "r" );
49 $text = fread( $file, filesize( $fileName ) );
50 $clipPos = strpos( $text, "class Language" );
51 $text = substr( $text, 0, $clipPos );
52 $text = preg_replace( "/^<\?(php|)/", "", $text );
53 $text = preg_replace( "/^include.*$/m", "", $text );
54
55 return $text;
56 }
57
58 function checkLanguage( $lang, $enText )
59 {
60 $text = $enText . getLanguage( $lang );
61 check("wgLanguageNames", $lang, $text);
62 check("wgNamespaceNames", $lang, $text);
63 check("wgDefaultUserOptions", $lang, $text);
64 check("wgQuickbarSettings", $lang, $text);
65 check("wgSkinNames", $lang, $text);
66 check("wgMathNames", $lang, $text);
67 check("wgUserToggles", $lang, $text);
68 check("wgWeekdayNames", $lang, $text);
69 check("wgMonthNames", $lang, $text);
70 check("wgMonthAbbreviations", $lang, $text);
71 check("wgValidSpecialPages", $lang, $text);
72 check("wgSysopSpecialPages", $lang, $text);
73 check("wgDeveloperSpecialPages", $lang, $text);
74 check("wgAllMessages", $lang, $text);
75 check("wgMagicWords", $lang, $text);
76 }
77
78 if ( $argc > 1 ) {
79 array_shift( $argv );
80 $glob = implode( " ", $argv );
81 } else {
82 $glob = "../languages/Language?*.php";
83 }
84
85 umask( 000 );
86 set_time_limit( 0 );
87 $count = $total = 0;
88 $enText = getLanguage( "" );
89 $filenames = glob( $glob );
90 $width = 80;
91 foreach ( $filenames as $filename ) {
92 if ( preg_match( "/languages\/Language(.*)\.php/", $filename, $m ) ) {
93 $lang = strtolower( $m[1] );
94 if ( $lang != "utf8" ) {
95 print "\n" . str_repeat( "-", $width );
96 print "\n$lang\n";
97 print str_repeat( "-", $width ) . "\n";
98 checkLanguage( $lang, $enText );
99 }
100 }
101 }
102
103 print "\n" . str_repeat( "-", $width ) . "\n";
104 print "{$count} messages of {$total} not translated.\n";
105