Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -12,7 +12,9 @@ |
13 | 13 | var $mMainLanguageCode; |
14 | 14 | var $mVariants, $mVariantFallbacks; |
15 | 15 | var $mTablesLoaded = false; |
| 16 | + var $mUseFss = false; |
16 | 17 | var $mTables; |
| 18 | + var $mFssObjects; |
17 | 19 | var $mTitleDisplay=''; |
18 | 20 | var $mDoTitleConvert=true, $mDoContentConvert=true; |
19 | 21 | var $mCacheKey; |
— | — | @@ -46,6 +48,9 @@ |
47 | 49 | $this->mMarkup = array_merge($m, $markup); |
48 | 50 | $f = array('A'=>'A', 'T'=>'T'); |
49 | 51 | $this->mFlags = array_merge($f, $flags); |
| 52 | + if ( function_exists( 'fss_prep_replace' ) ) { |
| 53 | + $this->mUseFss = true; |
| 54 | + } |
50 | 55 | } |
51 | 56 | |
52 | 57 | /** |
— | — | @@ -158,11 +163,11 @@ |
159 | 164 | |
160 | 165 | |
161 | 166 | $m = array_shift($matches); |
162 | | - $ret = strtr($m[0], $this->mTables[$toVariant]); |
| 167 | + $ret = $this->translate($m[0], $toVariant); |
163 | 168 | $mstart = $m[1]+strlen($m[0]); |
164 | 169 | foreach($matches as $m) { |
165 | 170 | $ret .= substr($text, $mstart, $m[1]-$mstart); |
166 | | - $ret .= strtr($m[0], $this->mTables[$toVariant]); |
| 171 | + $ret .= $this->translate($m[0], $toVariant); |
167 | 172 | $mstart = $m[1] + strlen($m[0]); |
168 | 173 | } |
169 | 174 | wfProfileOut( $fname ); |
— | — | @@ -170,6 +175,24 @@ |
171 | 176 | } |
172 | 177 | |
173 | 178 | /** |
| 179 | + * Translate a string to a variant |
| 180 | + * Doesn't process markup or do any of that other stuff, for that use convert() |
| 181 | + * |
| 182 | + * @param string $text Text to convert |
| 183 | + * @param string $variant Variant language code |
| 184 | + * @return string Translated text |
| 185 | + */ |
| 186 | + function translate( $text, $variant ) { |
| 187 | + if( !$this->mTablesLoaded ) |
| 188 | + $this->loadTables(); |
| 189 | + if ( $this->mUseFss ) { |
| 190 | + return fss_exec_replace( $this->mFssObjects[$variant], $text ); |
| 191 | + } else { |
| 192 | + return strtr( $text, $this->mTables[$variant] ); |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + /** |
174 | 197 | * convert text to all supported variants |
175 | 198 | * |
176 | 199 | * @param string $text the text to be converted |
— | — | @@ -184,7 +207,7 @@ |
185 | 208 | |
186 | 209 | $ret = array(); |
187 | 210 | foreach($this->mVariants as $variant) { |
188 | | - $ret[$variant] = strtr($text, $this->mTables[$variant]); |
| 211 | + $ret[$variant] = $this->translate($text, $variant); |
189 | 212 | } |
190 | 213 | wfProfileOut( $fname ); |
191 | 214 | return $ret; |
— | — | @@ -334,6 +357,9 @@ |
335 | 358 | |
336 | 359 | } |
337 | 360 | } |
| 361 | + if ( $this->mUseFss ) { |
| 362 | + $this->generateFssObjects(); |
| 363 | + } |
338 | 364 | } |
339 | 365 | } |
340 | 366 | else { |
— | — | @@ -498,8 +524,20 @@ |
499 | 525 | $wgMemc->set($this->mCacheKey, $this->mTables, 43200); |
500 | 526 | $this->unlockCache(); |
501 | 527 | } |
| 528 | + if ( $this->mUseFss ) { |
| 529 | + $this->generateFssObjects(); |
| 530 | + } |
502 | 531 | } |
503 | 532 | |
| 533 | + /** |
| 534 | + * Generate FSS objects. The FSS extension must be available. |
| 535 | + */ |
| 536 | + function generateFssObjects() { |
| 537 | + foreach ( $this->mTables as $variant => $table ) { |
| 538 | + $this->mFssObjects[$variant] = fss_prep_replace( $table ); |
| 539 | + } |
| 540 | + } |
| 541 | + |
504 | 542 | /** |
505 | 543 | * Hook for post processig after conversion tables are loaded |
506 | 544 | * |