ea5b1870b9cacbe8eb2ce673c444efa185157ab5
[lhc/web/wiklou.git] / maintenance / language / checkDupeMessages.php
1 <?php
2 /**
3 * Script to print out duplicates in message array
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup MaintenanceLanguage
22 */
23
24 require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
25 $messagesDir = dirname( __FILE__ ) . '/../../languages/messages/';
26 $runTest = false;
27 $run = false;
28 $runMode = 'text';
29
30 // Check parameters
31 if ( isset( $options['lang'] ) && isset( $options['clang'] ) ) {
32 if ( !isset( $options['mode'] ) ) {
33 $runMode = 'text';
34 } else {
35 if ( !strcmp( $options['mode'], 'wiki' ) ) {
36 $runMode = 'wiki';
37 } elseif ( !strcmp( $options['mode'], 'php' ) ) {
38 $runMode = 'php';
39 } elseif ( !strcmp( $options['mode'], 'raw' ) ) {
40 $runMode = 'raw';
41 } else {
42 }
43 }
44 $runTest = true;
45 } else {
46 echo <<<TEXT
47 Run this script to print out the duplicates against a message array.
48 Parameters:
49 * lang: Language code to be checked.
50 * clang: Language code to be compared.
51 Options:
52 * mode: Output format, can be either:
53 * text: Text output on the console (default)
54 * wiki: Wiki format, with * at beginning of each line
55 * php: Output text as PHP syntax in a array $dupeMessages
56 * raw: Raw output for duplicates
57 TEXT;
58 }
59
60 // Check file exists
61 if ( $runTest ) {
62 $langCode = $options['lang'];
63 $langCodeC = $options['clang'];
64 $langCodeF = ucfirst( strtolower( preg_replace( '/-/', '_', $langCode ) ) );
65 $langCodeFC = ucfirst( strtolower( preg_replace( '/-/', '_', $langCodeC ) ) );
66 $messagesFile = $messagesDir . 'Messages' . $langCodeF . '.php';
67 $messagesFileC = $messagesDir . 'Messages' . $langCodeFC . '.php';
68 if ( file_exists( $messagesFile ) && file_exists( $messagesFileC ) ) {
69 $run = true;
70 }
71 else {
72 echo "Messages file(s) could not be found.\nMake sure both files are exists.\n";
73 }
74 }
75
76 // Run to check the dupes
77 if ( $run ) {
78 if ( !strcmp( $runMode, 'wiki' ) ) {
79 $runMode = 'wiki';
80 } elseif ( !strcmp( $runMode, 'raw' ) ) {
81 $runMode = 'raw';
82 }
83 include( $messagesFile );
84 $messageExist = isset( $messages );
85 if ( $messageExist )
86 $wgMessages[$langCode] = $messages;
87 include( $messagesFileC );
88 $messageCExist = isset( $messages );
89 if ( $messageCExist )
90 $wgMessages[$langCodeC] = $messages;
91 $count = 0;
92
93 if ( ( $messageExist ) && ( $messageCExist ) ) {
94
95 if ( !strcmp( $runMode, 'php' ) ) {
96 print( "<?php\n" );
97 print( '$dupeMessages = array(' . "\n" );
98 }
99 foreach ( $wgMessages[$langCodeC] as $key => $value ) {
100 foreach ( $wgMessages[$langCode] as $ckey => $cvalue ) {
101 if ( !strcmp( $key, $ckey ) ) {
102 if ( ( !strcmp( $key, $ckey ) ) && ( !strcmp( $value, $cvalue ) ) ) {
103 if ( !strcmp( $runMode, 'raw' ) ) {
104 print( "$key\n" );
105 } elseif ( !strcmp( $runMode, 'php' ) ) {
106 print( "'$key' => '',\n" );
107 } elseif ( !strcmp( $runMode, 'wiki' ) ) {
108 $uKey = ucfirst( $key );
109 print( "* MediaWiki:$uKey/$langCode\n" );
110 } else {
111 print( "* $key\n" );
112 }
113 $count++;
114 }
115 }
116 }
117 }
118 if ( !strcmp( $runMode, 'php' ) ) {
119 print( ");\n" );
120 }
121 if ( !strcmp( $runMode, 'text' ) ) {
122 if ( $count == 1 ) {
123 echo "\nThere are $count duplicated message in $langCode, against to $langCodeC.\n";
124 } else {
125 echo "\nThere are $count duplicated messages in $langCode, against to $langCodeC.\n";
126 }
127 }
128 } else {
129 if ( !$messageExist )
130 echo "There are no messages defined in $langCode.\n";
131 if ( !$messageCExist )
132 echo "There are no messages defined in $langCodeC.\n";
133 }
134 }