/**
* Turkish (Türkçe)
*
+ * Turkish has two different i, one with a dot and another without a dot. They
+ * are totally different letters in this language, so we have to override the
+ * ucfirst and lcfirst methods.
+ * See http://en.wikipedia.org/wiki/Dotted_and_dotless_I
+ * and @bug 28040
* @ingroup Language
*/
class LanguageTr extends Language {
+
function ucfirst ( $string ) {
if ( !empty( $string ) && $string[0] == 'i' ) {
return 'İ' . substr( $string, 1 );
return parent::ucfirst( $string );
}
}
+
+ function lcfirst ( $string ) {
+ if ( !empty( $string ) && $string[0] == 'I' ) {
+ return 'ı' . substr( $string, 1 );
+ } else {
+ return parent::lcfirst( $string );
+ }
+ }
+
}
--- /dev/null
+<?php
+/**
+ * @author Ashar Voultoiz
+ * @copyright Copyright © 2011, Ashar Voultoiz
+ * @file
+ */
+
+require_once dirname(dirname(__FILE__)). '/bootstrap.php';
+
+/** Tests for MediaWiki languages/LanguageTr.php */
+class LanguageTrTest extends MediaWikiTestCase {
+ private $lang;
+
+ function setUp() {
+ $this->lang = Language::factory( 'Tr' );
+ }
+ function tearDown() {
+ unset( $this->lang );
+ }
+
+ /**
+ * See @bug 28040
+ * Credits to #wikipedia-tr users berm, []LuCkY[] and Emperyan
+ * @see http://en.wikipedia.org/wiki/Dotted_and_dotless_I
+ * @dataProvider provideDottedAndDotlessI
+ */
+ function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) {
+ if( $func == 'ucfirst' ) {
+ $res = $this->lang->ucfirst( $input );
+ } elseif( $func == 'lcfirst' ) {
+ $res = $this->lang->lcfirst( $input );
+ } else {
+ throw new MWException( __METHOD__ . " given an invalid function name '$func'" );
+ }
+
+ $msg = "Converting $inputCase case '$input' with $func should give '$expected'";
+
+ $this->assertEquals( $expected, $res, $msg );
+ }
+
+ function provideDottedAndDotlessI() {
+ return array(
+ # function, input, input case, expected
+ # Case changed:
+ array( 'ucfirst', 'ı', 'lower', 'I' ),
+ array( 'ucfirst', 'i', 'lower', 'İ' ),
+ array( 'lcfirst', 'I', 'upper', 'ı' ),
+ array( 'lcfirst', 'İ', 'upper', 'i' ),
+
+ # Already using the correct case
+ array( 'ucfirst', 'I', 'upper', 'I' ),
+ array( 'ucfirst', 'İ', 'upper', 'İ' ),
+ array( 'lcfirst', 'ı', 'lower', 'ı' ),
+ array( 'lcfirst', 'i', 'lower', 'i' ),
+
+ # A real example taken from bug 28040 using
+ # http://tr.wikipedia.org/wiki/%C4%B0Phone
+ array( 'lcfirst', 'iPhone', 'lower', 'iPhone' ),
+
+ # next case is valid in Turkish but are different words if we
+ # consider IPhone is English!
+ array( 'lcfirst', 'IPhone', 'upper', 'ıPhone' ),
+
+ );
+ }
+
+}