Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[lhc/web/wiklou.git] / maintenance / language / checkLanguage.php
1 <?php
2 /**
3 * Check a language file.
4 *
5 * @addtogroup Maintenance
6 */
7
8 require_once( dirname(__FILE__).'/../commandLine.inc' );
9 require_once( 'languages.inc' );
10 require_once( 'checkLanguage.inc' );
11
12 # Show help
13 if ( isset( $options['help'] ) ) {
14 echo <<<END
15 Run this script to check a specific language file, or all of them.
16 Parameters:
17 * lang: Language code (default: the installation default language). You can also specify "all" to check all the languages.
18 * help: Show this help.
19 * level: Show the following level (default: 2).
20 * links: Link the message values (default off).
21 * wikilang: For the links, what is the content language of the wiki to display the output in (default en).
22 * whitelist: Make only the following checks (form: code,code).
23 * blacklist: Don't make the following checks (form: code,code).
24 * duplicate: Additionally check for messages which are translated the same to English (default off).
25 * noexif: Don't check for EXIF messages (a bit hard and boring to translate), if you know that they are currently not translated and want to focus on other problems (default off).
26 Check codes (ideally, all of them should result 0; all the checks are executed by default):
27 * untranslated: Messages which are required to translate, but are not translated.
28 * obsolete: Messages which are untranslatable, but translated.
29 * variables: Messages without variables which should be used.
30 * empty: Empty messages.
31 * whitespace: Messages which have trailing whitespace.
32 * xhtml: Messages which are not well-formed XHTML.
33 * chars: Messages with hidden characters.
34 Display levels (default: 2):
35 * 0: Skip the checks (useful for checking syntax).
36 * 1: Show only the stub headers and number of wrong messages, without list of messages.
37 * 2: Show only the headers and the message keys, without the message values.
38 * 3: Show both the headers and the complete messages, with both keys and values.
39
40 END;
41 exit();
42 }
43
44 # Get the language code
45 if ( isset( $options['lang'] ) ) {
46 $wgCode = $options['lang'];
47 } else {
48 $wgCode = $wgContLang->getCode();
49 }
50
51 # Get the display level
52 if ( isset( $options['level'] ) ) {
53 $wgDisplayLevel = $options['level'];
54 } else {
55 $wgDisplayLevel = 2;
56 }
57
58 # Get the links options
59 $wgLinks = isset( $options['links'] );
60 $wgWikiLanguage = isset( $options['wikilang'] ) ? $options['wikilang'] : 'en';
61
62 # Get the checks to do
63 $wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
64 if ( isset( $options['whitelist'] ) ) {
65 $wgChecks = explode( ',', $options['whitelist'] );
66 } elseif ( isset( $options['blacklist'] ) ) {
67 $wgChecks = array_diff( $wgChecks, explode( ',', $options['blacklist'] ) );
68 }
69
70 # Add duplicate option if specified
71 if ( isset( $options['duplicate'] ) ) {
72 $wgChecks[] = 'duplicate';
73 }
74
75 # Should check for EXIF?
76 $wgCheckEXIF = !isset( $options['noexif'] );
77
78 # Get language objects
79 $wgLanguages = new languages( $wgCheckEXIF );
80
81 # Get the general messages
82 $wgGeneralMessages = $wgLanguages->getGeneralMessages();
83 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
84
85 # Check the language
86 if ( $wgCode == 'all' ) {
87 foreach ( $wgLanguages->getLanguages() as $language ) {
88 if ( $language != 'en' && $language != 'enRTL' ) {
89 checkLanguage( $wgLanguages, $language );
90 }
91 }
92 } else {
93 # Can't check English
94 if ( $wgCode == 'en' ) {
95 echo "Current selected language is English, which cannot be checked.\n";
96 } else if ( $wgCode == 'enRTL' ) {
97 echo "Current selected language is RTL English, which cannot be checked.\n";
98 } else {
99 checkLanguage( $wgLanguages, $wgCode );
100 }
101 }
102
103 ?>