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
24 require_once( __DIR__
. '/../LanguageConverter.php' );
27 * Conversion script between Latin and Syllabics for Inuktitut.
28 * - Syllabics -> lowercase Latin
29 * - lowercase/uppercase Latin -> Syllabics
33 * - http://commons.wikimedia.org/wiki/Image:Inuktitut.png
38 class IuConverter
extends LanguageConverter
{
40 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', 'ᖅᑳ' => 'qqaa',
47 'ᒡ' => 'g', 'ᒋ' => 'gi', 'ᒌ' => 'gii', 'ᒍ' => 'gu', 'ᒎ' => 'guu', 'ᒐ' => 'ga', 'ᒑ' => 'gaa',
48 'ᒻ' => 'm', 'ᒥ' => 'mi', 'ᒦ' => 'mii', 'ᒧ' => 'mu', 'ᒨ' => 'muu', 'ᒪ' => 'ma', 'ᒫ' => 'maa',
49 'ᓐ' => 'n', 'ᓂ' => 'ni', 'ᓃ' => 'nii', 'ᓄ' => 'nu', 'ᓅ' => 'nuu', 'ᓇ' => 'na', 'ᓈ' => 'naa',
50 'ᔅ' => 's', 'ᓯ' => 'si', 'ᓰ' => 'sii', 'ᓱ' => 'su', 'ᓲ' => 'suu', 'ᓴ' => 'sa', 'ᓵ' => 'saa',
51 'ᓪ' => 'l', 'ᓕ' => 'li', 'ᓖ' => 'lii', 'ᓗ' => 'lu', 'ᓘ' => 'luu', 'ᓚ' => 'la', 'ᓛ' => 'laa',
52 'ᔾ' => 'j', 'ᔨ' => 'ji', 'ᔩ' => 'jii', 'ᔪ' => 'ju', 'ᔫ' => 'juu', 'ᔭ' => 'ja', 'ᔮ' => 'jaa',
53 'ᕝ' => 'v', 'ᕕ' => 'vi', 'ᕖ' => 'vii', 'ᕗ' => 'vu', 'ᕘ' => 'vuu', 'ᕙ' => 'va', 'ᕚ' => 'vaa',
54 'ᕐ' => 'r', 'ᕆ' => 'ri', 'ᕇ' => 'rii', 'ᕈ' => 'ru', 'ᕉ' => 'ruu', 'ᕋ' => 'ra', 'ᕌ' => 'raa',
55 'ᖅ' => 'q', 'ᕿ' => 'qi', 'ᖀ' => 'qii', 'ᖁ' => 'qu', 'ᖂ' => 'quu', 'ᖃ' => 'qa', 'ᖄ' => 'qaa',
56 'ᖕ' => 'ng', 'ᖏ' => 'ngi', 'ᖐ' => 'ngii', 'ᖑ' => 'ngu', 'ᖒ' => 'nguu', 'ᖓ' => 'nga', 'ᖔ' => 'ngaa',
57 'ᖖ' => 'nng', 'ᙱ' => 'nngi', 'ᙲ' => 'nngii', 'ᙳ' => 'nngu', 'ᙴ' => 'nnguu', 'ᙵ' => 'nnga', 'ᙶ' => 'nngaa',
58 'ᖦ' => 'ɫ', 'ᖠ' => 'ɫi', 'ᖡ' => 'ɫii', 'ᖢ' => 'ɫu', 'ᖣ' => 'ɫuu', 'ᖤ' => 'ɫa', 'ᖥ' => 'ɫaa',
61 public $mUpperToLowerCaseLatin = array(
62 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
63 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
64 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
65 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
66 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
70 public $mToSyllabics = array(
71 'h' => 'ᐦ', 'i' => 'ᐃ', 'ii' => 'ᐄ', 'u' => 'ᐅ', 'uu' => 'ᐆ', 'a' => 'ᐊ', 'aa' => 'ᐋ',
72 'p' => 'ᑉ', 'pi' => 'ᐱ', 'pii' => 'ᐲ', 'pu' => 'ᐳ', 'puu' => 'ᐴ', 'pa' => 'ᐸ', 'paa' => 'ᐹ',
73 't' => 'ᑦ', 'ti' => 'ᑎ', 'tii' => 'ᑏ', 'tu' => 'ᑐ', 'tuu' => 'ᑑ', 'ta' => 'ᑕ', 'taa' => 'ᑖ',
74 'k' => 'ᒃ', 'ki' => 'ᑭ', 'kii' => 'ᑮ', 'ku' => 'ᑯ', 'kuu' => 'ᑰ', 'ka' => 'ᑲ', 'kaa' => 'ᑳ',
75 'g' => 'ᒡ', 'gi' => 'ᒋ', 'gii' => 'ᒌ', 'gu' => 'ᒍ', 'guu' => 'ᒎ', 'ga' => 'ᒐ', 'gaa' => 'ᒑ',
76 'm' => 'ᒻ', 'mi' => 'ᒥ', 'mii' => 'ᒦ', 'mu' => 'ᒧ', 'muu' => 'ᒨ', 'ma' => 'ᒪ', 'maa' => 'ᒫ',
77 'n' => 'ᓐ', 'ni' => 'ᓂ', 'nii' => 'ᓃ', 'nu' => 'ᓄ', 'nuu' => 'ᓅ', 'na' => 'ᓇ', 'naa' => 'ᓈ',
78 's' => 'ᔅ', 'si' => 'ᓯ', 'sii' => 'ᓰ', 'su' => 'ᓱ', 'suu' => 'ᓲ', 'sa' => 'ᓴ', 'saa' => 'ᓵ',
79 'l' => 'ᓪ', 'li' => 'ᓕ', 'lii' => 'ᓖ', 'lu' => 'ᓗ', 'luu' => 'ᓘ', 'la' => 'ᓚ', 'laa' => 'ᓛ',
80 'j' => 'ᔾ', 'ji' => 'ᔨ', 'jii' => 'ᔩ', 'ju' => 'ᔪ', 'juu' => 'ᔫ', 'ja' => 'ᔭ', 'jaa' => 'ᔮ',
81 'v' => 'ᕝ', 'vi' => 'ᕕ', 'vii' => 'ᕖ', 'vu' => 'ᕗ', 'vuu' => 'ᕘ', 'va' => 'ᕙ', 'vaa' => 'ᕚ',
82 'r' => 'ᕐ', 'ri' => 'ᕆ', 'rii' => 'ᕇ', 'ru' => 'ᕈ', 'ruu' => 'ᕉ', 'ra' => 'ᕋ', 'raa' => 'ᕌ',
83 'qq' => 'ᖅᒃ', 'qqi' => 'ᖅᑭ', 'qqii' => 'ᖅᑮ', 'qqu' => 'ᖅᑯ', 'qquu' => 'ᖅᑰ', 'qqa' => 'ᖅᑲ', 'qqaa' => 'ᖅᑳ',
84 'q' => 'ᖅ', 'qi' => 'ᕿ', 'qii' => 'ᖀ', 'qu' => 'ᖁ', 'quu' => 'ᖂ', 'qa' => 'ᖃ', 'qaa' => 'ᖄ',
85 'ng' => 'ᖕ', 'ngi' => 'ᖏ', 'ngii' => 'ᖐ', 'ngu' => 'ᖑ', 'nguu' => 'ᖒ', 'nga' => 'ᖓ', 'ngaa' => 'ᖔ',
86 'nng' => 'ᖖ', 'nngi' => 'ᙱ', 'nngii' => 'ᙲ', 'nngu' => 'ᙳ', 'nnguu' => 'ᙴ', 'nnga' => 'ᙵ', 'nngaa' => 'ᙶ',
87 'ɫ' => 'ᖦ', 'ɫi' => 'ᖠ', 'ɫii' => 'ᖡ', 'ɫu' => 'ᖢ', 'ɫuu' => 'ᖣ', 'ɫa' => 'ᖤ', 'ɫaa' => 'ᖥ',
90 function loadDefaultTables() {
91 $this->mTables
= array(
92 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin
),
93 'ike-cans' => new ReplacementArray( $this->mToSyllabics
),
94 'ike-latn' => new ReplacementArray( $this->mToLatin
),
95 'iu' => new ReplacementArray()
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
105 * @param $rule string
106 * @param $flags array
109 function parseManualRule( $rule, $flags = array() ) {
110 if ( in_array( 'T', $flags ) ) {
111 return parent
::parseManualRule( $rule, $flags );
115 // otherwise ignore all formatting
116 foreach ( $this->mVariants
as $v ) {
124 * Do not convert content on talk pages
126 * @param $text string
127 * @param $parser Parser
130 function parserConvert( $text, &$parser ) {
131 $this->mDoContentConvert
= !( is_object( $parser->getTitle() ) && $parser->getTitle()->isTalkPage() );
133 return parent
::parserConvert( $text, $parser );
137 * A function wrapper:
138 * - if there is no selected variant, leave the link
140 * - do not try to find variants for usernames
142 * @param $link string
144 * @param $ignoreOtherCond bool
146 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
147 // check for user namespace
148 if ( is_object( $nt ) ) {
149 $ns = $nt->getNamespace();
150 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
156 parent
::findVariantLink( $link, $nt, $ignoreOtherCond );
157 if ( $this->getPreferredVariant() == $this->mMainLanguageCode
) {
163 * An ugly function wrapper for parsing Image titles
164 * (to prevent image name conversion)
166 * @param $text string
167 * @param $toVariant bool
171 function autoConvert( $text, $toVariant = false ) {
173 if ( is_object( $wgTitle ) && $wgTitle->getNamespace() == NS_FILE
) {
174 $imagename = $wgTitle->getNsText();
175 if ( preg_match( "/^$imagename:/", $text ) ) {
179 return parent
::autoConvert( $text, $toVariant );
183 * It translates text into variant
185 * @param $text string
186 * @param $toVariant bool
190 function translate( $text, $toVariant ) {
191 // If $text is empty or only includes spaces, do nothing
192 // Otherwise translate it
193 if ( trim( $text ) ) {
195 // To syllabics, first translate uppercase to lowercase Latin
196 if ( $toVariant == 'ike-cans' ) {
197 $text = $this->mTables
['lowercase']->replace( $text );
199 $text = $this->mTables
[$toVariant]->replace( $text );
210 class LanguageIu
extends Language
{
211 function __construct() {
214 parent
::__construct();
216 $variants = array( 'iu', 'ike-cans', 'ike-latn' );
217 $variantfallbacks = array(
224 $this->mConverter
= new IuConverter( $this, 'iu', $variants, $variantfallbacks, $flags );
225 $wgHooks['PageContentSaveComplete'][] = $this->mConverter
;