Merge "registration: Only allow one extension to set a specific config setting"
[lhc/web/wiklou.git] / includes / collation / CollationFa.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 /**
22 * Temporary workaround for incorrect collation of Persian language ('fa') in ICU 52 (bug T139110).
23 *
24 * Replace with other letters that appear in an okish spot in the alphabet
25 *
26 * - Characters 'و' 'ا' (often appear at the beginning of words)
27 * - Characters 'ٲ' 'ٳ' (may appear at the beginning of words in loanwords)
28 *
29 * @since 1.29
30 */
31 class CollationFa extends IcuCollation {
32
33 // Really hacky - replace with stuff from other blocks.
34 private $override = [
35 // U+0627 ARABIC LETTER ALEF => U+0623 ARABIC LETTER ALEF WITH HAMZA ABOVE
36 "\xd8\xa7" => "\xd8\xa3",
37 // U+0648 ARABIC LETTER WAW => U+0649 ARABIC LETTER ALEF MAKSURA
38 "\xd9\x88" => "\xd9\x89",
39 // U+0672 ARABIC LETTER ALEF WITH WAVY HAMZA ABOVE => U+F3001 (private use area)
40 "\xd9\xb2" => "\xF3\xB3\x80\x81",
41 // U+0673 ARABIC LETTER ALEF WITH WAVY HAMZA BELOW => U+F3002 (private use area)
42 "\xd9\xb3" => "\xF3\xB3\x80\x82",
43 ];
44
45 public function __construct() {
46 parent::__construct( 'fa' );
47 }
48
49 public function getSortKey( $string ) {
50 $modified = strtr( $string, $this->override );
51 return parent::getSortKey( $modified );
52 }
53
54 public function getFirstLetter( $string ) {
55 if ( isset( $this->override[substr( $string, 0, 2 )] ) ) {
56 return substr( $string, 0, 2 );
57 }
58 return parent::getFirstLetter( $string );
59 }
60 }