some more tweaks
[lhc/web/wiklou.git] / maintenance / language / checkDupeMessages.php
1 <?php
2 /**
3 * @todo document
4 * @file
5 * @ingroup MaintenanceLanguage
6 */
7
8 require_once( dirname(__FILE__).'/../commandLine.inc' );
9 $messagesDir = dirname(__FILE__).'/../../languages/messages/';
10 $runTest = false;
11 $run = false;
12 $runMode = 'text';
13
14 // Check parameters
15 if ( isset( $options['lang'] ) && isset( $options['clang'] )) {
16 if (!isset( $options['mode'] )) {
17 $runMode = 'text';
18 } else {
19 if (!strcmp($options['mode'],'wiki')) {
20 $runMode = 'wiki';
21 } else if (!strcmp($options['mode'],'raw')) {
22 $runMode = 'raw';
23 } else {
24 }
25 }
26 $runTest = true;
27 } else {
28 echo <<<END
29 Run this script to print out the duplicates against a message array.
30 Parameters:
31 * lang: Language code to be checked.
32 * clang: Language code to be compared.
33 Options:
34 * mode: Output format, can be either:
35 * text: Text output on the console (default)
36 * wiki: Wiki format, with * at beginning of each line
37 * raw: Raw output for duplicates
38 END;
39 }
40
41 // Check file exists
42 if ( $runTest ) {
43 $langCode = $options['lang'];
44 $langCodeC = $options['clang'];
45 $langCodeF = ucfirst(strtolower(preg_replace('/-/','_',$langCode)));
46 $langCodeFC = ucfirst(strtolower(preg_replace('/-/','_',$langCodeC)));
47 $messagesFile = $messagesDir.'Messages'.$langCodeF.'.php';
48 $messagesFileC = $messagesDir.'Messages'.$langCodeFC.'.php';
49 if (file_exists($messagesFile) && file_exists($messagesFileC)) {
50 $run = true;
51 }
52 else {
53 echo "Messages file(s) could not be found.\nMake sure both files are exists.\n";
54 }
55 }
56
57 // Run to check the dupes
58 if ( $run ) {
59 if (!strcmp($runMode,'wiki')) {
60 $runMode = 'wiki';
61 } else if (!strcmp($runMode,'raw')) {
62 $runMode = 'raw';
63 }
64 include( $messagesFile );
65 $wgMessages[$langCode] = $messages;
66 include( $messagesFileC );
67 $wgMessages[$langCodeC] = $messages;
68 $count = 0;
69
70 foreach ($wgMessages[$langCodeC] as $key => $value) {
71 foreach ($wgMessages[$langCode] as $ckey => $cvalue) {
72 if (!strcmp($key,$ckey)) {
73 if ((!strcmp($key,$ckey)) && (!strcmp($value,$cvalue))) {
74 if (!strcmp($runMode,'raw')) {
75 print("$key\n");
76 } else if (!strcmp($runMode,'wiki')) {
77 $uKey = ucfirst($key);
78 print("* MediaWiki:$uKey/$langCode\n");
79 } else {
80 print("* $key\n");
81 }
82 $count++;
83 }
84 }
85 }
86 }
87 if (!strcmp($runMode,'text')) {
88 if ($count == 1) {
89 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n";
90 } else {
91 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n";
92 }
93 }
94 }