Stop doing $that = $this in Tests
[mediawiki.git] / languages / classes / LanguageShi.php
blobafd7283bb06bd6b7bdd6e953dfc6013d539ef09a
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 /**
25 * Conversion script between Latin and Tifinagh for Tachelhit.
26 * - Tifinagh -> lowercase Latin
27 * - lowercase/uppercase Latin -> Tifinagh
30 * Based on:
31 * - http://en.wikipedia.org/wiki/Shilha_language
32 * - LanguageSr.php
34 * @ingroup Language
36 class ShiConverter extends LanguageConverter {
37 protected $mDoContentConvert;
39 public $mToLatin = array(
40 'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e',
41 'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x',
42 'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n',
43 'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵖ' => 'γ', 'ⵙ' => 's', 'ⵚ' => 'ṣ',
44 'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z',
45 'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ', 'ⵖ' => 'ɣ', 'ⵠ' => 'v', 'ⵒ' => 'p',
48 public $mUpperToLowerCaseLatin = array(
49 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
50 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
51 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
52 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
53 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
54 'Z' => 'z', 'Ɣ' => 'ɣ',
57 public $mToTifinagh = array(
58 'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ',
59 'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ',
60 'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ',
61 'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ',
62 'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ',
63 'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ', 'ɣ' => 'ⵖ', 'v' => 'ⵠ', 'p' => 'ⵒ',
66 function loadDefaultTables() {
67 $this->mTables = array(
68 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
69 'shi-tfng' => new ReplacementArray( $this->mToTifinagh ),
70 'shi-latn' => new ReplacementArray( $this->mToLatin ),
71 'shi' => new ReplacementArray()
75 /**
76 * rules should be defined as -{Tifinagh | Latin-} -or-
77 * -{code:text | code:text | ...}-
78 * update: delete all rule parsing because it's not used
79 * currently, and just produces a couple of bugs
81 * @param string $rule
82 * @param array $flags
83 * @return array
85 function parseManualRule( $rule, $flags = array() ) {
86 if ( in_array( 'T', $flags ) ) {
87 return parent::parseManualRule( $rule, $flags );
90 $carray = array();
91 // otherwise ignore all formatting
92 foreach ( $this->mVariants as $v ) {
93 $carray[$v] = $rule;
96 return $carray;
99 /**
100 * Do not convert content on talk pages
102 * @param string $text
103 * @param Parser $parser
104 * @return string
106 function parserConvert( $text, &$parser ) {
107 $this->mDoContentConvert = !( is_object( $parser->getTitle() )
108 && $parser->getTitle()->isTalkPage() );
110 return parent::parserConvert( $text, $parser );
114 * A function wrapper:
115 * - if there is no selected variant, leave the link
116 * names as they were
117 * - do not try to find variants for usernames
119 * @param string &$link
120 * @param Title &$nt
121 * @param bool $ignoreOtherCond
123 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
124 // check for user namespace
125 if ( is_object( $nt ) ) {
126 $ns = $nt->getNamespace();
127 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
128 return;
132 $oldlink = $link;
133 parent::findVariantLink( $link, $nt, $ignoreOtherCond );
134 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
135 $link = $oldlink;
140 * It translates text into variant
142 * @param string $text
143 * @param string $toVariant
145 * @return string
147 function translate( $text, $toVariant ) {
148 // If $text is empty or only includes spaces, do nothing
149 // Otherwise translate it
150 if ( trim( $text ) ) {
151 $this->loadTables();
152 // To Tifinagh, first translate uppercase to lowercase Latin
153 if ( $toVariant == 'shi-tfng' ) {
154 $text = $this->mTables['lowercase']->replace( $text );
156 $text = $this->mTables[$toVariant]->replace( $text );
158 return $text;
163 * Tachelhit
165 * @ingroup Language
167 class LanguageShi extends Language {
168 function __construct() {
169 global $wgHooks;
171 parent::__construct();
173 $variants = array( 'shi', 'shi-tfng', 'shi-latn' );
174 $variantfallbacks = array(
175 'shi' => 'shi-tfng',
176 'shi-tfng' => 'shi',
177 'shi-latn' => 'shi',
180 $flags = array();
181 $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags );
182 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;