summaryrefslogtreecommitdiff
path: root/maintenance/language/languages.inc
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /maintenance/language/languages.inc
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'maintenance/language/languages.inc')
-rw-r--r--maintenance/language/languages.inc209
1 files changed, 133 insertions, 76 deletions
diff --git a/maintenance/language/languages.inc b/maintenance/language/languages.inc
index 6070f4ab..fb496cbc 100644
--- a/maintenance/language/languages.inc
+++ b/maintenance/language/languages.inc
@@ -24,35 +24,47 @@
/**
* @ingroup MaintenanceLanguage
*/
-class languages {
- protected $mLanguages; # List of languages
+class Languages {
+ /** @var array List of languages */
+ protected $mLanguages;
- protected $mRawMessages; # Raw list of the messages in each language
- protected $mMessages; # Messages in each language (except for English), divided to groups
- protected $mFallback; # Fallback language in each language
- protected $mGeneralMessages; # General messages in English, divided to groups
- protected $mIgnoredMessages; # All the messages which should be exist only in the English file
- protected $mOptionalMessages; # All the messages which may be translated or not, depending on the language
+ /** @var array Raw list of the messages in each language */
+ protected $mRawMessages;
- protected $mNamespaceNames; # Namespace names
- protected $mNamespaceAliases; # Namespace aliases
- protected $mMagicWords; # Magic words
- protected $mSpecialPageAliases; # Special page aliases
+ /** @var array Messages in each language (except for English), divided to groups */
+ protected $mMessages;
+
+ /** @var array Fallback language in each language */
+ protected $mFallback;
+
+ /** @var array General messages in English, divided to groups */
+ protected $mGeneralMessages;
+
+ /** @var array All the messages which should be exist only in the English file */
+ protected $mIgnoredMessages;
+
+ /** @var array All the messages which may be translated or not, depending on the language */
+ protected $mOptionalMessages;
+
+ /** @var array Namespace names */
+ protected $mNamespaceNames;
+
+ /** @var array Namespace aliases */
+ protected $mNamespaceAliases;
+
+ /** @var array Magic words */
+ protected $mMagicWords;
+
+ /** @var array Special page aliases */
+ protected $mSpecialPageAliases;
/**
* Load the list of languages: all the Messages*.php
* files in the languages directory.
- *
- * @param $exif bool Treat the Exif messages?
*/
- function __construct( $exif = true ) {
- require __DIR__ . '/messageTypes.inc';
- $this->mIgnoredMessages = $wgIgnoredMessages;
- if ( $exif ) {
- $this->mOptionalMessages = array_merge( $wgOptionalMessages );
- } else {
- $this->mOptionalMessages = array_merge( $wgOptionalMessages, $wgEXIFMessages );
- }
+ function __construct() {
+ wfRunHooks( 'LocalisationIgnoredOptionalMessages',
+ array( &$this->mIgnoredMessages, &$this->mOptionalMessages ) );
$this->mLanguages = array_keys( Language::fetchLanguageNames( null, 'mwfile' ) );
sort( $this->mLanguages );
@@ -88,7 +100,7 @@ class languages {
/**
* Load the language file.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*/
protected function loadFile( $code ) {
if ( isset( $this->mRawMessages[$code] ) &&
@@ -96,7 +108,8 @@ class languages {
isset( $this->mNamespaceNames[$code] ) &&
isset( $this->mNamespaceAliases[$code] ) &&
isset( $this->mMagicWords[$code] ) &&
- isset( $this->mSpecialPageAliases[$code] ) ) {
+ isset( $this->mSpecialPageAliases[$code] )
+ ) {
return;
}
$this->mRawMessages[$code] = array();
@@ -105,12 +118,16 @@ class languages {
$this->mNamespaceAliases[$code] = array();
$this->mMagicWords[$code] = array();
$this->mSpecialPageAliases[$code] = array();
+
+ $jsonfilename = Language::getJsonMessagesFileName( $code );
+ if ( file_exists( $jsonfilename ) ) {
+ $json = Language::getLocalisationCache()->readJSONFile( $jsonfilename );
+ $this->mRawMessages[$code] = $json['messages'];
+ }
+
$filename = Language::getMessagesFileName( $code );
if ( file_exists( $filename ) ) {
require $filename;
- if ( isset( $messages ) ) {
- $this->mRawMessages[$code] = $messages;
- }
if ( isset( $fallback ) ) {
$this->mFallback[$code] = $fallback;
}
@@ -130,14 +147,18 @@ class languages {
}
/**
- * Load the messages for a specific language (which is not English) and divide them to groups:
+ * Load the messages for a specific language (which is not English) and divide them to
+ * groups:
* all - all the messages.
* required - messages which should be translated in order to get a complete translation.
- * optional - messages which can be translated, the fallback translation is used if not translated.
- * obsolete - messages which should not be translated, either because they do not exist, or they are ignored messages.
- * translated - messages which are either required or optional, but translated from English and needed.
+ * optional - messages which can be translated, the fallback translation is used if not
+ * translated.
+ * obsolete - messages which should not be translated, either because they do not exist,
+ * or they are ignored messages.
+ * translated - messages which are either required or optional, but translated from
+ * English and needed.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*/
private function loadMessages( $code ) {
if ( isset( $this->mMessages[$code] ) ) {
@@ -166,10 +187,13 @@ class languages {
/**
* Load the messages for English and divide them to groups:
* all - all the messages.
- * required - messages which should be translated to other languages in order to get a complete translation.
- * optional - messages which can be translated to other languages, but it's not required for a complete translation.
+ * required - messages which should be translated to other languages in order to get a
+ * complete translation.
+ * optional - messages which can be translated to other languages, but it's not required
+ * for a complete translation.
* ignored - messages which should not be translated to other languages.
- * translatable - messages which are either required or optional, but can be translated from English.
+ * translatable - messages which are either required or optional, but can be translated
+ * from English.
*/
private function loadGeneralMessages() {
if ( isset( $this->mGeneralMessages ) ) {
@@ -199,111 +223,125 @@ class languages {
* fallback language messages, divided to groups:
* all - all the messages.
* required - messages which should be translated in order to get a complete translation.
- * optional - messages which can be translated, the fallback translation is used if not translated.
- * obsolete - messages which should not be translated, either because they do not exist, or they are ignored messages.
- * translated - messages which are either required or optional, but translated from English and needed.
+ * optional - messages which can be translated, the fallback translation is used if not
+ * translated.
+ * obsolete - messages which should not be translated, either because they do not exist,
+ * or they are ignored messages.
+ * translated - messages which are either required or optional, but translated from
+ * English and needed.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return string The messages in this language.
*/
public function getMessages( $code ) {
$this->loadMessages( $code );
+
return $this->mMessages[$code];
}
/**
* Get all the general English messages, divided to groups:
* all - all the messages.
- * required - messages which should be translated to other languages in order to get a complete translation.
- * optional - messages which can be translated to other languages, but it's not required for a complete translation.
+ * required - messages which should be translated to other languages in
+ * order to get a complete translation.
+ * optional - messages which can be translated to other languages, but it's
+ * not required for a complete translation.
* ignored - messages which should not be translated to other languages.
- * translatable - messages which are either required or optional, but can be translated from English.
+ * translatable - messages which are either required or optional, but can be
+ * translated from English.
*
* @return array The general English messages.
*/
public function getGeneralMessages() {
$this->loadGeneralMessages();
+
return $this->mGeneralMessages;
}
/**
* Get fallback language code for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return string Fallback code.
*/
public function getFallback( $code ) {
$this->loadFile( $code );
+
return $this->mFallback[$code];
}
/**
* Get namespace names for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array Namespace names.
*/
public function getNamespaceNames( $code ) {
$this->loadFile( $code );
+
return $this->mNamespaceNames[$code];
}
/**
* Get namespace aliases for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array Namespace aliases.
*/
public function getNamespaceAliases( $code ) {
$this->loadFile( $code );
+
return $this->mNamespaceAliases[$code];
}
/**
* Get magic words for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array Magic words.
*/
public function getMagicWords( $code ) {
$this->loadFile( $code );
+
return $this->mMagicWords[$code];
}
/**
* Get special page aliases for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array Special page aliases.
*/
public function getSpecialPageAliases( $code ) {
$this->loadFile( $code );
+
return $this->mSpecialPageAliases[$code];
}
/**
* Get the untranslated messages for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The untranslated messages for this language.
*/
public function getUntranslatedMessages( $code ) {
$this->loadGeneralMessages();
$this->loadMessages( $code );
+
return array_diff_key( $this->mGeneralMessages['required'], $this->mMessages[$code]['required'] );
}
/**
* Get the duplicate messages for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The duplicate messages for this language.
*/
@@ -316,26 +354,28 @@ class languages {
$duplicateMessages[$key] = $value;
}
}
+
return $duplicateMessages;
}
/**
* Get the obsolete messages for a specific language.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The obsolete messages for this language.
*/
public function getObsoleteMessages( $code ) {
$this->loadGeneralMessages();
$this->loadMessages( $code );
+
return $this->mMessages[$code]['obsolete'];
}
/**
* Get the messages whose variables do not match the original ones.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The messages whose variables do not match the original ones.
*/
@@ -348,11 +388,13 @@ class languages {
$missing = false;
foreach ( $variables as $var ) {
if ( preg_match( "/$var/sU", $this->mGeneralMessages['translatable'][$key] ) &&
- !preg_match( "/$var/sU", $value ) ) {
+ !preg_match( "/$var/sU", $value )
+ ) {
$missing = true;
}
if ( !preg_match( "/$var/sU", $this->mGeneralMessages['translatable'][$key] ) &&
- preg_match( "/$var/sU", $value ) ) {
+ preg_match( "/$var/sU", $value )
+ ) {
$missing = true;
}
}
@@ -360,13 +402,14 @@ class languages {
$mismatchMessages[$key] = $value;
}
}
+
return $mismatchMessages;
}
/**
* Get the messages which do not use plural.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The messages which do not use plural in this language.
*/
@@ -375,17 +418,20 @@ class languages {
$this->loadMessages( $code );
$messagesWithoutPlural = array();
foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
- if ( stripos( $this->mGeneralMessages['translatable'][$key], '{{plural:' ) !== false && stripos( $value, '{{plural:' ) === false ) {
+ if ( stripos( $this->mGeneralMessages['translatable'][$key], '{{plural:' ) !== false &&
+ stripos( $value, '{{plural:' ) === false
+ ) {
$messagesWithoutPlural[$key] = $value;
}
}
+
return $messagesWithoutPlural;
}
/**
* Get the empty messages.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The empty messages for this language.
*/
@@ -398,13 +444,14 @@ class languages {
$emptyMessages[$key] = $value;
}
}
+
return $emptyMessages;
}
/**
* Get the messages with trailing whitespace.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The messages with trailing whitespace in this language.
*/
@@ -417,13 +464,14 @@ class languages {
$messagesWithWhitespace[$key] = $value;
}
}
+
return $messagesWithWhitespace;
}
/**
* Get the non-XHTML messages.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The non-XHTML messages for this language.
*/
@@ -445,13 +493,14 @@ class languages {
$nonXHTMLMessages[$key] = $value;
}
}
+
return $nonXHTMLMessages;
}
/**
* Get the messages which include wrong characters.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The messages which include wrong characters in this language.
*/
@@ -482,13 +531,14 @@ class languages {
$wrongCharsMessages[$key] = $value;
}
}
+
return $wrongCharsMessages;
}
/**
* Get the messages which include dubious links.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The messages which include dubious links in this language.
*/
@@ -500,24 +550,25 @@ class languages {
foreach ( $this->mMessages[$code]['translated'] as $key => $value ) {
$matches = array();
preg_match_all( "/\[\[([{$tc}]+)(?:\\|(.+?))?]]/sDu", $value, $matches );
- for ( $i = 0; $i < count( $matches[0] ); $i++ ) {
+ $numMatches = count( $matches[0] );
+ for ( $i = 0; $i < $numMatches; $i++ ) {
if ( preg_match( "/.*project.*/isDu", $matches[1][$i] ) ) {
$messages[$key][] = $matches[0][$i];
}
}
-
if ( isset( $messages[$key] ) ) {
$messages[$key] = implode( $messages[$key], ", " );
}
}
+
return $messages;
}
/**
* Get the messages which include unbalanced brackets.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The messages which include unbalanced brackets in this language.
*/
@@ -547,15 +598,15 @@ class languages {
if ( $a !== $b || $c !== $d ) {
$messages[$key] = "$a, $b, $c, $d";
}
-
}
+
return $messages;
}
/**
* Get the untranslated namespace names.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The untranslated namespace names in this language.
*/
@@ -566,13 +617,14 @@ class languages {
if ( isset( $namespacesDiff[NS_MAIN] ) ) {
unset( $namespacesDiff[NS_MAIN] );
}
+
return $namespacesDiff;
}
/**
* Get the project talk namespace names with no $1.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The problematic project talk namespaces in this language.
*/
@@ -601,7 +653,7 @@ class languages {
/**
* Get the untranslated magic words.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The untranslated magic words in this language.
*/
@@ -614,13 +666,14 @@ class languages {
$magicWords[$key] = $value[1];
}
}
+
return $magicWords;
}
/**
* Get the obsolete magic words.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The obsolete magic words in this language.
*/
@@ -633,13 +686,14 @@ class languages {
$magicWords[$key] = $value[1];
}
}
+
return $magicWords;
}
/**
* Get the magic words that override the original English magic word.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The overriding magic words in this language.
*/
@@ -662,13 +716,14 @@ class languages {
}
}
}
+
return $magicWords;
}
/**
* Get the magic words which do not match the case-sensitivity of the original words.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The magic words whose case does not match in this language.
*/
@@ -685,13 +740,14 @@ class languages {
$magicWords[$key] = $local[0];
}
}
+
return $magicWords;
}
/**
* Get the untranslated special page names.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The untranslated special page names in this language.
*/
@@ -704,13 +760,14 @@ class languages {
$specialPageAliases[$key] = $value[0];
}
}
+
return $specialPageAliases;
}
/**
* Get the obsolete special page names.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*
* @return array The obsolete special page names in this language.
*/
@@ -723,12 +780,12 @@ class languages {
$specialPageAliases[$key] = $value[0];
}
}
+
return $specialPageAliases;
}
}
-class extensionLanguages extends languages {
-
+class ExtensionLanguages extends Languages {
/**
* @var MessageGroup
*/
@@ -736,7 +793,7 @@ class extensionLanguages extends languages {
/**
* Load the messages group.
- * @param $group MessageGroup The messages group.
+ * @param MessageGroup $group The messages group.
*/
function __construct( MessageGroup $group ) {
$this->mMessageGroup = $group;
@@ -757,7 +814,7 @@ class extensionLanguages extends languages {
/**
* Load the language file.
*
- * @param $code string The language code.
+ * @param string $code The language code.
*/
protected function loadFile( $code ) {
if ( !isset( $this->mRawMessages[$code] ) ) {