public function execute() { $dir = __DIR__; require_once "{$dir}/cldr.php"; $DATA = $this->getOption('datadir', "{$dir}/core/common/main"); $OUTPUT = $this->getOption('outputdir', $dir); if (!file_exists($DATA)) { $this->error("CLDR data not found at {$DATA}\n", 1); } // Get an array of all MediaWiki languages ( $wgLanguageNames + $wgExtraLanguageNames ) $languages = Language::fetchLanguageNames(); # hack to get pt-pt too $languages['pt-pt'] = 'Foo'; ksort($languages); foreach ($languages as $code => $name) { // Construct the correct name for the input file unset($codeParts); $codeParts = explode('-', $code); if (count($codeParts) > 1) { // ISO 15924 alpha-4 script code if (strlen($codeParts[1]) == 4) { $codeParts[1] = ucfirst($codeParts[1]); } // ISO 3166-1 alpha-2 country code if (strlen($codeParts[1]) == 2) { $codeParts[2] = $codeParts[1]; unset($codeParts[1]); } if (isset($codeParts[2]) && strlen($codeParts[2]) == 2) { $codeParts[2] = strtoupper($codeParts[2]); } $codeCLDR = implode('_', $codeParts); } else { $codeCLDR = $code; } $input = "{$DATA}/{$codeCLDR}.xml"; // If the file exists, parse it, otherwise display an error if (file_exists($input)) { $outputFileName = Language::getFileName("CldrNames", getRealCode($code), '.php'); $p = new CLDRParser(); $p->parse($input, "{$OUTPUT}/CldrNames/{$outputFileName}"); } else { $this->output("File {$input} not found\n"); } } // Now parse out what we want form the supplemental file $this->output("Parsing Supplemental Data...\n"); // argh! If $DATA defaulted to something slightly more general in the // CLDR dump, this wouldn't have to be this way. $input = "{$DATA}/../supplemental/supplementalData.xml"; if (file_exists($input)) { $p = new CLDRParser(); $p->parse_supplemental($input, "{$OUTPUT}/CldrSupplemental/Supplemental.php"); } else { $this->output("File {$input} not found\n"); } $this->output("Done parsing supplemental data.\n"); $this->output("Parsing Currency Symbol Data...\n"); $p = new CLDRParser(); $p->parse_currency_symbols($DATA, "{$OUTPUT}/CldrCurrency/Symbols.php"); $this->output("Done parsing currency symbols.\n"); }
unset($codeParts[1]); } if (isset($codeParts[2])) { if (strlen($codeParts[2]) == 2) { $codeParts[2] = strtoupper($codeParts[2]); } } $codeCLDR = implode('_', $codeParts); } else { $codeCLDR = $code; } $input = "{$DATA}/{$codeCLDR}.xml"; // If the file exists, parse it, otherwise display an error if (file_exists($input)) { $outputFileName = Language::getFileName("CldrNames", getRealCode($code), '.php'); $p = new CLDRParser(); $p->parse($input, "{$OUTPUT}/CldrNames/{$outputFileName}"); } elseif (isset($options['verbose'])) { echo "File {$input} not found\n"; } } class CLDRParser { private $parseContents = true; private $languages = false; private $currencies = false; private $currency = false; private $countries = false; private $languageCount = 0; private $currencyCount = 0; private $countryCount = 0;