PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/languages/classes/LanguageGan.php

https://github.com/tav/confluence
PHP | 168 lines | 126 code | 20 blank | 22 comment | 0 complexity | 495cbc798f3ca0e0ddfec947d6efd6e7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0
  1. <?php
  2. require_once( dirname(__FILE__).'/../LanguageConverter.php' );
  3. require_once( dirname(__FILE__).'/LanguageZh.php' );
  4. /**
  5. * @ingroup Language
  6. */
  7. class GanConverter extends LanguageConverter {
  8. function __construct($langobj, $maincode,
  9. $variants=array(),
  10. $variantfallbacks=array(),
  11. $markup=array(),
  12. $flags = array(),
  13. $manualLevel = array() ) {
  14. $this->mDescCodeSep = ':';
  15. $this->mDescVarSep = ';';
  16. parent::__construct($langobj, $maincode,
  17. $variants,
  18. $variantfallbacks,
  19. $markup,
  20. $flags,
  21. $manualLevel);
  22. $names = array(
  23. 'gan' => '原文',
  24. 'gan-hans' => '简体',
  25. 'gan-hant' => '繁體',
  26. );
  27. $this->mVariantNames = array_merge($this->mVariantNames,$names);
  28. $this->loadNamespaceTables();
  29. }
  30. function loadNamespaceTables() {
  31. global $wgMetaNamespace;
  32. $nsproject = $wgMetaNamespace;
  33. $projecttable = array(
  34. 'Wikipedia' => '维基百科',
  35. 'Wikisource' => '维基文库',
  36. 'Wikinews' => '维基新闻',
  37. 'Wiktionary' => '维基词典',
  38. 'Wikibooks' => '维基教科书',
  39. 'Wikiquote' => '维基语录',
  40. );
  41. $this->mNamespaceTables['gan-hans'] = array(
  42. 'Media' => '媒体',
  43. 'Special' => '特殊',
  44. 'Talk' => '談詑',
  45. 'User' => '用户',
  46. 'User talk' => '用户談詑',
  47. $nsproject
  48. => isset($projecttable[$nsproject]) ?
  49. $projecttable[$nsproject] : $nsproject,
  50. $nsproject . ' talk'
  51. => isset($projecttable[$nsproject]) ?
  52. $projecttable[$nsproject] . '談詑' : $nsproject . '談詑',
  53. 'File' => '文件',
  54. 'File talk' => '文件談詑',
  55. 'MediaWiki' => 'MediaWiki',
  56. 'MediaWiki talk' => 'MediaWiki談詑',
  57. 'Template' => '模板',
  58. 'Template talk' => '模板談詑',
  59. 'Help' => '帮助',
  60. 'Help talk' => '帮助談詑',
  61. 'Category' => '分类',
  62. 'Category talk' => '分类談詑',
  63. );
  64. $this->mNamespaceTables['gan-hant'] = array_merge($this->mNamespaceTables['gan-hans']);
  65. $this->mNamespaceTables['gan-hant']['File'] = '檔案';
  66. $this->mNamespaceTables['gan-hant']['File talk'] = '檔案談詑';
  67. $this->mNamespaceTables['gan'] = array_merge($this->mNamespaceTables['gan-hans']);
  68. }
  69. function loadDefaultTables() {
  70. require( dirname(__FILE__)."/../../includes/ZhConversion.php" );
  71. $this->mTables = array(
  72. 'gan-hans' => new ReplacementArray( $zh2Hans ),
  73. 'gan-hant' => new ReplacementArray( $zh2Hant ),
  74. 'gan' => new ReplacementArray
  75. );
  76. }
  77. /* there shouldn't be any latin text in Chinese conversion, so no need
  78. to mark anything.
  79. $noParse is there for compatibility with LanguageConvert::markNoConversion
  80. */
  81. function markNoConversion($text, $noParse = false) {
  82. return $text;
  83. }
  84. function convertCategoryKey( $key ) {
  85. return $this->autoConvert( $key, 'gan' );
  86. }
  87. }
  88. /**
  89. * class that handles both Traditional and Simplified Chinese
  90. * right now it only distinguish gan_hans, gan_hant.
  91. *
  92. * @ingroup Language
  93. */
  94. class LanguageGan extends LanguageZh {
  95. function __construct() {
  96. global $wgHooks;
  97. parent::__construct();
  98. $variants = array('gan','gan-hans','gan-hant');
  99. $variantfallbacks = array(
  100. 'gan' => array('gan-hans','gan-hant'),
  101. 'gan-hans' => array('gan'),
  102. 'gan-hant' => array('gan'),
  103. );
  104. $ml=array(
  105. 'gan' => 'disable',
  106. );
  107. $this->mConverter = new GanConverter( $this, 'gan',
  108. $variants, $variantfallbacks,
  109. array(),array(),
  110. $ml);
  111. $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
  112. }
  113. # this should give much better diff info
  114. function segmentForDiff( $text ) {
  115. return preg_replace(
  116. "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
  117. "' ' .\"$1\"", $text);
  118. }
  119. function unsegmentForDiff( $text ) {
  120. return preg_replace(
  121. "/ ([\\xc0-\\xff][\\x80-\\xbf]*)/e",
  122. "\"$1\"", $text);
  123. }
  124. // word segmentation
  125. function stripForSearch( $string ) {
  126. wfProfileIn( __METHOD__ );
  127. // eventually this should be a word segmentation
  128. // for now just treat each character as a word
  129. // @fixme only do this for Han characters...
  130. $t = preg_replace(
  131. "/([\\xc0-\\xff][\\x80-\\xbf]*)/",
  132. " $1", $string);
  133. //always convert to gan-hans before indexing. it should be
  134. //better to use gan-hans for search, since conversion from
  135. //Traditional to Simplified is less ambiguous than the
  136. //other way around
  137. $t = $this->mConverter->autoConvert($t, 'gan-hans');
  138. $t = parent::stripForSearch( $t );
  139. wfProfileOut( __METHOD__ );
  140. return $t;
  141. }
  142. function convertForSearchResult( $termsArray ) {
  143. $terms = implode( '|', $termsArray );
  144. $terms = implode( '|', $this->mConverter->autoConvertToAllVariants( $terms ) );
  145. $ret = array_unique( explode('|', $terms) );
  146. return $ret;
  147. }
  148. }