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