moving geo files to new experiments subdir
[lhc/web/wiklou.git] / maintenance / DiffLanguage.php
1 <?php
2 # MediaWiki web-based config/installation
3 # Copyright (C) 2004 Ashar Voultoiz <thoane@altern.org> and others
4 # http://www.mediawiki.org/
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # http://www.gnu.org/copyleft/gpl.html
20
21 /**
22 * Usage: php DiffLanguage.php [lang [file]]
23 *
24 * lang: Enter the language code following "Language" of the LanguageXX.php you
25 * want to check. If using linux you might need to follow case aka Zh and not
26 * zh.
27 *
28 * file: A php language file you want to include to compare mediawiki
29 * Language{Lang}.php against (for example Special:Allmessages PHP output).
30 *
31 * The goal is to get a list of messages not yet localised in a languageXX.php
32 * file using the language.php file as reference.
33 *
34 * The script then print a list of wgAllMessagesXX keys that aren't localised, a
35 * percentage of messages correctly localised and the number of messages to be
36 * translated.
37 *
38 * @package MediaWiki
39 * @subpackage Maintenance
40 */
41
42 /** This script run from the commandline */
43 require_once( 'commandLine.inc' );
44
45 $wgLanguageCode = ucfirstlcrest($wgLanguageCode);
46
47 # FUNCTIONS
48 /** Return a given string with first letter upper case, the rest lowercase */
49 function ucfirstlcrest($string) {
50 return strtoupper(substr($string,0,1)).strtolower(substr($string,1));
51 }
52
53 /** Ask user a language code */
54 function askLanguageCode() {
55 global $wgLanguageCode;
56
57 print "Enter the language you want to check [$wgLanguageCode]:";
58 $input = ucfirstlcrest( readconsole() );
59 if($input == '') $input = $wgLanguageCode;
60 return $input;
61 }
62
63
64 # MAIN ENTRY
65 if ( isset($args[0]) ) {
66 $lang = ucfirstlcrest($args[0],1);
67 // eventually against another language file
68 if( isset($args[1])) include($args[1]) or die("File {$args[1]} not found.\n");
69 } else {
70 // no lang given, prompt
71 $lang = askLanguageCode();
72 }
73
74 if($lang != $wgLanguageCode) {
75 $langFile = "$IP/languages/Language$lang.php";
76 if (file_exists( $langFile ) ) {
77 print "Including $langFile\n";
78 include($langFile);
79 } else die("ERROR: The file $langFile does not exist !\n");
80 }
81
82 /* ugly hack to load the correct array, if you have a better way
83 to achieve the same goal, recode it ! */
84 $foo = "wgAllMessages$lang";
85 $testme = &$$foo;
86 /* end of ugly hack */
87
88 # Get all references messages and check if they exist in the tested language
89 $i = 0;
90 print "\nChecking $lang localisation file against reference (en):\n----\n";
91 foreach($wgAllMessagesEn as $index => $localized)
92 {
93 if(!(isset($testme[$index]))) {
94 $i++;
95 print "$lang: $index\n";
96 }
97 }
98
99 echo "----\n";
100 echo "$lang language is complete at ".number_format((100 - $i/count($wgAllMessagesEn) * 100),2)."%\n";
101 echo "$i unlocalised messages of the ".count($wgAllMessagesEn)." messages available.\n";
102 print_r($time);