Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / languages / classes / LanguageShi.php
blob105a3af746344a7be3e4ddbb5cfa86e147b4ea33
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 {
39 protected $mDoContentConvert;
41 public $mToLatin = array(
42 'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e',
43 'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x',
44 'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n',
45 'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵖ' => 'γ', 'ⵙ' => 's', 'ⵚ' => 'ṣ',
46 'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z',
47 'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ', 'ⵖ' => 'ɣ', 'ⵠ' => 'v', 'ⵒ' => 'p',
50 public $mUpperToLowerCaseLatin = array(
51 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e',
52 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j',
53 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o',
54 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't',
55 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y',
56 'Z' => 'z', 'Ɣ' => 'ɣ',
59 public $mToTifinagh = array(
60 'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ',
61 'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ',
62 'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ',
63 'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ',
64 'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ',
65 'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ', 'ɣ' => 'ⵖ', 'v' => 'ⵠ', 'p' => 'ⵒ',
68 function loadDefaultTables() {
69 $this->mTables = array(
70 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ),
71 'shi-tfng' => new ReplacementArray( $this->mToTifinagh ),
72 'shi-latn' => new ReplacementArray( $this->mToLatin ),
73 'shi' => new ReplacementArray()
77 /**
78 * rules should be defined as -{Tifinagh | Latin-} -or-
79 * -{code:text | code:text | ...}-
80 * update: delete all rule parsing because it's not used
81 * currently, and just produces a couple of bugs
83 * @param string $rule
84 * @param array $flags
85 * @return array
87 function parseManualRule( $rule, $flags = array() ) {
88 if ( in_array( 'T', $flags ) ) {
89 return parent::parseManualRule( $rule, $flags );
92 $carray = array();
93 // otherwise ignore all formatting
94 foreach ( $this->mVariants as $v ) {
95 $carray[$v] = $rule;
98 return $carray;
102 * Do not convert content on talk pages
104 * @param string $text
105 * @param Parser $parser
106 * @return string
108 function parserConvert( $text, &$parser ) {
109 $this->mDoContentConvert = !( is_object( $parser->getTitle() )
110 && $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 string &$link
122 * @param Title &$nt
123 * @param bool $ignoreOtherCond
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 * It translates text into variant
144 * @param string $text
145 * @param string $toVariant
147 * @return string
149 function translate( $text, $toVariant ) {
150 // If $text is empty or only includes spaces, do nothing
151 // Otherwise translate it
152 if ( trim( $text ) ) {
153 $this->loadTables();
154 // To Tifinagh, first translate uppercase to lowercase Latin
155 if ( $toVariant == 'shi-tfng' ) {
156 $text = $this->mTables['lowercase']->replace( $text );
158 $text = $this->mTables[$toVariant]->replace( $text );
160 return $text;
165 * Tachelhit
167 * @ingroup Language
169 class LanguageShi extends Language {
170 function __construct() {
171 global $wgHooks;
173 parent::__construct();
175 $variants = array( 'shi', 'shi-tfng', 'shi-latn' );
176 $variantfallbacks = array(
177 'shi' => 'shi-tfng',
178 'shi-tfng' => 'shi',
179 'shi-latn' => 'shi',
182 $flags = array();
183 $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags );
184 $wgHooks['PageContentSaveComplete'][] = $this->mConverter;