From 9e9ee49c54567b852419f591206b63d8612d3281 Mon Sep 17 00:00:00 2001 From: Liangent Date: Wed, 15 Aug 2012 08:35:04 +0800 Subject: [PATCH] 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 --- languages/LanguageConverter.php | 33 ++++++++++++++++++++++++++++++++- tests/parser/parserTests.txt | 24 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) 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 -- 2.20.1