include_once -> require_once
[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 #
39 # Known bugs:
40 # - File paths are hardcoded
41 #
42
43
44 $wgCommandLineMode = true;
45 # Turn off output buffering if it's on
46 @ob_end_flush();
47
48 require_once("../LocalSettings.php");
49 require_once( "../includes/Setup.php" );
50 require_once( "../install-utils.inc" );
51
52 $wgLanguageCode = strtoupper(substr($wgLanguageCode,0,1)).strtolower(substr($wgLanguageCode,1));
53
54 # read command line argument
55 if ( isset($argv[1]) ) {
56 $lang = $argv[1];
57
58 # or prompt a simple menu
59 } else {
60 $loop = true;
61 do {
62 @ob_end_flush();
63 print "Enter the language you want to check [$wgLanguageCode]:";
64 $input = readconsole();
65
66 # set the input to current language
67 if($input == "") {
68 $input = $wgLanguageCode;
69 }
70
71 # convert to 1st char upper, rest lower case
72 $input = strtoupper(substr($input,0,1)).strtolower(substr($input,1));
73
74 # try to get the file
75 if( file_exists("../languages/Language$input.php") ) {
76 $loop = false;
77 $lang = $input;
78 } else {
79 print "ERROR: The file Language$input.php doesn't exist !\n";
80 }
81
82 } while ($loop);
83
84 }
85
86 /* TODO
87 Need to check case of the $lang : 1st char upper 2nd char lower
88 */
89
90
91 # include the language if it's not the already loaded one
92 if($lang != $wgLanguageCode) {
93 print "Including language file for $lang.\n";
94 include("Language{$lang}.php");
95 }
96
97 /* ugly hack to load the correct array, if you have a better way
98 to achieve the same goal, recode it ! */
99 $foo = "wgAllMessages$lang";
100 $testme = &$$foo;
101 /* end of ugly hack */
102
103
104 # Get all references messages and check if they exist in the tested language
105 $i = 0;
106 print "\nChecking $lang localisation file against reference (en):\n----\n";
107 foreach($wgAllMessagesEn as $index => $localized)
108 {
109 if(!(isset($testme[$index]))) {
110 $i++;
111
112 echo "$index\n";
113 }
114 }
115 echo "----\n";
116 echo "$lang language is complete at ".number_format((100 - $i/count($wgAllMessagesEn) * 100),2)."%\n";
117 echo "$i unlocalised message of the ".count($wgAllMessagesEn)." messages available.\n";