Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / languages / classes / LanguageIu.php
1 <?php
2 /**
3 * Inuktitut specific code.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Language
22 */
23
24 /**
25 * Conversion script between Latin and Syllabics for Inuktitut.
26 * - Syllabics -> lowercase Latin
27 * - lowercase/uppercase Latin -> Syllabics
28 *
29 *
30 * Based on:
31 * - https://commons.wikimedia.org/wiki/Image:Inuktitut.png
32 * - LanguageSr.php
33 *
34 * @ingroup Language
35 */
36 class IuConverter extends LanguageConverter {
37 protected $mDoContentConvert;
38
39 public $mToLatin = [
40 'ᐦ' => 'h', 'ᐃ' => 'i', 'ᐄ' => 'ii', 'ᐅ' => 'u', 'ᐆ' => 'uu', 'ᐊ' => 'a', 'ᐋ' => 'aa',
41 'ᑉ' => 'p', 'ᐱ' => 'pi', 'ᐲ' => 'pii', 'ᐳ' => 'pu', 'ᐴ' => 'puu', 'ᐸ' => 'pa', 'ᐹ' => 'paa',
42 'ᑦ' => 't', 'ᑎ' => 'ti', 'ᑏ' => 'tii', 'ᑐ' => 'tu', 'ᑑ' => 'tuu', 'ᑕ' => 'ta', 'ᑖ' => 'taa',
43 'ᒃ' => 'k', 'ᑭ' => 'ki', 'ᑮ' => 'kii', 'ᑯ' => 'ku', 'ᑰ' => 'kuu', 'ᑲ' => 'ka', 'ᑳ' => 'kaa',
44 'ᖅᒃ' => 'qq', 'ᖅᑭ' => 'qqi', 'ᖅᑮ' => 'qqii', 'ᖅᑯ' => 'qqu', 'ᖅᑰ' => 'ᖅqquu', 'ᖅᑲ' => 'qqa',
45 'ᖅᑳ' => 'qqaa', 'ᒡ' => 'g', 'ᒋ' => 'gi', 'ᒌ' => 'gii', 'ᒍ' => 'gu', 'ᒎ' => 'guu',
46 'ᒐ' => 'ga', 'ᒑ' => 'gaa', 'ᒻ' => 'm', 'ᒥ' => 'mi', 'ᒦ' => 'mii', 'ᒧ' => 'mu', 'ᒨ' => 'muu',
47 'ᒪ' => 'ma', 'ᒫ' => 'maa', 'ᓐ' => 'n', 'ᓂ' => 'ni', 'ᓃ' => 'nii', 'ᓄ' => 'nu', 'ᓅ' => 'nuu',
48 'ᓇ' => 'na', 'ᓈ' => 'naa', 'ᔅ' => 's', 'ᓯ' => 'si', 'ᓰ' => 'sii', 'ᓱ' => 'su', 'ᓲ' => 'suu',
49 'ᓴ' => 'sa', 'ᓵ' => 'saa', 'ᓪ' => 'l', 'ᓕ' => 'li', 'ᓖ' => 'lii', 'ᓗ' => 'lu', 'ᓘ' => 'luu',
50 'ᓚ' => 'la', 'ᓛ' => 'laa', 'ᔾ' => 'j', 'ᔨ' => 'ji', 'ᔩ' => 'jii', 'ᔪ' => 'ju', 'ᔫ' => 'juu',
51 'ᔭ' => 'ja', 'ᔮ' => 'jaa', 'ᕝ' => 'v', 'ᕕ' => 'vi', 'ᕖ' => 'vii', 'ᕗ' => 'vu', 'ᕘ' => 'vuu',
52 'ᕙ' => 'va', 'ᕚ' => 'vaa', 'ᕐ' => 'r', 'ᕆ' => 'ri', 'ᕇ' => 'rii', 'ᕈ' => 'ru', 'ᕉ' => 'ruu',
53 'ᕋ' => 'ra', 'ᕌ' => 'raa', 'ᖅ' => 'q', 'ᕿ' => 'qi', 'ᖀ' => 'qii', 'ᖁ' => 'qu', 'ᖂ' => 'quu',
54 'ᖃ' => 'qa', 'ᖄ' => 'qaa', 'ᖕ' => 'ng', 'ᖏ' => 'ngi', 'ᖐ' => 'ngii', 'ᖑ' => 'ngu',
55 'ᖒ' => 'nguu', 'ᖓ' => 'nga', 'ᖔ' => 'ngaa', 'ᖖ' => 'nng', 'ᙱ' => 'nngi', 'ᙲ' => 'nngii',
56 'ᙳ' => 'nngu', 'ᙴ' => 'nnguu', 'ᙵ' => 'nnga', 'ᙶ' => 'nngaa', 'ᖦ' => 'ɫ', 'ᖠ' => 'ɫi',
57 'ᖡ' => 'ɫii', 'ᖢ' => 'ɫu', 'ᖣ' => 'ɫuu', 'ᖤ' => 'ɫa', 'ᖥ' => 'ɫaa',
58 ];
59
60 public $mUpperToLowerCaseLatin = [
61 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
62 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
63 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
64 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
65 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
66 'Z' => 'z',
67 ];
68
69 public $mToSyllabics = [
70 'h' => 'ᐦ', 'i' => 'ᐃ', 'ii' => 'ᐄ', 'u' => 'ᐅ', 'uu' => 'ᐆ', 'a' => 'ᐊ', 'aa' => 'ᐋ',
71 'p' => 'ᑉ', 'pi' => 'ᐱ', 'pii' => 'ᐲ', 'pu' => 'ᐳ', 'puu' => 'ᐴ', 'pa' => 'ᐸ', 'paa' => 'ᐹ',
72 't' => 'ᑦ', 'ti' => 'ᑎ', 'tii' => 'ᑏ', 'tu' => 'ᑐ', 'tuu' => 'ᑑ', 'ta' => 'ᑕ', 'taa' => 'ᑖ',
73 'k' => 'ᒃ', 'ki' => 'ᑭ', 'kii' => 'ᑮ', 'ku' => 'ᑯ', 'kuu' => 'ᑰ', 'ka' => 'ᑲ', 'kaa' => 'ᑳ',
74 'g' => 'ᒡ', 'gi' => 'ᒋ', 'gii' => 'ᒌ', 'gu' => 'ᒍ', 'guu' => 'ᒎ', 'ga' => 'ᒐ', 'gaa' => 'ᒑ',
75 'm' => 'ᒻ', 'mi' => 'ᒥ', 'mii' => 'ᒦ', 'mu' => 'ᒧ', 'muu' => 'ᒨ', 'ma' => 'ᒪ', 'maa' => 'ᒫ',
76 'n' => 'ᓐ', 'ni' => 'ᓂ', 'nii' => 'ᓃ', 'nu' => 'ᓄ', 'nuu' => 'ᓅ', 'na' => 'ᓇ', 'naa' => 'ᓈ',
77 's' => 'ᔅ', 'si' => 'ᓯ', 'sii' => 'ᓰ', 'su' => 'ᓱ', 'suu' => 'ᓲ', 'sa' => 'ᓴ', 'saa' => 'ᓵ',
78 'l' => 'ᓪ', 'li' => 'ᓕ', 'lii' => 'ᓖ', 'lu' => 'ᓗ', 'luu' => 'ᓘ', 'la' => 'ᓚ', 'laa' => 'ᓛ',
79 'j' => 'ᔾ', 'ji' => 'ᔨ', 'jii' => 'ᔩ', 'ju' => 'ᔪ', 'juu' => 'ᔫ', 'ja' => 'ᔭ', 'jaa' => 'ᔮ',
80 'v' => 'ᕝ', 'vi' => 'ᕕ', 'vii' => 'ᕖ', 'vu' => 'ᕗ', 'vuu' => 'ᕘ', 'va' => 'ᕙ', 'vaa' => 'ᕚ',
81 'r' => 'ᕐ', 'ri' => 'ᕆ', 'rii' => 'ᕇ', 'ru' => 'ᕈ', 'ruu' => 'ᕉ', 'ra' => 'ᕋ', 'raa' => 'ᕌ',
82 'qq' => 'ᖅᒃ', 'qqi' => 'ᖅᑭ', 'qqii' => 'ᖅᑮ', 'qqu' => 'ᖅᑯ', 'qquu' => 'ᖅᑰ', 'qqa' => 'ᖅᑲ',
83 'qqaa' => 'ᖅᑳ', 'q' => 'ᖅ', 'qi' => 'ᕿ', 'qii' => 'ᖀ', 'qu' => 'ᖁ', 'quu' => 'ᖂ',
84 'qa' => 'ᖃ', 'qaa' => 'ᖄ', 'ng' => 'ᖕ', 'ngi' => 'ᖏ', 'ngii' => 'ᖐ', 'ngu' => 'ᖑ',
85 'nguu' => 'ᖒ', 'nga' => 'ᖓ', 'ngaa' => 'ᖔ', 'nng' => 'ᖖ', 'nngi' => 'ᙱ', 'nngii' => 'ᙲ',
86 'nngu' => 'ᙳ', 'nnguu' => 'ᙴ', 'nnga' => 'ᙵ', 'nngaa' => 'ᙶ', 'ɫ' => 'ᖦ', 'ɫi' => 'ᖠ',
87 'ɫii' => 'ᖡ', 'ɫu' => 'ᖢ', 'ɫuu' => 'ᖣ', 'ɫa' => 'ᖤ', 'ɫaa' => 'ᖥ',
88 ];
89
90 function loadDefaultTables() {
91 $this->mTables = [
92 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
93 'ike-cans' => new ReplacementArray( $this->mToSyllabics ),
94 'ike-latn' => new ReplacementArray( $this->mToLatin ),
95 'iu' => new ReplacementArray()
96 ];
97 }
98
99 /**
100 * rules should be defined as -{Syllabic | Latin-} -or-
101 * -{code:text | code:text | ...}-
102 * update: delete all rule parsing because it's not used
103 * currently, and just produces a couple of bugs
104 *
105 * @param string $rule
106 * @param array $flags
107 * @return array
108 */
109 function parseManualRule( $rule, $flags = [] ) {
110 if ( in_array( 'T', $flags ) ) {
111 return parent::parseManualRule( $rule, $flags );
112 }
113
114 $carray = [];
115 // otherwise ignore all formatting
116 foreach ( $this->mVariants as $v ) {
117 $carray[$v] = $rule;
118 }
119
120 return $carray;
121 }
122
123 /**
124 * Do not convert content on talk pages
125 *
126 * @param string $text
127 * @param Parser $parser
128 * @return string
129 */
130 function parserConvert( $text, &$parser ) {
131 $this->mDoContentConvert = !( is_object( $parser->getTitle() )
132 && $parser->getTitle()->isTalkPage() );
133
134 return parent::parserConvert( $text, $parser );
135 }
136
137 /**
138 * A function wrapper:
139 * - if there is no selected variant, leave the link
140 * names as they were
141 * - do not try to find variants for usernames
142 *
143 * @param string &$link
144 * @param Title &$nt
145 * @param bool $ignoreOtherCond
146 */
147 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
148 // check for user namespace
149 if ( is_object( $nt ) ) {
150 $ns = $nt->getNamespace();
151 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
152 return;
153 }
154 }
155
156 $oldlink = $link;
157 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
158 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
159 $link = $oldlink;
160 }
161 }
162
163 /**
164 * It translates text into variant
165 *
166 * @param string $text
167 * @param bool $toVariant
168 *
169 * @return string
170 */
171 function translate( $text, $toVariant ) {
172 // If $text is empty or only includes spaces, do nothing
173 // Otherwise translate it
174 if ( trim( $text ) ) {
175 $this->loadTables();
176 // To syllabics, first translate uppercase to lowercase Latin
177 if ( $toVariant == 'ike-cans' ) {
178 $text = $this->mTables['lowercase']->replace( $text );
179 }
180 $text = $this->mTables[$toVariant]->replace( $text );
181 }
182 return $text;
183 }
184 }
185
186 /**
187 * Inuktitut
188 *
189 * @ingroup Language
190 */
191 class LanguageIu extends Language {
192 function __construct() {
193 parent::__construct();
194
195 $variants = [ 'iu', 'ike-cans', 'ike-latn' ];
196 $variantfallbacks = [
197 'iu' => 'ike-cans',
198 'ike-cans' => 'iu',
199 'ike-latn' => 'iu',
200 ];
201
202 $flags = [];
203 $this->mConverter = new IuConverter( $this, 'iu', $variants, $variantfallbacks, $flags );
204 }
205 }