summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Evans <grknight@gentoo.org>2022-09-27 18:53:03 -0400
committerBrian Evans <grknight@gentoo.org>2022-09-27 19:02:02 -0400
commit5ca8d30155e11d97b20f79acec40632c2e06fcd5 (patch)
tree7531fb116791f8328c0bb0cabe42265ca67e6df9 /MLEB/Translate/ffs/GettextFFS.php
parentMerge branch 'master' into wikitest (diff)
downloadextensions-5ca8d30155e11d97b20f79acec40632c2e06fcd5.tar.gz
extensions-5ca8d30155e11d97b20f79acec40632c2e06fcd5.tar.bz2
extensions-5ca8d30155e11d97b20f79acec40632c2e06fcd5.zip
Update MLEB to 2021.12v1.35.2
This is the final version for MW 1.35 Signed-off-by: Brian Evans <grknight@gentoo.org>
Diffstat (limited to 'MLEB/Translate/ffs/GettextFFS.php')
-rw-r--r--MLEB/Translate/ffs/GettextFFS.php34
1 files changed, 28 insertions, 6 deletions
diff --git a/MLEB/Translate/ffs/GettextFFS.php b/MLEB/Translate/ffs/GettextFFS.php
index bdbbd0c5..deb3dcfc 100644
--- a/MLEB/Translate/ffs/GettextFFS.php
+++ b/MLEB/Translate/ffs/GettextFFS.php
@@ -17,6 +17,9 @@ use MediaWiki\Logger\LoggerFactory;
* @ingroup FFS
*/
class GettextFFS extends SimpleFFS implements MetaYamlSchemaExtender {
+ private $allowPotMode = false;
+ protected $offlineMode = false;
+
public function supportsFuzzy() {
return 'yes';
}
@@ -25,13 +28,24 @@ class GettextFFS extends SimpleFFS implements MetaYamlSchemaExtender {
return [ '.pot', '.po' ];
}
- protected $offlineMode = false;
-
/** @param bool $value */
public function setOfflineMode( $value ) {
$this->offlineMode = $value;
}
+ /** @inheritDoc */
+ public function read( $code ) {
+ // This is somewhat hacky, but pot mode should only ever be used for the source language.
+ // See https://phabricator.wikimedia.org/T230361
+ $this->allowPotMode = $this->getGroup()->getSourceLanguage() === $code;
+
+ try {
+ return parent::read( $code );
+ } finally {
+ $this->allowPotMode = false;
+ }
+ }
+
/**
* @param string $data
* @return array
@@ -57,13 +71,13 @@ class GettextFFS extends SimpleFFS implements MetaYamlSchemaExtender {
public function parseGettext( $data ) {
$mangler = $this->group->getMangler();
- $useCtxtAsKey = isset( $this->extra['CtxtAsKey'] ) && $this->extra['CtxtAsKey'];
+ $useCtxtAsKey = $this->extra['CtxtAsKey'] ?? false;
$keyAlgorithm = 'simple';
if ( isset( $this->extra['keyAlgorithm'] ) ) {
$keyAlgorithm = $this->extra['keyAlgorithm'];
}
- return self::parseGettextData( $data, $useCtxtAsKey, $mangler, $keyAlgorithm );
+ return self::parseGettextData( $data, $useCtxtAsKey, $mangler, $keyAlgorithm, $this->allowPotMode );
}
/**
@@ -73,10 +87,17 @@ class GettextFFS extends SimpleFFS implements MetaYamlSchemaExtender {
* or use msgctxt (non-standard po-files)
* @param StringMangler $mangler
* @param string $keyAlgorithm Key generation algorithm, see generateKeyFromItem
+ * @param bool $allowPotMode
* @throws MWException
* @return array
*/
- public static function parseGettextData( $data, $useCtxtAsKey, $mangler, $keyAlgorithm ) {
+ public static function parseGettextData(
+ $data,
+ $useCtxtAsKey,
+ $mangler,
+ $keyAlgorithm,
+ bool $allowPotMode
+ ) {
$potmode = false;
// Normalise newlines, to make processing easier
@@ -100,7 +121,7 @@ class GettextFFS extends SimpleFFS implements MetaYamlSchemaExtender {
// Check for pot-mode by checking if the header is fuzzy
$flags = self::parseFlags( $headerSection );
if ( in_array( 'fuzzy', $flags, true ) ) {
- $potmode = true;
+ $potmode = $allowPotMode;
}
} else {
$message = "Gettext file header was not found:\n\n$data";
@@ -313,6 +334,7 @@ class GettextFFS extends SimpleFFS implements MetaYamlSchemaExtender {
} else { // legacy
global $wgLegalTitleChars;
$snippet = $item['id'];
+ // @phan-suppress-next-line PhanPossiblyUndeclaredVariable
$snippet = preg_replace( "/[^$wgLegalTitleChars]/", ' ', $snippet );
$snippet = preg_replace( "/[:&%\/_]/", ' ', $snippet );
$snippet = preg_replace( '/ {2,}/', ' ', $snippet );