From: Liangent
Date: Wed, 15 Aug 2012 00:35:04 +0000 (+0800)
Subject: Partly disable title conversion if variant == main language code
X-Git-Tag: 1.31.0-rc.0~19762^2
X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=9e9ee49c54567b852419f591206b63d8612d3281;p=lhc%2Fweb%2Fwiklou.git
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
---
diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php
index d9227d7916..4969a7c88d 100644
--- a/languages/LanguageConverter.php
+++ b/languages/LanguageConverter.php
@@ -1357,6 +1357,37 @@ class ConverterRule {
}
}
+ /**
+ * 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 @@ class ConverterRule {
$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 f38d826ec0..a4e32abd34 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -12130,6 +12130,30 @@ This won't take interferes with the title rule.
!! 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
+
+
+!! 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
+
+
+!! end
+
!! test
Raw output of variant escape tags (R flag)
!! options