added support to output as PHP syntax
[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'],'php')) {
22 $runMode = 'php';
23 } else if (!strcmp($options['mode'],'raw')) {
24 $runMode = 'raw';
25 } else {
26 }
27 }
28 $runTest = true;
29 } else {
30 echo <<<END
31 Run this script to print out the duplicates against a message array.
32 Parameters:
33 * lang: Language code to be checked.
34 * clang: Language code to be compared.
35 Options:
36 * mode: Output format, can be either:
37 * text: Text output on the console (default)
38 * wiki: Wiki format, with * at beginning of each line
39 * php: Output text as PHP syntax in a array $dupeMessages
40 * raw: Raw output for duplicates
41 END;
42 }
43
44 // Check file exists
45 if ( $runTest ) {
46 $langCode = $options['lang'];
47 $langCodeC = $options['clang'];
48 $langCodeF = ucfirst(strtolower(preg_replace('/-/','_',$langCode)));
49 $langCodeFC = ucfirst(strtolower(preg_replace('/-/','_',$langCodeC)));
50 $messagesFile = $messagesDir.'Messages'.$langCodeF.'.php';
51 $messagesFileC = $messagesDir.'Messages'.$langCodeFC.'.php';
52 if (file_exists($messagesFile) && file_exists($messagesFileC)) {
53 $run = true;
54 }
55 else {
56 echo "Messages file(s) could not be found.\nMake sure both files are exists.\n";
57 }
58 }
59
60 // Run to check the dupes
61 if ( $run ) {
62 if (!strcmp($runMode,'wiki')) {
63 $runMode = 'wiki';
64 } else if (!strcmp($runMode,'raw')) {
65 $runMode = 'raw';
66 }
67 include( $messagesFile );
68 $wgMessages[$langCode] = $messages;
69 include( $messagesFileC );
70 $wgMessages[$langCodeC] = $messages;
71 $count = 0;
72
73 if (!strcmp($runMode,'php')) {
74 print("<?php\n");
75 print('$dupeMessages = array('."\n");
76 }
77 foreach ($wgMessages[$langCodeC] as $key => $value) {
78 foreach ($wgMessages[$langCode] as $ckey => $cvalue) {
79 if (!strcmp($key,$ckey)) {
80 if ((!strcmp($key,$ckey)) && (!strcmp($value,$cvalue))) {
81 if (!strcmp($runMode,'raw')) {
82 print("$key\n");
83 } else if (!strcmp($runMode,'php')) {
84 print("'$key' => '',\n");
85 } else if (!strcmp($runMode,'wiki')) {
86 $uKey = ucfirst($key);
87 print("* MediaWiki:$uKey/$langCode\n");
88 } else {
89 print("* $key\n");
90 }
91 $count++;
92 }
93 }
94 }
95 }
96 if (!strcmp($runMode,'php')) {
97 print(");\n");
98 }
99 if (!strcmp($runMode,'text')) {
100 if ($count == 1) {
101 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n";
102 } else {
103 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n";
104 }
105 }
106 }