DifferenceEngine cleanup
[mediawiki.git] / languages / classes / LanguageShi.php
blobf4180cb8fb2d1a3f758270c95d302fb1504ea9be
1 <?php
2 /**
3 * Shilha 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 Tifinagh for Tachelhit.
28 * - Tifinagh -> lowercase Latin
29 * - lowercase/uppercase Latin -> Tifinagh
32 * Based on:
33 * - http://en.wikipedia.org/wiki/Shilha_language
34 * - LanguageSr.php
36 * @ingroup Language
38 class ShiConverter extends LanguageConverter {
40 protected $mDoContentConvert;
42 public $mToLatin = array(
43 'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e',
44 'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x',
45 'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n',
46 'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵖ' => 'γ', 'ⵙ' => 's', 'ⵚ' => 'ṣ',
47 'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z',
48 'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ', 'ⵖ' => 'ɣ', 'ⵠ' => 'v', 'ⵒ' => 'p',
51 public $mUpperToLowerCaseLatin = array(
52 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
53 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
54 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
55 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
56 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
57 'Z' => 'z', 'Ɣ' => 'ɣ',
60 public $mToTifinagh = array(
61 'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ',
62 'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ',
63 'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ',
64 'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ',
65 'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ',
66 'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ', 'ɣ' => 'ⵖ', 'v' => 'ⵠ', 'p' => 'ⵒ',
69 function loadDefaultTables() {
70 $this->mTables = array(
71 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
72 'shi-tfng' => new ReplacementArray( $this->mToTifinagh ),
73 'shi-latn' => new ReplacementArray( $this->mToLatin ),
74 'shi' => new ReplacementArray()
78 /**
79 * rules should be defined as -{Tifinagh | Latin-} -or-
80 * -{code:text | code:text | ...}-
81 * update: delete all rule parsing because it's not used
82 * currently, and just produces a couple of bugs
84 * @param $rule string
85 * @param $flags array
86 * @return array
88 function parseManualRule( $rule, $flags = array() ) {
89 if ( in_array( 'T', $flags ) ) {
90 return parent::parseManualRule( $rule, $flags );
93 $carray = array();
94 // otherwise ignore all formatting
95 foreach ( $this->mVariants as $v ) {
96 $carray[$v] = $rule;
99 return $carray;
103 * Do not convert content on talk pages
105 * @param $text string
106 * @param $parser Parser
107 * @return string
109 function parserConvert( $text, &$parser ) {
110 $this->mDoContentConvert = !( is_object( $parser->getTitle() ) && $parser->getTitle()->isTalkPage() );
112 return parent::parserConvert( $text, $parser );
116 * A function wrapper:
117 * - if there is no selected variant, leave the link
118 * names as they were
119 * - do not try to find variants for usernames
121 * @param $link string
122 * @param $nt Title
123 * @param $ignoreOtherCond bool
125 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
126 // check for user namespace
127 if ( is_object( $nt ) ) {
128 $ns = $nt->getNamespace();
129 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
130 return;
134 $oldlink = $link;
135 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
136 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
137 $link = $oldlink;
142 * An ugly function wrapper for parsing Image titles
143 * (to prevent image name conversion)
145 * @param $text string
146 * @param $toVariant bool
148 * @return string
150 function autoConvert( $text, $toVariant = false ) {
151 global $wgTitle;
152 if ( is_object( $wgTitle ) && $wgTitle->getNamespace() == NS_FILE ) {
153 $imagename = $wgTitle->getNsText();
154 if ( preg_match( "/^$imagename:/", $text ) ) {
155 return $text;
158 return parent::autoConvert( $text, $toVariant );
162 * It translates text into variant
164 * @param $text string
165 * @param $toVariant string
167 * @return string
169 function translate( $text, $toVariant ) {
170 // If $text is empty or only includes spaces, do nothing
171 // Otherwise translate it
172 if ( trim( $text ) ) {
173 $this->loadTables();
174 // To Tifinagh, first translate uppercase to lowercase Latin
175 if ( $toVariant == 'shi-tfng' ) {
176 $text = $this->mTables['lowercase']->replace( $text );
178 $text = $this->mTables[$toVariant]->replace( $text );
180 return $text;
185 * Tachelhit
187 * @ingroup Language
189 class LanguageShi extends Language {
190 function __construct() {
191 global $wgHooks;
193 parent::__construct();
195 $variants = array( 'shi', 'shi-tfng', 'shi-latn' );
196 $variantfallbacks = array(
197 'shi' => 'shi-tfng',
198 'shi-tfng' => 'shi',
199 'shi-latn' => 'shi',
202 $flags = array();
203 $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags );
204 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;