Restructured the languages directory, to avoid problems when people untar MW 1.8...
[lhc/web/wiklou.git] / maintenance / languages.inc
1 <?php
2 /**
3 * Handle messages in the language files.
4 *
5 * @package MediaWiki
6 * @subpackage Maintenance
7 */
8
9 class languages {
10 private $mLanguages; # List of languages
11 private $mRawMessages; # Raw list of the messages in each language
12 private $mMessages; # Messages in each language (except for English), divided to groups
13 private $mGeneralMessages; # General messages in English, divided to groups
14 private $mIgnoredMessages = array(
15 'sidebar',
16 'addsection',
17 'anonnotice',
18 'catseparator',
19 'googlesearch',
20 'exif-make-value',
21 'exif-model-value',
22 'exif-software-value',
23 'history_copyright',
24 'licenses',
25 'loginend',
26 'loginlanguagelinks',
27 'markaspatrolledlink',
28 'newarticletextanon',
29 'noarticletextanon',
30 'number_of_watching_users_RCview',
31 'pubmedurl',
32 'randompage-url',
33 'recentchanges-url',
34 'rfcurl',
35 'shareddescriptionfollows',
36 'signupend',
37 'sitenotice',
38 'sitesubtitle',
39 'sitetitle',
40 'talkpagetext',
41 'trackback',
42 'trackbackexcerpt',
43 'widthheight',
44 ); # All the messages which should be exist only in the English file
45 private $mOptionalMessages = array(
46 'imgmultigotopost',
47 'linkprefix',
48 'allpages-summary',
49 'booksources-summary',
50 'ipblocklist-summary',
51 'listusers-summary',
52 'longpages-summary',
53 'preferences-summary',
54 'specialpages-summary',
55 'whatlinkshere-summary',
56 ); # All the messages which may be translated or not, depending on the language
57 private $mEXIFMessages = array(
58 'exif-imagewidth',
59 'exif-imagelength',
60 'exif-bitspersample',
61 'exif-compression',
62 'exif-photometricinterpretation',
63 'exif-orientation',
64 'exif-samplesperpixel',
65 'exif-planarconfiguration',
66 'exif-ycbcrsubsampling',
67 'exif-ycbcrpositioning',
68 'exif-xresolution',
69 'exif-yresolution',
70 'exif-resolutionunit',
71 'exif-stripoffsets',
72 'exif-rowsperstrip',
73 'exif-stripbytecounts',
74 'exif-jpeginterchangeformat',
75 'exif-jpeginterchangeformatlength',
76 'exif-transferfunction',
77 'exif-whitepoint',
78 'exif-primarychromaticities',
79 'exif-ycbcrcoefficients',
80 'exif-referenceblackwhite',
81 'exif-datetime',
82 'exif-imagedescription',
83 'exif-make',
84 'exif-model',
85 'exif-software',
86 'exif-artist',
87 'exif-copyright',
88 'exif-exifversion',
89 'exif-flashpixversion',
90 'exif-colorspace',
91 'exif-componentsconfiguration',
92 'exif-compressedbitsperpixel',
93 'exif-pixelydimension',
94 'exif-pixelxdimension',
95 'exif-makernote',
96 'exif-usercomment',
97 'exif-relatedsoundfile',
98 'exif-datetimeoriginal',
99 'exif-datetimedigitized',
100 'exif-subsectime',
101 'exif-subsectimeoriginal',
102 'exif-subsectimedigitized',
103 'exif-exposuretime',
104 'exif-exposuretime-format',
105 'exif-fnumber',
106 'exif-fnumber-format',
107 'exif-exposureprogram',
108 'exif-spectralsensitivity',
109 'exif-isospeedratings',
110 'exif-oecf',
111 'exif-shutterspeedvalue',
112 'exif-aperturevalue',
113 'exif-brightnessvalue',
114 'exif-exposurebiasvalue',
115 'exif-maxaperturevalue',
116 'exif-subjectdistance',
117 'exif-meteringmode',
118 'exif-lightsource',
119 'exif-flash',
120 'exif-focallength',
121 'exif-focallength-format',
122 'exif-subjectarea',
123 'exif-flashenergy',
124 'exif-spatialfrequencyresponse',
125 'exif-focalplanexresolution',
126 'exif-focalplaneyresolution',
127 'exif-focalplaneresolutionunit',
128 'exif-subjectlocation',
129 'exif-exposureindex',
130 'exif-sensingmethod',
131 'exif-filesource',
132 'exif-scenetype',
133 'exif-cfapattern',
134 'exif-customrendered',
135 'exif-exposuremode',
136 'exif-whitebalance',
137 'exif-digitalzoomratio',
138 'exif-focallengthin35mmfilm',
139 'exif-scenecapturetype',
140 'exif-gaincontrol',
141 'exif-contrast',
142 'exif-saturation',
143 'exif-sharpness',
144 'exif-devicesettingdescription',
145 'exif-subjectdistancerange',
146 'exif-imageuniqueid',
147 'exif-gpsversionid',
148 'exif-gpslatituderef',
149 'exif-gpslatitude',
150 'exif-gpslongituderef',
151 'exif-gpslongitude',
152 'exif-gpsaltituderef',
153 'exif-gpsaltitude',
154 'exif-gpstimestamp',
155 'exif-gpssatellites',
156 'exif-gpsstatus',
157 'exif-gpsmeasuremode',
158 'exif-gpsdop',
159 'exif-gpsspeedref',
160 'exif-gpsspeed',
161 'exif-gpstrackref',
162 'exif-gpstrack',
163 'exif-gpsimgdirectionref',
164 'exif-gpsimgdirection',
165 'exif-gpsmapdatum',
166 'exif-gpsdestlatituderef',
167 'exif-gpsdestlatitude',
168 'exif-gpsdestlongituderef',
169 'exif-gpsdestlongitude',
170 'exif-gpsdestbearingref',
171 'exif-gpsdestbearing',
172 'exif-gpsdestdistanceref',
173 'exif-gpsdestdistance',
174 'exif-gpsprocessingmethod',
175 'exif-gpsareainformation',
176 'exif-gpsdatestamp',
177 'exif-gpsdifferential',
178 'exif-compression-1',
179 'exif-compression-6',
180 'exif-photometricinterpretation-2',
181 'exif-photometricinterpretation-6',
182 'exif-orientation-1',
183 'exif-orientation-2',
184 'exif-orientation-3',
185 'exif-orientation-4',
186 'exif-orientation-5',
187 'exif-orientation-6',
188 'exif-orientation-7',
189 'exif-orientation-8',
190 'exif-planarconfiguration-1',
191 'exif-planarconfiguration-2',
192 'exif-xyresolution-i',
193 'exif-xyresolution-c',
194 'exif-colorspace-1',
195 'exif-colorspace-ffff.h',
196 'exif-componentsconfiguration-0',
197 'exif-componentsconfiguration-1',
198 'exif-componentsconfiguration-2',
199 'exif-componentsconfiguration-3',
200 'exif-componentsconfiguration-4',
201 'exif-componentsconfiguration-5',
202 'exif-componentsconfiguration-6',
203 'exif-exposureprogram-0',
204 'exif-exposureprogram-1',
205 'exif-exposureprogram-2',
206 'exif-exposureprogram-3',
207 'exif-exposureprogram-4',
208 'exif-exposureprogram-5',
209 'exif-exposureprogram-6',
210 'exif-exposureprogram-7',
211 'exif-exposureprogram-8',
212 'exif-subjectdistance-value',
213 'exif-meteringmode-0',
214 'exif-meteringmode-1',
215 'exif-meteringmode-2',
216 'exif-meteringmode-3',
217 'exif-meteringmode-4',
218 'exif-meteringmode-5',
219 'exif-meteringmode-6',
220 'exif-meteringmode-255',
221 'exif-lightsource-0',
222 'exif-lightsource-1',
223 'exif-lightsource-2',
224 'exif-lightsource-3',
225 'exif-lightsource-4',
226 'exif-lightsource-9',
227 'exif-lightsource-10',
228 'exif-lightsource-11',
229 'exif-lightsource-12',
230 'exif-lightsource-13',
231 'exif-lightsource-14',
232 'exif-lightsource-15',
233 'exif-lightsource-17',
234 'exif-lightsource-18',
235 'exif-lightsource-19',
236 'exif-lightsource-20',
237 'exif-lightsource-21',
238 'exif-lightsource-22',
239 'exif-lightsource-23',
240 'exif-lightsource-24',
241 'exif-lightsource-255',
242 'exif-focalplaneresolutionunit-2',
243 'exif-sensingmethod-1',
244 'exif-sensingmethod-2',
245 'exif-sensingmethod-3',
246 'exif-sensingmethod-4',
247 'exif-sensingmethod-5',
248 'exif-sensingmethod-7',
249 'exif-sensingmethod-8',
250 'exif-filesource-3',
251 'exif-scenetype-1',
252 'exif-customrendered-0',
253 'exif-customrendered-1',
254 'exif-exposuremode-0',
255 'exif-exposuremode-1',
256 'exif-exposuremode-2',
257 'exif-whitebalance-0',
258 'exif-whitebalance-1',
259 'exif-scenecapturetype-0',
260 'exif-scenecapturetype-1',
261 'exif-scenecapturetype-2',
262 'exif-scenecapturetype-3',
263 'exif-gaincontrol-0',
264 'exif-gaincontrol-1',
265 'exif-gaincontrol-2',
266 'exif-gaincontrol-3',
267 'exif-gaincontrol-4',
268 'exif-contrast-0',
269 'exif-contrast-1',
270 'exif-contrast-2',
271 'exif-saturation-0',
272 'exif-saturation-1',
273 'exif-saturation-2',
274 'exif-sharpness-0',
275 'exif-sharpness-1',
276 'exif-sharpness-2',
277 'exif-subjectdistancerange-0',
278 'exif-subjectdistancerange-1',
279 'exif-subjectdistancerange-2',
280 'exif-subjectdistancerange-3',
281 'exif-gpslatitude-n',
282 'exif-gpslatitude-s',
283 'exif-gpslongitude-e',
284 'exif-gpslongitude-w',
285 'exif-gpsstatus-a',
286 'exif-gpsstatus-v',
287 'exif-gpsmeasuremode-2',
288 'exif-gpsmeasuremode-3',
289 'exif-gpsspeed-k',
290 'exif-gpsspeed-m',
291 'exif-gpsspeed-n',
292 'exif-gpsdirection-t',
293 'exif-gpsdirection-m',
294 ); # All the EXIF messages, may be set as optional if defined as such
295
296 /**
297 * Load the list of languages: all the Messages*.php
298 * files in the languages directory.
299 *
300 * @param $exif Treat the EXIF messages?
301 */
302 function __construct( $exif = true ) {
303 $this->mLanguages = array_keys( Language::getLanguageNames( true ) );
304 sort( $this->mLanguages );
305 if ( !$exif ) {
306 $this->mOptionalMessages = array_merge( $this->mOptionalMessages, $this->mEXIFMessages );
307 }
308 }
309
310 /**
311 * Get the language list.
312 *
313 * @return The language list.
314 */
315 public function getLanguages() {
316 return $this->mLanguages;
317 }
318
319 /**
320 * Load the raw messages for a specific langauge from the messages file.
321 *
322 * @param $code The langauge code.
323 */
324 private function loadRawMessages( $code ) {
325 if ( isset( $this->mRawMessages[$code] ) ) {
326 return;
327 }
328 $filename = Language::getMessagesFileName( $code );
329 if ( file_exists( $filename ) ) {
330 require( $filename );
331 if ( isset( $messages ) ) {
332 $this->mRawMessages[$code] = $messages;
333 } else {
334 $this->mRawMessages[$code] = array();
335 }
336 } else {
337 $this->mRawMessages[$code] = array();
338 }
339 }
340
341 /**
342 * Load the messages for a specific language (which is not English) and divide them to groups:
343 * all - all the messages.
344 * required - messages which should be translated in order to get a complete translation.
345 * optional - messages which can be translated, the fallback translation is used if not translated.
346 * obsolete - messages which should not be translated, either because they are not exist, or they are ignored messages.
347 * translated - messages which are either required or optional, but translated from English and needed.
348 *
349 * @param $code The language code.
350 */
351 private function loadMessages( $code ) {
352 if ( isset( $this->mMessages[$code] ) ) {
353 return;
354 }
355 $this->loadRawMessages( $code );
356 $this->loadGeneralMessages();
357 $this->mMessages[$code]['all'] = $this->mRawMessages[$code];
358 $this->mMessages[$code]['required'] = array();
359 $this->mMessages[$code]['optional'] = array();
360 $this->mMessages[$code]['obsolete'] = array();
361 $this->mMessages[$code]['translated'] = array();
362 foreach ( $this->mMessages[$code]['all'] as $key => $value ) {
363 if ( isset( $this->mGeneralMessages['required'][$key] ) ) {
364 $this->mMessages[$code]['required'][$key] = $value;
365 $this->mMessages[$code]['translated'][$key] = $value;
366 } else if ( isset( $this->mGeneralMessages['optional'][$key] ) ) {
367 $this->mMessages[$code]['optional'][$key] = $value;
368 $this->mMessages[$code]['translated'][$key] = $value;
369 } else {
370 $this->mMessages[$code]['obsolete'][$key] = $value;
371 }
372 }
373 }
374
375 /**
376 * Load the messages for English and divide them to groups:
377 * all - all the messages.
378 * required - messages which should be translated to other languages in order to get a complete translation.
379 * optional - messages which can be translated to other languages, but it's not required for a complete translation.
380 * ignored - messages which should not be translated to other languages.
381 * translatable - messages which are either required or optional, but can be translated from English.
382 */
383 private function loadGeneralMessages() {
384 if ( isset( $this->mGeneralMessages ) ) {
385 return;
386 }
387 $this->loadRawMessages( 'en' );
388 $this->mGeneralMessages['all'] = $this->mRawMessages['en'];
389 $this->mGeneralMessages['required'] = array();
390 $this->mGeneralMessages['optional'] = array();
391 $this->mGeneralMessages['ignored'] = array();
392 $this->mGeneralMessages['translatable'] = array();
393 foreach ( $this->mGeneralMessages['all'] as $key => $value ) {
394 if ( in_array( $key, $this->mIgnoredMessages ) ) {
395 $this->mGeneralMessages['ignored'][$key] = $value;
396 } else if ( in_array( $key, $this->mOptionalMessages ) ) {
397 $this->mGeneralMessages['optional'][$key] = $value;
398 $this->mGeneralMessages['translatable'][$key] = $value;
399 } else {
400 $this->mGeneralMessages['required'][$key] = $value;
401 $this->mGeneralMessages['translatable'][$key] = $value;
402 }
403 }
404 }
405
406 /**
407 * Get all the messages for a specific langauge (not English), without the
408 * fallback language messages, divided to groups:
409 * all - all the messages.
410 * required - messages which should be translated in order to get a complete translation.
411 * optional - messages which can be translated, the fallback translation is used if not translated.
412 * obsolete - messages which should not be translated, either because they are not exist, or they are ignored messages.
413 * translated - messages which are either required or optional, but translated from English and needed.
414 *
415 * @param $code The langauge code.
416 *
417 * @return The messages in this language.
418 */
419 public function getMessages( $code ) {
420 $this->loadMessages( $code );
421 return $this->mMessages[$code];
422 }
423
424 /**
425 * Get all the general English messages, divided to groups:
426 * all - all the messages.
427 * required - messages which should be translated to other languages in order to get a complete translation.
428 * optional - messages which can be translated to other languages, but it's not required for a complete translation.
429 * ignored - messages which should not be translated to other languages.
430 * translatable - messages which are either required or optional, but can be translated from English.
431 *
432 * @return The general English messages.
433 */
434 public function getGeneralMessages() {
435 $this->loadGeneralMessages();
436 return $this->mGeneralMessages;
437 }
438
439 /**
440 * Get the untranslated messages for a specific language.
441 *
442 * @param $code The langauge code.
443 *
444 * @return The untranslated messages for this language.
445 */
446 public function getUntranslatedMessages( $code ) {
447 $this->loadGeneralMessages();
448 $this->loadMessages( $code );
449 $requiredGeneralMessages = array_keys( $this->mGeneralMessages['required'] );
450 $requiredMessages = array_keys( $this->mMessages[$code]['required'] );
451 $untranslatedMessages = array();
452 foreach ( array_diff( $requiredGeneralMessages, $requiredMessages ) as $key ) {
453 $untranslatedMessages[$key] = $this->mGeneralMessages['required'][$key];
454 }
455 return $untranslatedMessages;
456 }
457
458 /**
459 * Get the duplicate messages for a specific language.
460 *
461 * @param $code The langauge code.
462 *
463 * @return The duplicate messages for this language.
464 */
465 public function getDuplicateMessages( $code ) {
466 $this->loadGeneralMessages();
467 $this->loadMessages( $code );
468 $duplicateMessages = array();
469 foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
470 if ( $this->mGeneralMessages['translatable'][$key] == $value ) {
471 $duplicateMessages[$key] = $value;
472 }
473 }
474 return $duplicateMessages;
475 }
476
477 /**
478 * Get the messages which do not use some variables.
479 *
480 * @param $code The langauge code.
481 *
482 * @return The messages which do not use some variables in this language.
483 */
484 public function getMessagesWithoutVariables( $code ) {
485 $this->loadGeneralMessages();
486 $this->loadMessages( $code );
487 $variables = array( '\$1', '\$2', '\$3', '\$4', '\$5', '\$6', '\$7', '\$8', '\$9' );
488 $messagesWithoutVariables = array();
489 foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
490 $missing = false;
491 foreach ( $variables as $var ) {
492 if ( preg_match( "/$var/sU", $this->mGeneralMessages['translatable'][$key] ) &&
493 !preg_match( "/$var/sU", $value ) ) {
494 $missing = true;
495 }
496 }
497 if ( $missing ) {
498 $messagesWithoutVariables[$key] = $value;
499 }
500 }
501 return $messagesWithoutVariables;
502 }
503
504 /**
505 * Get the empty messages.
506 *
507 * @param $code The langauge code.
508 *
509 * @return The empty messages for this language.
510 */
511 public function getEmptyMessages( $code ) {
512 $this->loadGeneralMessages();
513 $this->loadMessages( $code );
514 $emptyMessages = array();
515 foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
516 if ( $value === '' || $value === '-' ) {
517 $emptyMessages[$key] = $value;
518 }
519 }
520 return $emptyMessages;
521 }
522
523 /**
524 * Get the messages with trailing whitespace.
525 *
526 * @param $code The langauge code.
527 *
528 * @return The messages with trailing whitespace in this language.
529 */
530 public function getMessagesWithWhitespace( $code ) {
531 $this->loadGeneralMessages();
532 $this->loadMessages( $code );
533 $messagesWithWhitespace = array();
534 foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
535 if ( $this->mGeneralMessages['translatable'][$key] !== '' && $value !== rtrim( $value ) ) {
536 $messagesWithWhitespace[$key] = $value;
537 }
538 }
539 return $messagesWithWhitespace;
540 }
541
542 /**
543 * Get the non-XHTML messages.
544 *
545 * @param $code The langauge code.
546 *
547 * @return The non-XHTML messages for this language.
548 */
549 public function getNonXHTMLMessages( $code ) {
550 $this->loadGeneralMessages();
551 $this->loadMessages( $code );
552 $wrongPhrases = array(
553 '<hr *\\?>',
554 '<br *\\?>',
555 '<hr/>',
556 '<br/>',
557 );
558 $wrongPhrases = '~(' . implode( '|', $wrongPhrases ) . ')~sDu';
559 $nonXHTMLMessages = array();
560 foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
561 if ( preg_match( $wrongPhrases, $value ) ) {
562 $nonXHTMLMessages[$key] = $value;
563 }
564 }
565 return $nonXHTMLMessages;
566 }
567
568 /**
569 * Get the messages which include wrong characters.
570 *
571 * @param $code The langauge code.
572 *
573 * @return The messages which include wrong characters in this language.
574 */
575 public function getMessagesWithWrongChars( $code ) {
576 $this->loadGeneralMessages();
577 $this->loadMessages( $code );
578 $wrongChars = array(
579 '[LRM]' => "\xE2\x80\x8E",
580 '[RLM]' => "\xE2\x80\x8F",
581 '[LRE]' => "\xE2\x80\xAA",
582 '[RLE]' => "\xE2\x80\xAB",
583 '[POP]' => "\xE2\x80\xAC",
584 '[LRO]' => "\xE2\x80\xAD",
585 '[RLO]' => "\xE2\x80\xAB",
586 '[ZWSP]'=> "\xE2\x80\x8B",
587 '[NBSP]'=> "\xC2\xA0",
588 '[WJ]' => "\xE2\x81\xA0",
589 '[BOM]' => "\xEF\xBB\xBF",
590 '[FFFD]'=> "\xEF\xBF\xBD",
591 );
592 $wrongRegExp = '/(' . implode( '|', array_values( $wrongChars ) ) . ')/sDu';
593 $wrongCharsMessages = array();
594 foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
595 if ( preg_match( $wrongRegExp, $value ) ) {
596 foreach ( $wrongChars as $viewableChar => $hiddenChar ) {
597 $value = str_replace( $hiddenChar, $viewableChar, $value );
598 }
599 $wrongCharsMessages[$key] = $value;
600 }
601 }
602 return $wrongCharsMessages;
603 }
604
605 /**
606 * Output a messages list
607 *
608 * @param $messages The messages list
609 * @param $code The language code
610 * @param $text The text to show before the list (optional)
611 * @param $level The display level (optional)
612 * @param $links Show links (optional)
613 * @param $wikilang The langauge of the wiki to display the list in, for the links (optional)
614 */
615 public function outputMessagesList( $messages, $code, $text = '', $level = 2, $links = false, $wikilang = null ) {
616 if ( count( $messages ) == 0 ) {
617 return;
618 }
619 if ( $text ) {
620 echo "$text\n";
621 }
622 if ( $level == 1 ) {
623 echo "[messages are hidden]\n";
624 } else {
625 foreach ( $messages as $key => $value ) {
626 if ( $links ) {
627 $displayKey = ucfirst( $key );
628 if ( !isset( $wikilang ) ) {
629 global $wgContLang;
630 $wikilang = $wgContLang->getCode();
631 }
632 if ( $code == $wikilang ) {
633 $displayKey = "[[MediaWiki:$displayKey|$key]]";
634 } else {
635 $displayKey = "[[MediaWiki:$displayKey/$code|$key]]";
636 }
637 } else {
638 $displayKey = $key;
639 }
640 if ( $level == 2 ) {
641 echo "* $displayKey\n";
642 } else {
643 echo "* $displayKey: '$value'\n";
644 }
645 }
646 }
647 }
648 }
649
650 ?>