Debian Codegraph @

includes/language/converters/KuConverter.php

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