Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
10 / 16
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
KuConverter
62.50% covered (warning)
62.50%
10 / 16
60.00% covered (warning)
60.00%
3 / 5
7.90
0.00% covered (danger)
0.00%
0 / 1
 getMainCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLanguageVariants
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getVariantsFallbacks
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 loadDefaultTables
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 translate
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
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
21use MediaWiki\Language\ReplacementArray;
22
23/**
24 * Kurdish converter routines.
25 *
26 * @ingroup Languages
27 */
28class KuConverter extends LanguageConverterSpecific {
29
30    private const ARABIC_TO_LATIN = [
31        'ب' => 'b', 'ج' => 'c', 'چ' => 'ç', 'د' => 'd', 'ف' => 'f', 'گ' => 'g', 'ھ' => 'h',
32        'ہ' => 'h', 'ه' => 'h', 'ح' => 'h', 'ژ' => 'j', 'ك' => 'k', 'ک' => 'k', 'ل' => 'l',
33        'م' => 'm', 'ن' => 'n', 'پ' => 'p', 'ق' => 'q', 'ر' => 'r', 'س' => 's', 'ش' => 'ş',
34        'ت' => 't', 'ڤ' => 'v', 'خ' => 'x', 'غ' => 'x', 'ز' => 'z',
35
36        /* full and semi-vowel */
37        'ڵ' => 'll', # ll
38        'ڕ' => 'rr', # rr
39        'ا' => 'a',
40        'ە' => 'e',
41        'ه‌' => 'e', # with one non-joiner
42        'ه‌‌' => 'e', # with two non-joiners
43        'ة' => 'e',
44        'ێ' => 'ê',
45        'ي' => 'î',
46        'ی' => 'î', # U+06CC  db 8c  ARABIC LETTER FARSI YEH
47        'ى' => 'î', # U+0649  d9 89  ARABIC LETTER ALEF MAKSURA
48        'ۆ' => 'o',
49        'و' => 'w',
50        'ئ' => '', # initial hemze should not be shown
51        '،' => ',',
52        'ع' => '\'', # ayn
53        '؟' => '?',
54
55        # digits
56        '٠' => '0', # U+0660
57        '١' => '1', # U+0661
58        '٢' => '2', # U+0662
59        '٣' => '3', # U+0663
60        '٤' => '4', # U+0664
61        '٥' => '5', # U+0665
62        '٦' => '6', # U+0666
63        '٧' => '7', # U+0667
64        '٨' => '8', # U+0668
65        '٩' => '9', # U+0669
66    ];
67
68    private const LATIN_TO_ARABIC = [
69        'b' => 'ب', 'c' => 'ج', 'ç' => 'چ', 'd' => 'د', 'f' => 'ف', 'g' => 'گ',
70        'h' => 'ه', 'j' => 'ژ', 'k' => 'ک', 'l' => 'ل',
71        'm' => 'م', 'n' => 'ن', 'p' => 'پ', 'q' => 'ق', 'r' => 'ر', 's' => 'س', 'ş' => 'ش',
72        't' => 'ت', 'v' => 'ڤ',
73        'x' => 'خ', 'y' => 'ی', 'z' => 'ز',
74
75        'B' => 'ب', 'C' => 'ج', 'Ç' => 'چ', 'D' => 'د', 'F' => 'ف', 'G' => 'گ',
76        'H' => 'ح', 'J' => 'ژ', 'K' => 'ک', 'L' => 'ل',
77        'M' => 'م', 'N' => 'ن', 'P' => 'پ', 'Q' => 'ق', 'R' => 'ر', 'S' => 'س', 'Ş' => 'ش',
78        'T' => 'ت', 'V' => 'ڤ', 'W' => 'و', 'X' => 'خ',
79        'Y' => 'ی', 'Z' => 'ز',
80
81        /* Vowels */
82        'a' => 'ا',
83        'e' => 'ە',
84        'ê' => 'ێ',
85        'i' => '',
86        'î' => 'ی',
87        'o' => 'ۆ',
88        'u' => 'و',
89        'û' => 'وو',
90        'w' => 'و',
91        ',' => '،',
92        '?' => '؟',
93
94        # Try to replace the leading vowel
95        ' a' => 'ئا ',
96        ' e' => 'ئە ',
97        ' ê' => 'ئێ ',
98        ' î' => 'ئی ',
99        ' o' => 'ئۆ ',
100        ' u' => 'ئو ',
101        ' û' => 'ئوو ',
102        'A' => 'ئا',
103        'E' => 'ئە',
104        'Ê' => 'ئێ',
105        'Î' => 'ئی',
106        'O' => 'ئۆ',
107        'U' => 'ئو',
108        'Û' => 'ئوو',
109        ' A' => 'ئا ',
110        ' E' => 'ئە ',
111        ' Ê' => 'ئێ ',
112        ' Î' => 'ئی ',
113        ' O' => 'ئۆ ',
114        ' U' => 'ئو ',
115        ' Û' => 'ئوو ',
116    ];
117
118    public function getMainCode(): string {
119        return 'ku';
120    }
121
122    public function getLanguageVariants(): array {
123        return [ 'ku', 'ku-arab', 'ku-latn' ];
124    }
125
126    public function getVariantsFallbacks(): array {
127        return [
128            'ku' => 'ku-latn',
129            'ku-arab' => 'ku-latn',
130            'ku-latn' => 'ku-arab',
131        ];
132    }
133
134    protected function loadDefaultTables(): array {
135        return [
136            'ku-latn' => new ReplacementArray( self::ARABIC_TO_LATIN ),
137            'ku-arab' => new ReplacementArray( self::LATIN_TO_ARABIC ),
138            'ku' => new ReplacementArray()
139        ];
140    }
141
142    public function translate( $text, $toVariant ) {
143        $this->loadTables();
144
145        if ( !isset( $this->mTables[$toVariant] ) ) {
146            throw new LogicException( 'Broken variant table: ' . implode( ',', array_keys( $this->mTables ) ) );
147        }
148
149        return parent::translate( $text, $toVariant );
150    }
151}