| 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 | * Standard Moroccan Amazigh specific code. |
| 23 | * |
| 24 | * Conversion script for Tifinagh to lowercase Latin for Standard Moroccan Amazigh. |
| 25 | * |
| 26 | * |
| 27 | * Based on: |
| 28 | * - LanguageShi.php |
| 29 | * - https://fr.wikipedia.org/wiki/Tifinagh |
| 30 | * |
| 31 | * @ingroup Languages |
| 32 | */ |
| 33 | class ZghConverter extends LanguageConverterSpecific { |
| 34 | /** |
| 35 | * The Tifinagh alphabet sequence is based on |
| 36 | * "Dictionnaire Général de la Langue Amazighe Informatisé" |
| 37 | * by IRCAM (https://tal.ircam.ma/dglai/lexieam.php, DGLAi), |
| 38 | * with the labio-velarization mark in the end. |
| 39 | */ |
| 40 | private const TO_LATIN = [ |
| 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 | public function getMainCode(): string { |
| 76 | return 'zgh'; |
| 77 | } |
| 78 | |
| 79 | public function getLanguageVariants(): array { |
| 80 | return [ 'zgh', 'zgh-latn' ]; |
| 81 | } |
| 82 | |
| 83 | public function getVariantsFallbacks(): array { |
| 84 | return []; |
| 85 | } |
| 86 | |
| 87 | protected function loadDefaultTables(): array { |
| 88 | return [ |
| 89 | 'zgh-latn' => new ReplacementArray( self::TO_LATIN ), |
| 90 | 'zgh' => new ReplacementArray() |
| 91 | ]; |
| 92 | } |
| 93 | |
| 94 | public function translate( $text, $toVariant ) { |
| 95 | // We only convert zgh (zgh-Tfng) to zgh-Latn, not the |
| 96 | // other way around. We also don't need to try to |
| 97 | // convert if there is no text. |
| 98 | if ( $toVariant === 'zgh' || !trim( $text ) ) { |
| 99 | return $text; |
| 100 | } |
| 101 | |
| 102 | $this->loadTables(); |
| 103 | $text = $this->mTables[$toVariant]->replace( $text ); |
| 104 | return $text; |
| 105 | } |
| 106 | } |