00001 <?php
00002
00016
00017
00018
00019 require(dirname(__FILE__) . '/includes/cliTool.inc.php');
00020
00021 define('PO_TO_CSV_TOOL', '/usr/bin/po2csv');
00022
00023 class poToCurrencies extends CommandLineTool {
00025 var $locale;
00026
00028 var $translationFile;
00029
00033 function poToCurrencies($argv = array()) {
00034 parent::CommandLineTool($argv);
00035
00036 $toolName = array_shift($argv);
00037
00038 $this->locale = array_shift($argv);
00039 $this->translationFile = array_shift($argv);
00040
00041 if ( !preg_match('/^[a-z]{2}_[A-Z]{2}$/', $this->locale) ||
00042 empty($this->translationFile) ||
00043 !file_exists($this->translationFile)
00044 ) {
00045 $this->usage();
00046 exit(1);
00047 }
00048 }
00049
00053 function usage() {
00054 echo "Script to convert PO file to OJS's ISO4217 XML format\n"
00055 . "Usage: {$this->scriptName} locale /path/to/translation.po\n";
00056 }
00057
00061 function execute() {
00062
00063 $ih = popen(PO_TO_CSV_TOOL . ' ' . escapeshellarg($this->translationFile), 'r');
00064 if (!$ih) die ('Unable to read ' . $this->translationFile . ' using ' . PO_TO_CSV_TOOL . "\n");
00065
00066 $translationMap = array();
00067 while ($row = fgetcsv($ih)) {
00068 if (count($row) != 3) continue;
00069 list($comment, $english, $translation) = $row;
00070 $translationMap[$english] = $translation;
00071 }
00072 fclose($ih);
00073
00074
00075 $currencyDao =& DAORegistry::getDAO('CurrencyDAO');
00076 $currencies =& $currencyDao->getCurrencies();
00077
00078
00079 $outputMap = array();
00080 foreach ($currencies as $currency) {
00081 $english = $currency->getName();
00082 $codeAlpha = $currency->getCodeAlpha();
00083 $codeNumeric = $currency->getCodeNumeric();
00084
00085 if (!isset($translationMap[$english])) {
00086 echo "WARNING: Unknown currency \"$english\"! Using English as default.\n";
00087 } else {
00088 $currency->setName($translationMap[$english]);
00089 }
00090 $outputMap[] = $currency;
00091 }
00092
00093
00094 $ofn = 'locale/' . $this->locale . '/currencies.xml';
00095 $oh = fopen($ofn, 'w');
00096 if (!$oh) die ("Unable to $ofn for writing.\n");
00097
00098 fwrite($oh, '<?xml version="1.0" encoding="UTF-8"?>
00099
00100 <!--
00101 * currencies.xml
00102 *
00103 * Copyright (c) 2003-2008 John Willinsky
00104 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
00105 *
00106 * Localized list of currencies.
00107 *
00108 * $Id: poToCurrencies.php,v 1.3 2008/07/01 01:16:14 asmecher Exp $
00109 -->
00110
00111 <!DOCTYPE currencies [
00112 <!ELEMENT currencies (currency+)>
00113 <!ATTLIST currencies
00114 locale CDATA #REQUIRED>
00115 <!ELEMENT currency EMPTY>
00116 <!ATTLIST currency
00117 code_alpha CDATA #REQUIRED
00118 code_numeric CDATA #REQUIRED
00119 name CDATA #REQUIRED>
00120 ]>
00121
00122 <currencies locale="' . $this->locale . "\">\n");
00123 foreach ($outputMap as $currency) {
00124 fwrite($oh, " <currency name=\"" . $currency->getName() . "\" code_alpha=\"" . $currency->getCodeAlpha() . "\" code_numeric=\"" . $currency->getCodeNumeric() . "\" />\n");
00125 }
00126
00127 fwrite($oh, "</currencies>");
00128 fclose($oh);
00129 }
00130 }
00131
00132 $tool = &new poToCurrencies(isset($argv) ? $argv : array());
00133 $tool->execute();
00134
00135 ?>