695927fb12cc0819d5fcbd0e2314ca519d9261a3
[lhc/web/wiklou.git] / maintenance / language / checkExtensioni18n.php
1 <?php
2 /**
3 * Copyright (C) 2007 Ashar Voultoiz <hashar@altern.org>
4 *
5 * Based on dumpBackup:
6 * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
7 *
8 * http://www.mediawiki.org
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
24 *
25 * @package MediaWiki
26 * @subpackage SpecialPage
27 */
28
29 #
30 # Lacking documentation. An example is:
31 # php checkExtensioni18n.php /opt/mw/extensions/CentralAuth/CentralAuth.i18n.php wgCentralAuthMessages
32 #
33
34 require_once( dirname(__FILE__).'/../commandLine.inc' );
35 require_once( 'languages.inc' );
36 require_once( 'checkLanguage.inc' );
37
38 class extensionLanguages extends languages {
39 private $mExt18nFilename, $mExtArrayName ;
40 private $mExtArray;
41
42 function __construct( $ext18nFilename, $extArrayName ) {
43 $exif = false;
44 $this->mExt18nFilename = $ext18nFilename;
45 $this->mExtArrayName = $extArrayName;
46
47 $this->mIgnoredMessages = array() ;
48 $this->mOptionalMessages = array() ;
49
50 if ( file_exists( $this->mExt18nFilename ) ) {
51 require_once( $this->mExt18nFilename );
52 $this->mExtArray = ${$this->mExtArrayName} ;
53 $this->mLanguages = array_keys( $this->mExtArray );
54 } else {
55 wfDie( "File $this->mExt18nFilename not found\n" );
56 }
57 }
58
59 protected function loadRawMessages( $code ) {
60 if ( isset( $this->mRawMessages[$code] ) ) {
61 return;
62 }
63 if( isset( $this->mExtArray[$code] ) ) {
64 $this->mRawMessages[$code] = $this->mExtArray[$code] ;
65 } else {
66 $this->mRawMessages[$code] = array();
67 }
68 }
69
70 public function getLanguages() {
71 return $this->mLanguages;
72 }
73 }
74
75
76 function usage() {
77 // Usage
78 print <<<END
79 Usage: php checkExtensioni18n.php <filename> <arrayname>
80
81
82 END;
83 die;
84 }
85
86 // Check arguments
87 if ( isset( $argv[0] ) ) {
88
89 if (file_exists( $argv[0] ) ) {
90 $filename = $argv[0];
91 } else {
92 print "Unable to open file '{$argv[0]}'\n";
93 usage();
94 }
95
96 if ( isset( $argv[1] ) ) {
97 $arrayname = $argv[1];
98 } else {
99 print "You must give an array name to be checked\n";
100 usage();
101 }
102 } else {
103 usage();
104 }
105
106 $extLanguages = new extensionLanguages($filename, $arrayname);
107
108 // Stuff needed by the checkLanguage routine (globals)
109 $wgGeneralMessages = $extLanguages->getGeneralMessages();
110 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
111 $wgDisplayLevel = 2;
112 $wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
113
114 foreach( $extLanguages->getLanguages() as $lang ) {
115 if( $lang == 'en' ) {
116 print "Skipped english language\n";
117 continue;
118 }
119 checkLanguage( $extLanguages, $lang );
120 /*
121 print "== $lang ==\n";
122 print count($ext->getUntranslatedMessages( $lang ) ) . "\n";
123 print count($ext->getEmptyMessages( $lang ) ) . "\n";
124 */
125 }
126
127 ?>