| 1 | <?php |
| 2 | /** |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | * http://www.gnu.org/copyleft/gpl.html |
| 17 | * |
| 18 | * @file |
| 19 | */ |
| 20 | |
| 21 | use MediaWiki\Language\Language; |
| 22 | |
| 23 | /** |
| 24 | * Turkish (Türkçe) |
| 25 | * |
| 26 | * The Turkish language, like other Turkic languages, distinguishes |
| 27 | * a dotted letter 'i' from a dotless letter 'ı' (U+0131 LATIN SMALL LETTER DOTLESS I). |
| 28 | * In these languages, each has an equivalent uppercase mapping: |
| 29 | * ı (U+0131 LATIN SMALL LETTER DOTLESS I) -> I (U+0049 LATIN CAPITAL LETTER I), |
| 30 | * i (U+0069 LATIN SMALL LETTER I) -> İ (U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE). |
| 31 | * |
| 32 | * Unicode CaseFolding.txt defines these mappings as type 'T', which means that |
| 33 | * they are only for the Turkic languages, tr and az. PHP ignores these mappings, |
| 34 | * so we have to override the ucfirst and lcfirst methods. |
| 35 | * |
| 36 | * See https://en.wikipedia.org/wiki/Dotted_and_dotless_I and T30040 |
| 37 | * |
| 38 | * @ingroup Languages |
| 39 | */ |
| 40 | class LanguageTr extends Language { |
| 41 | |
| 42 | private const UC = [ 'I', 'İ' ]; |
| 43 | private const LC = [ 'ı', 'i' ]; |
| 44 | |
| 45 | public function ucfirst( $str ) { |
| 46 | $first = mb_substr( $str, 0, 1 ); |
| 47 | if ( in_array( $first, self::LC ) ) { |
| 48 | $first = str_replace( self::LC, self::UC, $first ); |
| 49 | return $first . mb_substr( $str, 1 ); |
| 50 | } |
| 51 | return parent::ucfirst( $str ); |
| 52 | } |
| 53 | |
| 54 | public function lcfirst( $str ) { |
| 55 | $first = mb_substr( $str, 0, 1 ); |
| 56 | if ( in_array( $first, self::UC ) ) { |
| 57 | $first = str_replace( self::UC, self::LC, $first ); |
| 58 | return $first . mb_substr( $str, 1 ); |
| 59 | } |
| 60 | return parent::lcfirst( $str ); |
| 61 | } |
| 62 | |
| 63 | } |