locale = array_shift($argv); $this->translationFile = array_shift($argv); if ( !preg_match('/^[a-z]{2}_[A-Z]{2}$/', $this->locale) || empty($this->translationFile) || !file_exists($this->translationFile) ) { $this->usage(); exit(1); } } /** * Print command usage information. */ function usage() { echo "Script to convert PO file to OJS's ISO4217 XML format\n" . "Usage: {$this->scriptName} locale /path/to/translation.po\n"; } /** * Rebuild the search index for all articles in all journals. */ function execute() { // Read the translated file as a map from English => Whatever $ih = popen(PO_TO_CSV_TOOL . ' ' . escapeshellarg($this->translationFile), 'r'); if (!$ih) die ('Unable to read ' . $this->translationFile . ' using ' . PO_TO_CSV_TOOL . "\n"); $translationMap = array(); while ($row = fgetcsv($ih)) { if (count($row) != 3) continue; list($comment, $english, $translation) = $row; $translationMap[$english] = $translation; } fclose($ih); // Get the English map $currencyDao = DAORegistry::getDAO('CurrencyDAO'); $currencies = $currencyDao->getCurrencies(); // Generate a map of code => translation $outputMap = array(); foreach ($currencies as $currency) { $english = $currency->getName(); if (!isset($translationMap[$english])) { echo "WARNING: Unknown currency \"$english\"! Using English as default.\n"; } else { $currency->setName($translationMap[$english]); } $outputMap[] = $currency; } // Use the map to convert the currency list to the new locale $ofn = 'locale/' . $this->locale . '/currencies.xml'; $oh = fopen($ofn, 'w'); if (!$oh) die ("Unable to $ofn for writing.\n"); fwrite($oh, ' ]> \n"); foreach ($outputMap as $currency) { fwrite($oh, " getName() . "\" code_alpha=\"" . $currency->getCodeAlpha() . "\" code_numeric=\"" . $currency->getCodeNumeric() . "\" />\n"); } fwrite($oh, ""); fclose($oh); } } $tool = new poToCurrencies(isset($argv) ? $argv : array()); $tool->execute(); ?>