* comment at top
[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 # This script is an alpha version.
23 #
24 # The goal is to get a list of messages not yet localised in a
25 # languageXX.php file using the language.php file as reference.
26 #
27 # Usage:
28 # php DiffLanguage.php
29 #
30 # Enter the language code following "Language" of the LanguageXX.php
31 # you want to check. If using linux you might need to follow case aka
32 # Zh and not zh.
33 #
34 # The script then print a list of wgAllMessagesXX keys that aren't
35 # localised, a percentage of messages correctly localised and the
36 # number of messages to be translated.
37
38 require_once( "commandLine.inc" );
39
40 $wgLanguageCode = strtoupper(substr($wgLanguageCode,0,1)).strtolower(substr($wgLanguageCode,1));
41
42 # read command line argument
43 if ( isset($argv[1]) ) {
44 $lang = $argv[1];
45
46 # or prompt a simple menu
47 } else {
48 $loop = true;
49 do {
50 @ob_end_flush();
51 print "Enter the language you want to check [$wgLanguageCode]:";
52 $input = readconsole();
53
54 # set the input to current language
55 if($input == "") {
56 $input = $wgLanguageCode;
57 }
58
59 # convert to 1st char upper, rest lower case
60 $input = strtoupper(substr($input,0,1)).strtolower(substr($input,1));
61
62 # try to get the file
63 if( file_exists("../languages/Language$input.php") ) {
64 $loop = false;
65 $lang = $input;
66 } else {
67 print "ERROR: The file Language$input.php doesn't exist !\n";
68 }
69
70 } while ($loop);
71
72 }
73
74 /* TODO
75 Need to check case of the $lang : 1st char upper 2nd char lower
76 */
77
78
79 # include the language if it's not the already loaded one
80 if($lang != $wgLanguageCode) {
81 print "Including language file for $lang.\n";
82 include("Language{$lang}.php");
83 }
84
85 /* ugly hack to load the correct array, if you have a better way
86 to achieve the same goal, recode it ! */
87 $foo = "wgAllMessages$lang";
88 $testme = &$$foo;
89 /* end of ugly hack */
90
91
92 # Get all references messages and check if they exist in the tested language
93 $i = 0;
94 print "\nChecking $lang localisation file against reference (en):\n----\n";
95 foreach($wgAllMessagesEn as $index => $localized)
96 {
97 if(!(isset($testme[$index]))) {
98 $i++;
99
100 echo "$index\n";
101 }
102 }
103 echo "----\n";
104 echo "$lang language is complete at ".number_format((100 - $i/count($wgAllMessagesEn) * 100),2)."%\n";
105 echo "$i unlocalised message of the ".count($wgAllMessagesEn)." messages available.\n";