Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ZghConverter
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 5
56
0.00% covered (danger)
0.00%
0 / 1
 getMainCode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLanguageVariants
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVariantsFallbacks
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadDefaultTables
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 translate
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
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 * Standard Moroccan Amazigh specific code.
25 *
26 * Conversion script for Tifinagh to lowercase Latin for Standard Moroccan Amazigh.
27 *
28 *
29 * Based on:
30 *   - LanguageShi.php
31 *   - https://fr.wikipedia.org/wiki/Tifinagh
32 *
33 * @ingroup Languages
34 */
35class ZghConverter extends LanguageConverterSpecific {
36    /**
37     * The Tifinagh alphabet sequence is based on
38     * "Dictionnaire Général de la Langue Amazighe Informatisé"
39     * by IRCAM (https://tal.ircam.ma/dglai/lexieam.php, DGLAi),
40     * with the labio-velarization mark in the end.
41     */
42    private const TO_LATIN = [
43        'ⴰ' => 'a',
44        'ⴱ' => 'b',
45        'ⴳ' => 'g',
46        'ⴷ' => 'd',
47        'ⴹ' => 'ḍ',
48        'ⴻ' => 'e',
49        'ⴼ' => 'f',
50        'ⴽ' => 'k',
51        'ⵀ' => 'h',
52        'ⵃ' => 'ḥ',
53        'ⵄ' => 'ɛ',
54        'ⵅ' => 'x',
55        'ⵇ' => 'q',
56        'ⵉ' => 'i',
57        'ⵊ' => 'j',
58        'ⵍ' => 'l',
59        'ⵎ' => 'm',
60        'ⵏ' => 'n',
61        'ⵓ' => 'u',
62        'ⵔ' => 'r',
63        'ⵕ' => 'ṛ',
64        'ⵖ' => 'ɣ',
65        'ⵙ' => 's',
66        'ⵚ' => 'ṣ',
67        'ⵛ' => 'c',
68        'ⵜ' => 't',
69        'ⵟ' => 'ṭ',
70        'ⵡ' => 'w',
71        'ⵢ' => 'y',
72        'ⵣ' => 'z',
73        'ⵥ' => 'ẓ',
74        'ⵯ' => 'ʷ',
75    ];
76
77    public function getMainCode(): string {
78        return 'zgh';
79    }
80
81    public function getLanguageVariants(): array {
82        return [ 'zgh', 'zgh-latn' ];
83    }
84
85    public function getVariantsFallbacks(): array {
86        return [];
87    }
88
89    protected function loadDefaultTables(): array {
90        return [
91            'zgh-latn' => new ReplacementArray( self::TO_LATIN ),
92            'zgh' => new ReplacementArray()
93        ];
94    }
95
96    public function translate( $text, $toVariant ) {
97        // We only convert zgh (zgh-Tfng) to zgh-Latn, not the
98        // other way around. We also don't need to try to
99        // convert if there is no text.
100        if ( $toVariant === 'zgh' || !trim( $text ) ) {
101            return $text;
102        }
103
104        $this->loadTables();
105        $text = $this->mTables[$toVariant]->replace( $text );
106        return $text;
107    }
108}