Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / maintenance / language / generateNormalizerDataMl.php
1 <?php
2 /**
3 * Generates the normalizer data file for Malayalam.
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 MaintenanceLanguage
22 */
23
24 require_once __DIR__ . '/../Maintenance.php';
25
26 /**
27 * Generates the normalizer data file for Malayalam.
28 *
29 * This data file is used after normalizing to NFC.
30 *
31 * @ingroup MaintenanceLanguage
32 */
33 class GenerateNormalizerDataMl extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Generate the normalizer data file for Malayalam' );
37 }
38
39 public function getDbType() {
40 return Maintenance::DB_NONE;
41 }
42
43 public function execute() {
44 $hexPairs = [
45 # From http://unicode.org/versions/Unicode5.1.0/#Malayalam_Chillu_Characters
46 '0D23 0D4D 200D' => '0D7A',
47 '0D28 0D4D 200D' => '0D7B',
48 '0D30 0D4D 200D' => '0D7C',
49 '0D32 0D4D 200D' => '0D7D',
50 '0D33 0D4D 200D' => '0D7E',
51
52 # From http://permalink.gmane.org/gmane.science.linguistics.wikipedia.technical/46413
53 '0D15 0D4D 200D' => '0D7F',
54 ];
55
56 $pairs = [];
57 foreach ( $hexPairs as $hexSource => $hexDest ) {
58 $source = UtfNormal\Utils::hexSequenceToUtf8( $hexSource );
59 $dest = UtfNormal\Utils::hexSequenceToUtf8( $hexDest );
60 $pairs[$source] = $dest;
61 }
62
63 global $IP;
64 file_put_contents( "$IP/serialized/normalize-ml.ser", serialize( $pairs ) );
65 echo "ml: " . count( $pairs ) . " pairs written.\n";
66 }
67 }
68
69 $maintClass = GenerateNormalizerDataMl::class;
70 require_once RUN_MAINTENANCE_IF_MAIN;