Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
73.68% covered (warning)
73.68%
14 / 19
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ShiConverter
73.68% covered (warning)
73.68%
14 / 19
80.00% covered (warning)
80.00%
4 / 5
7.89
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%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 translate
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
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 * Shilha specific code.
23 *
24 * Conversion script between Latin and Tifinagh for Tachelhit.
25 * - Tifinagh -> lowercase Latin
26 * - lowercase/uppercase Latin -> Tifinagh
27 *
28 *
29 * Based on:
30 *   - https://en.wikipedia.org/wiki/Shilha_language
31 *   - LanguageSr.php
32 *
33 * @ingroup Languages
34 */
35class ShiConverter extends LanguageConverterSpecific {
36    // The Tifinagh alphabet sequence is based on
37    // "Dictionnaire Général de la Langue Amazighe Informatisé"
38    // by IRCAM (https://tal.ircam.ma/dglai/lexieam.php, DGLAi),
39    // with the labio-velarization mark in the end
40    public $mToLatin = [
41        'ⴰ' => 'a',
42        'ⴱ' => 'b',
43        'ⴳ' => 'g',
44        'ⴷ' => 'd',
45        'ⴹ' => 'ḍ',
46        'ⴻ' => 'e',
47        'ⴼ' => 'f',
48        'ⴽ' => 'k',
49        'ⵀ' => 'h',
50        'ⵃ' => 'ḥ',
51        'ⵄ' => 'ɛ',
52        'ⵅ' => 'x',
53        'ⵇ' => 'q',
54        'ⵉ' => 'i',
55        'ⵊ' => 'j',
56        'ⵍ' => 'l',
57        'ⵎ' => 'm',
58        'ⵏ' => 'n',
59        'ⵓ' => 'u',
60        'ⵔ' => 'r',
61        'ⵕ' => 'ṛ',
62        'ⵖ' => 'ɣ',
63        'ⵙ' => 's',
64        'ⵚ' => 'ṣ',
65        'ⵛ' => 'c',
66        'ⵜ' => 't',
67        'ⵟ' => 'ṭ',
68        'ⵡ' => 'w',
69        'ⵢ' => 'y',
70        'ⵣ' => 'z',
71        'ⵥ' => 'ẓ',
72        'ⵯ' => 'ʷ',
73    ];
74
75    // The sequence is based on DGLAi, with the non-standard letters in the end
76    public $mUpperToLowerCaseLatin = [
77        'A' => 'a',
78        'B' => 'b',
79        'G' => 'g',
80        'D' => 'd',
81        'Ḍ' => 'ḍ',
82        'E' => 'e',
83        'F' => 'f',
84        'K' => 'k',
85        'H' => 'h',
86        'Ḥ' => 'ḥ',
87        'Ɛ' => 'ɛ',
88        'X' => 'x',
89        'Q' => 'q',
90        'I' => 'i',
91        'J' => 'j',
92        'L' => 'l',
93        'M' => 'm',
94        'N' => 'n',
95        'U' => 'u',
96        'R' => 'r',
97        'Ṛ' => 'ṛ',
98        'Ɣ' => 'ɣ',
99        'S' => 's',
100        'Ṣ' => 'ṣ',
101        'C' => 'c',
102        'T' => 't',
103        'Ṭ' => 'ṭ',
104        'W' => 'w',
105        'Y' => 'y',
106        'Z' => 'z',
107        'Ẓ' => 'ẓ',
108        'O' => 'o',
109        'P' => 'p',
110        'V' => 'v',
111    ];
112
113    // The sequence is based on DGLAi, with the labio-velarization mark and
114    // the non-standard letters in the end
115    public $mToTifinagh = [
116        'a' => 'ⴰ',
117        'b' => 'ⴱ',
118        'g' => 'ⴳ',
119        'd' => 'ⴷ',
120        'ḍ' => 'ⴹ',
121        'e' => 'ⴻ',
122        'f' => 'ⴼ',
123        'k' => 'ⴽ',
124        'h' => 'ⵀ',
125        'ḥ' => 'ⵃ',
126        'ɛ' => 'ⵄ',
127        'x' => 'ⵅ',
128        'q' => 'ⵇ',
129        'i' => 'ⵉ',
130        'j' => 'ⵊ',
131        'l' => 'ⵍ',
132        'm' => 'ⵎ',
133        'n' => 'ⵏ',
134        'u' => 'ⵓ',
135        'r' => 'ⵔ',
136        'ṛ' => 'ⵕ',
137        'ɣ' => 'ⵖ',
138        's' => 'ⵙ',
139        'ṣ' => 'ⵚ',
140        'c' => 'ⵛ',
141        't' => 'ⵜ',
142        'ṭ' => 'ⵟ',
143        'w' => 'ⵡ',
144        'y' => 'ⵢ',
145        'z' => 'ⵣ',
146        'ẓ' => 'ⵥ',
147        'ʷ' => 'ⵯ',
148        'o' => 'ⵓ',
149        'p' => 'ⴱ',
150        'v' => 'ⴼ',
151    ];
152
153    public function getMainCode(): string {
154        return 'shi';
155    }
156
157    public function getLanguageVariants(): array {
158        return [ 'shi', 'shi-tfng', 'shi-latn' ];
159    }
160
161    public function getVariantsFallbacks(): array {
162        return [
163            'shi' => [ 'shi-latn', 'shi-tfng' ],
164            'shi-tfng' => 'shi',
165            'shi-latn' => 'shi',
166        ];
167    }
168
169    protected function loadDefaultTables(): array {
170        return [
171            'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
172            'shi-tfng' => new ReplacementArray( $this->mToTifinagh ),
173            'shi-latn' => new ReplacementArray( $this->mToLatin ),
174            'shi' => new ReplacementArray()
175        ];
176    }
177
178    public function translate( $text, $toVariant ) {
179        // If $text is empty or only includes spaces, do nothing
180        // Otherwise translate it
181        if ( trim( $text ) ) {
182            $this->loadTables();
183            // For Tifinagh, first translate uppercase to lowercase Latin
184            if ( $toVariant == 'shi-tfng' ) {
185                $text = $this->mTables['lowercase']->replace( $text );
186            }
187            $text = $this->mTables[$toVariant]->replace( $text );
188        }
189        return $text;
190    }
191}