Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / languages / classes / LanguageIu.php
blob4c956f011ac6d88b7f4cf8327e5d3f760a61bea2
1 <?php
2 /**
3 * Inuktitut specific code.
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.
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.
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
20 * @file
21 * @ingroup Language
24 require_once __DIR__ . '/../LanguageConverter.php';
26 /**
27 * Conversion script between Latin and Syllabics for Inuktitut.
28 * - Syllabics -> lowercase Latin
29 * - lowercase/uppercase Latin -> Syllabics
32 * Based on:
33 * - http://commons.wikimedia.org/wiki/Image:Inuktitut.png
34 * - LanguageSr.php
36 * @ingroup Language
38 class IuConverter extends LanguageConverter {
39 protected $mDoContentConvert;
41 public $mToLatin = array(
42 'ᐦ' => 'h', 'ᐃ' => 'i', 'ᐄ' => 'ii', 'ᐅ' => 'u', 'ᐆ' => 'uu', 'ᐊ' => 'a', 'ᐋ' => 'aa',
43 'ᑉ' => 'p', 'ᐱ' => 'pi', 'ᐲ' => 'pii', 'ᐳ' => 'pu', 'ᐴ' => 'puu', 'ᐸ' => 'pa', 'ᐹ' => 'paa',
44 'ᑦ' => 't', 'ᑎ' => 'ti', 'ᑏ' => 'tii', 'ᑐ' => 'tu', 'ᑑ' => 'tuu', 'ᑕ' => 'ta', 'ᑖ' => 'taa',
45 'ᒃ' => 'k', 'ᑭ' => 'ki', 'ᑮ' => 'kii', 'ᑯ' => 'ku', 'ᑰ' => 'kuu', 'ᑲ' => 'ka', 'ᑳ' => 'kaa',
46 'ᖅᒃ' => 'qq', 'ᖅᑭ' => 'qqi', 'ᖅᑮ' => 'qqii', 'ᖅᑯ' => 'qqu', 'ᖅᑰ' => 'ᖅqquu', 'ᖅᑲ' => 'qqa',
47 'ᖅᑳ' => 'qqaa', 'ᒡ' => 'g', 'ᒋ' => 'gi', 'ᒌ' => 'gii', 'ᒍ' => 'gu', 'ᒎ' => 'guu',
48 'ᒐ' => 'ga', 'ᒑ' => 'gaa', 'ᒻ' => 'm', 'ᒥ' => 'mi', 'ᒦ' => 'mii', 'ᒧ' => 'mu', 'ᒨ' => 'muu',
49 'ᒪ' => 'ma', 'ᒫ' => 'maa', 'ᓐ' => 'n', 'ᓂ' => 'ni', 'ᓃ' => 'nii', 'ᓄ' => 'nu', 'ᓅ' => 'nuu',
50 'ᓇ' => 'na', 'ᓈ' => 'naa', 'ᔅ' => 's', 'ᓯ' => 'si', 'ᓰ' => 'sii', 'ᓱ' => 'su', 'ᓲ' => 'suu',
51 'ᓴ' => 'sa', 'ᓵ' => 'saa', 'ᓪ' => 'l', 'ᓕ' => 'li', 'ᓖ' => 'lii', 'ᓗ' => 'lu', 'ᓘ' => 'luu',
52 'ᓚ' => 'la', 'ᓛ' => 'laa', 'ᔾ' => 'j', 'ᔨ' => 'ji', 'ᔩ' => 'jii', 'ᔪ' => 'ju', 'ᔫ' => 'juu',
53 'ᔭ' => 'ja', 'ᔮ' => 'jaa', 'ᕝ' => 'v', 'ᕕ' => 'vi', 'ᕖ' => 'vii', 'ᕗ' => 'vu', 'ᕘ' => 'vuu',
54 'ᕙ' => 'va', 'ᕚ' => 'vaa', 'ᕐ' => 'r', 'ᕆ' => 'ri', 'ᕇ' => 'rii', 'ᕈ' => 'ru', 'ᕉ' => 'ruu',
55 'ᕋ' => 'ra', 'ᕌ' => 'raa', 'ᖅ' => 'q', 'ᕿ' => 'qi', 'ᖀ' => 'qii', 'ᖁ' => 'qu', 'ᖂ' => 'quu',
56 'ᖃ' => 'qa', 'ᖄ' => 'qaa', 'ᖕ' => 'ng', 'ᖏ' => 'ngi', 'ᖐ' => 'ngii', 'ᖑ' => 'ngu',
57 'ᖒ' => 'nguu', 'ᖓ' => 'nga', 'ᖔ' => 'ngaa', 'ᖖ' => 'nng', 'ᙱ' => 'nngi', 'ᙲ' => 'nngii',
58 'ᙳ' => 'nngu', 'ᙴ' => 'nnguu', 'ᙵ' => 'nnga', 'ᙶ' => 'nngaa', 'ᖦ' => 'ɫ', 'ᖠ' => 'ɫi',
59 'ᖡ' => 'ɫii', 'ᖢ' => 'ɫu', 'ᖣ' => 'ɫuu', 'ᖤ' => 'ɫa', 'ᖥ' => 'ɫaa',
62 public $mUpperToLowerCaseLatin = array(
63 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
64 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
65 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
66 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
67 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
68 'Z' => 'z',
71 public $mToSyllabics = array(
72 'h' => 'ᐦ', 'i' => 'ᐃ', 'ii' => 'ᐄ', 'u' => 'ᐅ', 'uu' => 'ᐆ', 'a' => 'ᐊ', 'aa' => 'ᐋ',
73 'p' => 'ᑉ', 'pi' => 'ᐱ', 'pii' => 'ᐲ', 'pu' => 'ᐳ', 'puu' => 'ᐴ', 'pa' => 'ᐸ', 'paa' => 'ᐹ',
74 't' => 'ᑦ', 'ti' => 'ᑎ', 'tii' => 'ᑏ', 'tu' => 'ᑐ', 'tuu' => 'ᑑ', 'ta' => 'ᑕ', 'taa' => 'ᑖ',
75 'k' => 'ᒃ', 'ki' => 'ᑭ', 'kii' => 'ᑮ', 'ku' => 'ᑯ', 'kuu' => 'ᑰ', 'ka' => 'ᑲ', 'kaa' => 'ᑳ',
76 'g' => 'ᒡ', 'gi' => 'ᒋ', 'gii' => 'ᒌ', 'gu' => 'ᒍ', 'guu' => 'ᒎ', 'ga' => 'ᒐ', 'gaa' => 'ᒑ',
77 'm' => 'ᒻ', 'mi' => 'ᒥ', 'mii' => 'ᒦ', 'mu' => 'ᒧ', 'muu' => 'ᒨ', 'ma' => 'ᒪ', 'maa' => 'ᒫ',
78 'n' => 'ᓐ', 'ni' => 'ᓂ', 'nii' => 'ᓃ', 'nu' => 'ᓄ', 'nuu' => 'ᓅ', 'na' => 'ᓇ', 'naa' => 'ᓈ',
79 's' => 'ᔅ', 'si' => 'ᓯ', 'sii' => 'ᓰ', 'su' => 'ᓱ', 'suu' => 'ᓲ', 'sa' => 'ᓴ', 'saa' => 'ᓵ',
80 'l' => 'ᓪ', 'li' => 'ᓕ', 'lii' => 'ᓖ', 'lu' => 'ᓗ', 'luu' => 'ᓘ', 'la' => 'ᓚ', 'laa' => 'ᓛ',
81 'j' => 'ᔾ', 'ji' => 'ᔨ', 'jii' => 'ᔩ', 'ju' => 'ᔪ', 'juu' => 'ᔫ', 'ja' => 'ᔭ', 'jaa' => 'ᔮ',
82 'v' => 'ᕝ', 'vi' => 'ᕕ', 'vii' => 'ᕖ', 'vu' => 'ᕗ', 'vuu' => 'ᕘ', 'va' => 'ᕙ', 'vaa' => 'ᕚ',
83 'r' => 'ᕐ', 'ri' => 'ᕆ', 'rii' => 'ᕇ', 'ru' => 'ᕈ', 'ruu' => 'ᕉ', 'ra' => 'ᕋ', 'raa' => 'ᕌ',
84 'qq' => 'ᖅᒃ', 'qqi' => 'ᖅᑭ', 'qqii' => 'ᖅᑮ', 'qqu' => 'ᖅᑯ', 'qquu' => 'ᖅᑰ', 'qqa' => 'ᖅᑲ',
85 'qqaa' => 'ᖅᑳ', 'q' => 'ᖅ', 'qi' => 'ᕿ', 'qii' => 'ᖀ', 'qu' => 'ᖁ', 'quu' => 'ᖂ',
86 'qa' => 'ᖃ', 'qaa' => 'ᖄ', 'ng' => 'ᖕ', 'ngi' => 'ᖏ', 'ngii' => 'ᖐ', 'ngu' => 'ᖑ',
87 'nguu' => 'ᖒ', 'nga' => 'ᖓ', 'ngaa' => 'ᖔ', 'nng' => 'ᖖ', 'nngi' => 'ᙱ', 'nngii' => 'ᙲ',
88 'nngu' => 'ᙳ', 'nnguu' => 'ᙴ', 'nnga' => 'ᙵ', 'nngaa' => 'ᙶ', 'ɫ' => 'ᖦ', 'ɫi' => 'ᖠ',
89 'ɫii' => 'ᖡ', 'ɫu' => 'ᖢ', 'ɫuu' => 'ᖣ', 'ɫa' => 'ᖤ', 'ɫaa' => 'ᖥ',
92 function loadDefaultTables() {
93 $this->mTables = array(
94 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
95 'ike-cans' => new ReplacementArray( $this->mToSyllabics ),
96 'ike-latn' => new ReplacementArray( $this->mToLatin ),
97 'iu' => new ReplacementArray()
102 * rules should be defined as -{Syllabic | Latin-} -or-
103 * -{code:text | code:text | ...}-
104 * update: delete all rule parsing because it's not used
105 * currently, and just produces a couple of bugs
107 * @param string $rule
108 * @param array $flags
109 * @return array
111 function parseManualRule( $rule, $flags = array() ) {
112 if ( in_array( 'T', $flags ) ) {
113 return parent::parseManualRule( $rule, $flags );
116 $carray = array();
117 // otherwise ignore all formatting
118 foreach ( $this->mVariants as $v ) {
119 $carray[$v] = $rule;
122 return $carray;
126 * Do not convert content on talk pages
128 * @param string $text
129 * @param Parser $parser
130 * @return string
132 function parserConvert( $text, &$parser ) {
133 $this->mDoContentConvert = !( is_object( $parser->getTitle() )
134 && $parser->getTitle()->isTalkPage() );
136 return parent::parserConvert( $text, $parser );
140 * A function wrapper:
141 * - if there is no selected variant, leave the link
142 * names as they were
143 * - do not try to find variants for usernames
145 * @param string $link
146 * @param Title $nt
147 * @param bool $ignoreOtherCond
149 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
150 // check for user namespace
151 if ( is_object( $nt ) ) {
152 $ns = $nt->getNamespace();
153 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
154 return;
158 $oldlink = $link;
159 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
160 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
161 $link = $oldlink;
166 * An ugly function wrapper for parsing Image titles
167 * (to prevent image name conversion)
169 * @param string $text
170 * @param bool $toVariant
172 * @return string
174 function autoConvert( $text, $toVariant = false ) {
175 global $wgTitle;
176 if ( is_object( $wgTitle ) && $wgTitle->getNamespace() == NS_FILE ) {
177 $imagename = $wgTitle->getNsText();
178 if ( preg_match( "/^$imagename:/", $text ) ) {
179 return $text;
182 return parent::autoConvert( $text, $toVariant );
186 * It translates text into variant
188 * @param string $text
189 * @param bool $toVariant
191 * @return string
193 function translate( $text, $toVariant ) {
194 // If $text is empty or only includes spaces, do nothing
195 // Otherwise translate it
196 if ( trim( $text ) ) {
197 $this->loadTables();
198 // To syllabics, first translate uppercase to lowercase Latin
199 if ( $toVariant == 'ike-cans' ) {
200 $text = $this->mTables['lowercase']->replace( $text );
202 $text = $this->mTables[$toVariant]->replace( $text );
204 return $text;
209 * Inuktitut
211 * @ingroup Language
213 class LanguageIu extends Language {
214 function __construct() {
215 global $wgHooks;
217 parent::__construct();
219 $variants = array( 'iu', 'ike-cans', 'ike-latn' );
220 $variantfallbacks = array(
221 'iu' => 'ike-cans',
222 'ike-cans' => 'iu',
223 'ike-latn' => 'iu',
226 $flags = array();
227 $this->mConverter = new IuConverter( $this, 'iu', $variants, $variantfallbacks, $flags );
228 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;