jenkins-bot has submitted this change and it was merged.
Change subject: Partly disable title conversion if variant == main language code
......................................................................
Partly disable title conversion if variant == main language code
Currently the main language code means "no conversion",
but may technically be used as a standalone variant (and
usually falls back to another variant). However for the
page title, since there can be a nice unconverted version
from real page name, it seems better to provide people who
choose "no conversion" with this unconverted version, rather
than a fallback from a variant which is always converted.
If a string targeting exactly the main language code exists
(ie. no fallbacks needed), it's still used. Because the
magic word DISPLAYTITLE cannot be used together with
language conversion syntax and people must use -{T| }- to
show a modified display title for "no conversion" version.
Change-Id: I25cf5a94f6e47f85a9d0b80cc1c9c9f957288478
---
M languages/LanguageConverter.php
M tests/parser/parserTests.txt
2 files changed, 56 insertions(+), 1 deletion(-)
Approvals:
GWicke: Looks good to me, approved
jenkins-bot: Verified
diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php
index d9227d7..4969a7c 100644
--- a/languages/LanguageConverter.php
+++ b/languages/LanguageConverter.php
@@ -1358,6 +1358,37 @@
}
/**
+ * Similar to getRuleConvertedStr(), but this prefers to use original
+ * page title if $variant === $this->mConverter->mMainLanguageCode
+ * and may return false in this case (so this title conversion rule
+ * will be ignored and the original title is shown).
+ *
+ * @since 1.20
+ * @param $variant The variant code to display page title in
+ * @return String|false The converted title or false if just page name
+ */
+ function getRuleConvertedTitle( $variant ) {
+ if ( $variant === $this->mConverter->mMainLanguageCode ) {
+ // If a string targeting exactly this variant is set,
+ // use it. Otherwise, just return false, so the real
+ // page name can be shown (and because variant === main,
+ // there'll be no further automatic conversion).
+ $disp = $this->getTextInBidtable( $variant );
+ if ( $disp ) {
+ return $disp;
+ }
+ if ( array_key_exists( $variant, $this->mUnidtable ) ) {
+ $disp = array_values(
$this->mUnidtable[$variant] );
+ $disp = $disp[0];
+ }
+ // Assigned above or still false.
+ return $disp;
+ } else {
+ return $this->getRuleConvertedStr( $variant );
+ }
+ }
+
+ /**
* Generate conversion table for all text.
* @private
*/
@@ -1509,7 +1540,7 @@
$this->mRuleDisplay =
$this->getRuleConvertedStr( $variant );
break;
case 'T':
- $this->mRuleTitle =
$this->getRuleConvertedStr( $variant );
+ $this->mRuleTitle =
$this->getRuleConvertedTitle( $variant );
$this->mRuleDisplay = '';
break;
default:
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index f38d826..a4e32ab 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -12131,6 +12131,30 @@
!! end
!! test
+Partly disable title conversion if variant == main language code
+!! options
+language=zh variant=zh title=[[ZH]] showtitle
+!! input
+-{T|zh-cn:CN;zh-tw:TW}-
+!! result
+ZH
+<p>
+</p>
+!! end
+
+!! test
+Partly disable title conversion if variant == main language code, more
+!! options
+language=zh variant=zh title=[[ZH]] showtitle
+!! input
+-{T|TW}-
+!! result
+ZH
+<p>
+</p>
+!! end
+
+!! test
Raw output of variant escape tags (R flag)
!! options
language=zh variant=zh-tw
--
To view, visit https://gerrit.wikimedia.org/r/19746
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I25cf5a94f6e47f85a9d0b80cc1c9c9f957288478
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Liangent <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Liangent <[email protected]>
Gerrit-Reviewer: Nasirkhan <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: SPQRobin <[email protected]>
Gerrit-Reviewer: Siddhartha Ghai <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits