From: Antoine Musso Date: Tue, 15 Mar 2011 21:56:54 +0000 (+0000) Subject: bug 28040 Turkish: properly handle dotted and dotless i X-Git-Tag: 1.31.0-rc.0~31380 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=3e6e06a3bb2bd5ef8158f7eefb4f7c35040d1870;p=lhc%2Fweb%2Fwiklou.git bug 28040 Turkish: properly handle dotted and dotless i As mentioned by Bawolff on code review, r83970 only handled case change of the first character lacking full strings support. This patch override the uc and lc methods for the Turkish language (tr) using preg_replace() which know about unicode. Other possible choices would have been: - strtr() => outputs garbage - mbstring => can not know we handle turkish and transform i to I! I have amended the RELEASE-NOTES to reflect this patch. Some new tests are added as well to cover the regular functions as well as the specific Turkish overriding. Result in testdox: LanguageTr [x] Change case of first char being dotted and dotless i [x] Language tr lower casing override [x] Language tr upper casing override [x] Upper casing of a string with dotted and dot less i [x] Lower casing of a string with dotted and dot less i --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3f8bba03fd..576edb0852 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -277,7 +277,8 @@ changes to languages because of Bugzilla reports. * (bug 27681) Set $namespaceGenderAliases for Portuguese (pt and pt-br) * (bug 27785) Fallback language for Kabardian (kbd) is English now. * (bug 27825) Raw watchlist edit message now uses formatted numbers. -* (bug 28040) Turkish: properly lower case 'I' to 'ı' (dotless i) +* (bug 28040) Turkish: properly lower case 'I' to 'ı' (dotless i) and + uppercase 'i' to 'İ' (dotted i) == Compatibility == diff --git a/languages/classes/LanguageTr.php b/languages/classes/LanguageTr.php index dec504588a..297f6b43c5 100644 --- a/languages/classes/LanguageTr.php +++ b/languages/classes/LanguageTr.php @@ -28,4 +28,16 @@ class LanguageTr extends Language { } } + /** @see bug 28040 */ + function uc( $string ) { + $string = preg_replace( '/i/', 'İ', $string ); + return parent::uc( $string ); + } + + /** @see bug 28040 */ + function lc( $string ) { + $string = preg_replace( '/I/', 'ı', $string ); + return parent::lc( $string ); + } + } diff --git a/tests/phpunit/languages/LanguageTrTest.php b/tests/phpunit/languages/LanguageTrTest.php index ddc8ea6a99..eb3601d202 100644 --- a/tests/phpunit/languages/LanguageTrTest.php +++ b/tests/phpunit/languages/LanguageTrTest.php @@ -24,7 +24,7 @@ class LanguageTrTest extends MediaWikiTestCase { * @see http://en.wikipedia.org/wiki/Dotted_and_dotless_I * @dataProvider provideDottedAndDotlessI */ - function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) { + function testChangeCaseOfFirstCharBeingDottedAndDotlessI( $func, $input, $inputCase, $expected ) { if( $func == 'ucfirst' ) { $res = $this->lang->ucfirst( $input ); } elseif( $func == 'lcfirst' ) { @@ -62,6 +62,60 @@ class LanguageTrTest extends MediaWikiTestCase { array( 'lcfirst', 'IPhone', 'upper', 'ıPhone' ), ); + } + +##### LanguageTr specificities ############################################# + /** + * @cover LanguageTr:lc + * See @bug 28040 + */ + function testLanguageTrLowerCasingOverride() { + $this->assertEquals( 'ııııı', $this->lang->lc( 'IIIII') ); + } + /** + * @cover LanguageTr:uc + * See @bug 28040 + */ + function testLanguageTrUpperCasingOverride() { + $this->assertEquals( 'İİİİİ', $this->lang->uc( 'iiiii') ); + } + +##### Upper casing a string ################################################# + /** + * Generic test for the Turkish dotted and dotless I strings + * See @bug 28040 + * @dataProvider provideUppercaseStringsWithDottedAndDotlessI + */ + function testUpperCasingOfAStringWithDottedAndDotLessI( $expected, $input ) { + $this->assertEquals( $expected, $this->lang->uc( $input ) ); + } + function provideUppercaseStringsWithDottedAndDotlessI() { + return array( + # expected, input string to uc() + array( 'IIIII', 'ııııı' ), + array( 'IIIII', 'IIIII' ), #identity + array( 'İİİİİ', 'iiiii' ), # Specifically handled by LanguageTr:uc + array( 'İİİİİ', 'İİİİİ' ), #identity + ); + } + +##### Lower casing a string ################################################# + /** + * Generic test for the Turkish dotted and dotless I strings + * See @bug 28040 + * @dataProvider provideLowercaseStringsWithDottedAndDotlessI + */ + function testLowerCasingOfAStringWithDottedAndDotLessI( $expected, $input ) { + $this->assertEquals( $expected, $this->lang->lc( $input ) ); + } + function provideLowercaseStringsWithDottedAndDotlessI() { + return array( + # expected, input string to lc() + array( 'ııııı', 'IIIII' ), # Specifically handled by LanguageTr:lc + array( 'ııııı', 'ııııı' ), #identity + array( 'iiiii', 'İİİİİ' ), + array( 'iiiii', 'iiiii' ), #identity + ); } }