summaryrefslogtreecommitdiff
path: root/languages/classes/LanguageIu.php
blob: c6221dee24bec030735d7c444a9bbfbf6feab47d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/**
  * @addtogroup Language
  */

/*
* Conversion script between Latin and Syllabics for Inuktitut.
* - Syllabics -> lowercase Latin
* - lowercase/uppercase Latin -> Syllabics
* 
*
* Based on:
*   - http://commons.wikimedia.org/wiki/Image:Inuktitut.png
*   - LanguageSr.php
*
* @ingroup Language
*/
require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' );

/**
 *
 */
class IuConverter extends LanguageConverter {
	var $mToLatin = array(
		'ᐦ' => 'h',   'ᐃ' => 'i',    'ᐄ' => 'ii',    'ᐅ' => 'u',    'ᐆ' => 'uu',    'ᐊ' => 'a',    'ᐋ' => 'aa',
		'ᑉ' => 'p',   'ᐱ' => 'pi',   'ᐲ' => 'pii',   'ᐳ' => 'pu',   'ᐴ' => 'puu',   'ᐸ' => 'pa',   'ᐹ' => 'paa',
		'ᑦ' => 't',   'ᑎ' => 'ti',   'ᑏ' => 'tii',   'ᑐ' => 'tu',   'ᑑ' => 'tuu',   'ᑕ' => 'ta',   'ᑖ' => 'taa',
		'ᒃ' => 'k',   'ᑭ' => 'ki',   'ᑮ' => 'kii',   'ᑯ' => 'ku',   'ᑰ' => 'kuu',   'ᑲ' => 'ka',   'ᑳ' => 'kaa',
		'ᖅᒃ' => 'qq', 'ᖅᑭ' => 'qqi', 'ᖅᑮ' => 'qqii', 'ᖅᑯ' => 'qqu', 'ᖅᑰ' => 'ᖅqquu', 'ᖅᑲ' => 'qqa', 'ᖅᑳ' => 'qqaa',
		'ᒡ' => 'g',   'ᒋ' => 'gi',   'ᒌ' => 'gii',   'ᒍ' => 'gu',   'ᒎ' => 'guu',   'ᒐ' => 'ga',   'ᒑ' => 'gaa',
		'ᒻ' => 'm',   'ᒥ' => 'mi',   'ᒦ' => 'mii',   'ᒧ' => 'mu',   'ᒨ' => 'muu',   'ᒪ' => 'ma',   'ᒫ' => 'maa',
		'ᓐ' => 'n',   'ᓂ' => 'ni',  'ᓃ' => 'nii',   'ᓄ' => 'nu',   'ᓅ' => 'nuu',   'ᓇ' => 'na',   'ᓈ' => 'naa',
		'ᔅ' => 's',   'ᓯ' => 'si',   'ᓰ' => 'sii',   'ᓱ' => 'su',   'ᓲ' => 'suu',   'ᓴ' => 'sa',   'ᓵ' => 'saa',
		'ᓪ' => 'l',   'ᓕ' => 'li',  'ᓖ' => 'lii',   'ᓗ' => 'lu',   'ᓘ' => 'luu',   'ᓚ' => 'la',   'ᓛ' => 'laa',
		'ᔾ' => 'j',   'ᔨ' => 'ji',   'ᔩ' => 'jii',   'ᔪ' => 'ju',   'ᔫ' => 'juu',   'ᔭ' => 'ja',   'ᔮ' => 'jaa',
		'ᕝ' => 'v',   'ᕕ' => 'vi',   'ᕖ' => 'vii',   'ᕗ' => 'vu',   'ᕘ' => 'vuu',   'ᕙ' => 'va',   'ᕚ' => 'vaa',
		'ᕐ' => 'r',   'ᕆ' => 'ri',   'ᕇ' => 'rii',   'ᕈ' => 'ru',   'ᕉ' => 'ruu',   'ᕋ' => 'ra',   'ᕌ' => 'raa',
		'ᖅ' => 'q',   'ᕿ' => 'qi',   'ᖀ' => 'qii',   'ᖁ' => 'qu',   'ᖂ' => 'quu',   'ᖃ' => 'qa',   'ᖄ' => 'qaa',
		'ᖕ' => 'ng',  'ᖏ' => 'ngi',  'ᖐ' => 'ngii',  'ᖑ' => 'ngu',  'ᖒ' => 'nguu',  'ᖓ' => 'nga',  'ᖔ' => 'ngaa',
		'ᖖ' => 'nng', 'ᙱ' => 'nngi', 'ᙲ' => 'nngii', 'ᙳ' => 'nngu', 'ᙴ' => 'nnguu', 'ᙵ' => 'nnga', 'ᙶ' => 'nngaa',
		'ᖦ' => 'ɫ',   'ᖠ' => 'ɫi',    'ᖡ' => 'ɫii',   'ᖢ' => 'ɫu',    'ᖣ' => 'ɫuu',   'ᖤ' => 'ɫa',    'ᖥ' => 'ɫaa',
	);

	var $mUpperToLowerCaseLatin = array(
		'A' => 'a',	'B' => 'b',	'C' => 'c',	'D' => 'd',	'E' => 'e',
		'F' => 'f',	'G' => 'g',	'H' => 'h',	'I' => 'i',	'J' => 'j',
		'K' => 'k',	'L' => 'l',	'M' => 'm',	'N' => 'n',	'O' => 'o',
		'P' => 'p',	'Q' => 'q',	'R' => 'r',	'S' => 's',	'T' => 't',
		'U' => 'u',	'V' => 'v',	'W' => 'w',	'X' => 'x',	'Y' => 'y',
		'Z' => 'z',
	);

	var $mToSyllabics = array(
		'h' => 'ᐦ',   'i' => 'ᐃ',    'ii' => 'ᐄ',    'u' => 'ᐅ',    'uu' => 'ᐆ',    'a' => 'ᐊ',    'aa' => 'ᐋ',
		'p' => 'ᑉ',   'pi' => 'ᐱ',   'pii' => 'ᐲ',   'pu' => 'ᐳ',   'puu' => 'ᐴ',   'pa' => 'ᐸ',   'paa' => 'ᐹ',
		't' => 'ᑦ',   'ti' => 'ᑎ',   'tii' => 'ᑏ',   'tu' => 'ᑐ',   'tuu' => 'ᑑ',   'ta' => 'ᑕ',   'taa' => 'ᑖ',
		'k' => 'ᒃ',   'ki' => 'ᑭ',   'kii' => 'ᑮ',   'ku' => 'ᑯ',   'kuu' => 'ᑰ',   'ka' => 'ᑲ',   'kaa' => 'ᑳ',
		'g' => 'ᒡ',   'gi' => 'ᒋ',   'gii' => 'ᒌ',   'gu' => 'ᒍ',   'guu' => 'ᒎ',   'ga' => 'ᒐ',   'gaa' => 'ᒑ',
		'm' => 'ᒻ',   'mi' => 'ᒥ',   'mii' => 'ᒦ',   'mu' => 'ᒧ',   'muu' => 'ᒨ',   'ma' => 'ᒪ',   'maa' => 'ᒫ',
		'n' => 'ᓐ',   'ni' => 'ᓂ',   'nii' => 'ᓃ',   'nu' => 'ᓄ',   'nuu' => 'ᓅ',   'na' => 'ᓇ',   'naa' => 'ᓈ',
		's' => 'ᔅ',   'si' => 'ᓯ',   'sii' => 'ᓰ',   'su' => 'ᓱ',   'suu' => 'ᓲ',   'sa' => 'ᓴ',   'saa' => 'ᓵ',
		'l' => 'ᓪ',   'li' => 'ᓕ',   'lii' => 'ᓖ',   'lu' => 'ᓗ',   'luu' => 'ᓘ',   'la' => 'ᓚ',   'laa' => 'ᓛ',
		'j' => 'ᔾ',   'ji' => 'ᔨ',   'jii' => 'ᔩ',   'ju' => 'ᔪ',   'juu' => 'ᔫ',   'ja' => 'ᔭ',   'jaa' => 'ᔮ',
		'v' => 'ᕝ',   'vi' => 'ᕕ',   'vii' => 'ᕖ',   'vu' => 'ᕗ',   'vuu' => 'ᕘ',   'va' => 'ᕙ',   'vaa' => 'ᕚ',
		'r' => 'ᕐ',   'ri' => 'ᕆ',   'rii' => 'ᕇ',   'ru' => 'ᕈ',   'ruu' => 'ᕉ',   'ra' => 'ᕋ',   'raa' => 'ᕌ',
		'qq' => 'ᖅᒃ',  'qqi' => 'ᖅᑭ',  'qqii' => 'ᖅᑮ',  'qqu' => 'ᖅᑯ',  'qquu' => 'ᖅᑰ',  'qqa' => 'ᖅᑲ',  'qqaa' => 'ᖅᑳ',
		'q' => 'ᖅ',   'qi' => 'ᕿ',   'qii' => 'ᖀ',   'qu' => 'ᖁ',   'quu' => 'ᖂ',   'qa' => 'ᖃ',   'qaa' => 'ᖄ',
		'ng' => 'ᖕ',  'ngi' => 'ᖏ',  'ngii' => 'ᖐ',  'ngu' => 'ᖑ',  'nguu' => 'ᖒ',  'nga' => 'ᖓ',  'ngaa' => 'ᖔ',
		'nng' => 'ᖖ', 'nngi' => 'ᙱ', 'nngii' => 'ᙲ', 'nngu' => 'ᙳ', 'nnguu' => 'ᙴ', 'nnga' => 'ᙵ', 'nngaa' => 'ᙶ',
		'ɫ' => 'ᖦ',   'ɫi' => 'ᖠ',    'ɫii' => 'ᖡ',   'ɫu' => 'ᖢ',    'ɫuu' => 'ᖣ',   'ɫa' => 'ᖤ',    'ɫaa' => 'ᖥ',
	);

	function loadDefaultTables() {
		$this->mTables = array(
			'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
			'ike-cans' => new ReplacementArray( $this->mToSyllabics ),
			'ike-latn' => new ReplacementArray( $this->mToLatin ),
			'iu'    => new ReplacementArray()
		);
	}

	/**
	 * rules should be defined as -{Syllabic | Latin-} -or-
	 * -{code:text | code:text | ...}-
	 * update: delete all rule parsing because it's not used
	 * currently, and just produces a couple of bugs
	 *
	 * @param $rule string
	 * @param $flags array
	 * @return array
	 */
	function parseManualRule( $rule, $flags = array() ) {
		if ( in_array( 'T', $flags ) ) {
			return parent::parseManualRule( $rule, $flags );
		}

		$carray = array();
		// otherwise ignore all formatting
		foreach ( $this->mVariants as $v ) {
			$carray[$v] = $rule;
		}

		return $carray;
	}

	/**
	 * Do not convert content on talk pages
	 *
	 * @param $text string
	 * @param $parser Parser
	 * @return string
	 */
	function parserConvert( $text, &$parser ) {
		if ( is_object( $parser->getTitle() ) && $parser->getTitle()->isTalkPage() )
			$this->mDoContentConvert = false;
		else
			$this->mDoContentConvert = true;

		return parent::parserConvert( $text, $parser );
	}

	/**
	 * A function wrapper:
	 *   - if there is no selected variant, leave the link
	 *     names as they were
	 *   - do not try to find variants for usernames
	 *
	 * @param $link string
	 * @param $nt Title
	 * @param $ignoreOtherCond bool
	 */
	function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
		 // check for user namespace
		if ( is_object( $nt ) ) {
			$ns = $nt->getNamespace();
			if ( $ns == NS_USER || $ns == NS_USER_TALK )
				return;
		}

		$oldlink = $link;
		parent::findVariantLink( $link, $nt, $ignoreOtherCond );
		if ( $this->getPreferredVariant() == $this->mMainLanguageCode )
			$link = $oldlink;
	}

	/**
	 * We want our external link captions to be converted in variants,
	 * so we return the original text instead -{$text}-, except for URLs
	 *
	 * @param $text string
	 * @param $noParse bool
	 *
	 * @return string
	 */
	function markNoConversion( $text, $noParse = false ) {
		if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) )
			return parent::markNoConversion( $text );
		return $text;
	}

	/**
	 * An ugly function wrapper for parsing Image titles
	 * (to prevent image name conversion)
	 *
	 * @param $text string
	 * @param $toVariant bool
	 *
	 * @return string
	 */
	function autoConvert( $text, $toVariant = false ) {
		global $wgTitle;
		if ( is_object( $wgTitle ) && $wgTitle->getNameSpace() == NS_FILE ) {
			$imagename = $wgTitle->getNsText();
			if ( preg_match( "/^$imagename:/", $text ) ) return $text;
		}
		return parent::autoConvert( $text, $toVariant );
	}

	/**
	 * It translates text into variant
	 *
	 * @param $text string
	 * @param $toVariant bool
	 *
	 * @return string
	 */
	function translate( $text, $toVariant ) {
		// If $text is empty or only includes spaces, do nothing
		// Otherwise translate it
		if ( trim( $text ) ) {
			$this->loadTables();
			// To syllabics, first translate uppercase to lowercase Latin
			if($toVariant == 'ike-cans') {
				$text = $this->mTables['lowercase']->replace( $text );
			}
			$text = $this->mTables[$toVariant]->replace( $text );
		}
		return $text;
	}
}

/**
 * Inuktitut
 *
 * @ingroup Language
 */
class LanguageIu extends Language {
	function __construct() {
		global $wgHooks;

		parent::__construct();

		$variants = array( 'iu', 'ike-cans', 'ike-latn' );
		$variantfallbacks = array(
			'iu'    => 'ike-cans',
			'ike-cans' => 'iu',
			'ike-latn' => 'iu',
		);

		$flags = array();
		$this->mConverter = new IuConverter( $this, 'iu', $variants, $variantfallbacks, $flags );
		$wgHooks['ArticleSaveComplete'][] = $this->mConverter;
	}
}