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