Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -322,6 +322,10 @@ |
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
| 326 | + if( $this->guessVariant( $text, $toVariant ) ) { |
| 327 | + return $text; |
| 328 | + } |
| 329 | + |
326 | 330 | /* we convert everything except: |
327 | 331 | 1. HTML markups (anything between < and >) |
328 | 332 | 2. HTML entities |
— | — | @@ -571,7 +575,7 @@ |
572 | 576 | */ |
573 | 577 | public function convertTo( $text, $variant ) { |
574 | 578 | global $wgDisableLangConversion; |
575 | | - if ( $wgDisableLangConversion ) { |
| 579 | + if ( $wgDisableLangConversion || $this->guessVariant( $text, $variant ) ) { |
576 | 580 | return $text; |
577 | 581 | } |
578 | 582 | return $this->recursiveConvertTopLevel( $text, $variant ); |
— | — | @@ -769,6 +773,20 @@ |
770 | 774 | } |
771 | 775 | |
772 | 776 | /** |
| 777 | + * Guess if a text is written in a variant. This should be implemented in subclasses. |
| 778 | + * |
| 779 | + * @param string $text the text to be checked |
| 780 | + * @param string $variant language code of the variant to be checked for |
| 781 | + * @return bool true if $text appears to be written in $variant, false if not |
| 782 | + * |
| 783 | + * @author Nikola Smolenski <smolensk@eunet.rs> |
| 784 | + * @since 1.18 |
| 785 | + */ |
| 786 | + public function guessVariant($text, $variant) { |
| 787 | + return false; |
| 788 | + } |
| 789 | + |
| 790 | + /** |
773 | 791 | * Load default conversion tables. |
774 | 792 | * This method must be implemented in derived class. |
775 | 793 | * |
Index: trunk/phase3/languages/classes/LanguageSr.php |
— | — | @@ -148,6 +148,27 @@ |
149 | 149 | |
150 | 150 | return $ret; |
151 | 151 | } |
| 152 | + |
| 153 | + /** |
| 154 | + * Guess if a text is written in Cyrillic or Latin. |
| 155 | + * |
| 156 | + * @author Nikola Smolenski <smolensk@eunet.rs> |
| 157 | + * @since 1.18 |
| 158 | + */ |
| 159 | + public function guessVariant( $text, $variant ) { |
| 160 | + $numCyrillic = preg_match_all("/[шђчћжШЂЧЋЖ]/u", $text, $dummy); |
| 161 | + $numLatin = preg_match_all("/[šđč枊ĐČĆŽ]/u", $text, $dummy); |
| 162 | + |
| 163 | + if( $variant == 'sr-ec' ) { |
| 164 | + return $numCyrillic > $numLatin; |
| 165 | + } else if( $variant == 'sr-el' ) { |
| 166 | + return $numLatin > $numCyrillic; |
| 167 | + } else { |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
| 171 | + } |
| 172 | + |
152 | 173 | } |
153 | 174 | |
154 | 175 | /** |
— | — | @@ -202,4 +223,5 @@ |
203 | 224 | } |
204 | 225 | } |
205 | 226 | } |
| 227 | + |
206 | 228 | } |
Property changes on: trunk/phase3/languages |
___________________________________________________________________ |
Added: svn:mergeinfo |
207 | 229 | Merged /branches/new-installer/phase3/languages:r43664-66004 |
208 | 230 | Merged /branches/REL1_15/phase3/languages:r51646 |
209 | 231 | Merged /branches/REL1_17/phase3/languages:r81445,81448 |
210 | 232 | Merged /branches/nikola/phase3/languages:r85224,85239,85308 |
211 | 233 | Merged /branches/sqlite/languages:r58211-58321 |