[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/languages/classes/ -> LanguageShi.php (source)

   1  <?php
   2  /**
   3   * Shilha specific code.
   4   *
   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.
   9   *
  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.
  14   *
  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
  19   *
  20   * @file
  21   * @ingroup Language
  22   */
  23  
  24  require_once  __DIR__ . '/../LanguageConverter.php';
  25  
  26  /**
  27   * Conversion script between Latin and Tifinagh for Tachelhit.
  28   * - Tifinagh -> lowercase Latin
  29   * - lowercase/uppercase Latin -> Tifinagh
  30   *
  31   *
  32   * Based on:
  33   *   - http://en.wikipedia.org/wiki/Shilha_language
  34   *   - LanguageSr.php
  35   *
  36   * @ingroup Language
  37   */
  38  class ShiConverter extends LanguageConverter {
  39      protected $mDoContentConvert;
  40  
  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',
  48      );
  49  
  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', 'Ɣ' => 'ɣ',
  57      );
  58  
  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' => 'ⵒ',
  66      );
  67  
  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()
  74          );
  75      }
  76  
  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
  82       *
  83       * @param string $rule
  84       * @param array $flags
  85       * @return array
  86       */
  87  	function parseManualRule( $rule, $flags = array() ) {
  88          if ( in_array( 'T', $flags ) ) {
  89              return parent::parseManualRule( $rule, $flags );
  90          }
  91  
  92          $carray = array();
  93          // otherwise ignore all formatting
  94          foreach ( $this->mVariants as $v ) {
  95              $carray[$v] = $rule;
  96          }
  97  
  98          return $carray;
  99      }
 100  
 101      /**
 102       * Do not convert content on talk pages
 103       *
 104       * @param string $text
 105       * @param Parser $parser
 106       * @return string
 107       */
 108  	function parserConvert( $text, &$parser ) {
 109          $this->mDoContentConvert = !( is_object( $parser->getTitle() )
 110              && $parser->getTitle()->isTalkPage() );
 111  
 112          return parent::parserConvert( $text, $parser );
 113      }
 114  
 115      /**
 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
 120       *
 121       * @param string &$link
 122       * @param Title &$nt
 123       * @param bool $ignoreOtherCond
 124       */
 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;
 131              }
 132          }
 133  
 134          $oldlink = $link;
 135          parent::findVariantLink( $link, $nt, $ignoreOtherCond );
 136          if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
 137              $link = $oldlink;
 138          }
 139      }
 140  
 141      /**
 142       * It translates text into variant
 143       *
 144       * @param string $text
 145       * @param string $toVariant
 146       *
 147       * @return string
 148       */
 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 );
 157              }
 158              $text = $this->mTables[$toVariant]->replace( $text );
 159          }
 160          return $text;
 161      }
 162  }
 163  
 164  /**
 165   * Tachelhit
 166   *
 167   * @ingroup Language
 168   */
 169  class LanguageShi extends Language {
 170  	function __construct() {
 171          global $wgHooks;
 172  
 173          parent::__construct();
 174  
 175          $variants = array( 'shi', 'shi-tfng', 'shi-latn' );
 176          $variantfallbacks = array(
 177              'shi' => 'shi-tfng',
 178              'shi-tfng' => 'shi',
 179              'shi-latn' => 'shi',
 180          );
 181  
 182          $flags = array();
 183          $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags );
 184          $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
 185      }
 186  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1