argv) == 2) { $this->inLocale = $this->argv[0]; $this->outLocale = $this->argv[1]; } else { $this->inLocale = DEFAULT_IN_LOCALE; $this->outLocale = DEFAULT_OUT_LOCALE; } $this->replaceMap = array( 'a' => "\xc3\xa5", 'A' => "\xc3\x86", 'c' => "\xc3\xa7", 'C' => "\xc3\x87", 'd' => "\xc3\xb0", 'D' => "\xc3\x90", 'e' => "\xc3\xa8", 'E' => "\xc3\x89", 'i' => "\xc3\xae", 'I' => "\xc3\x8e", 'n' => "\xc3\xb1", 'N' => "\xc3\x91", 'o' => "\xc3\xb3", 'O' => "\xc3\x92", 's' => "\xc3\xbe", 'S' => "\xc3\x9f", 'u' => "\xc3\xbc", 'U' => "\xc3\x9c", 'y' => "\xc3\xbd", 'Y' => "\xc3\x9d", '&' => "&" ); } /** * Create the test locale file. */ function execute() { Locale::initialize(); $localeFiles =& Locale::getLocaleFiles(); $localeFile = array_shift($localeFiles[$this->inLocale]); $localeData = LocaleFile::load($localeFile->filename); if (!isset($localeData)) { printf('Invalid locale \'%s\'', $this->inLocale); exit(1); } $outFile = sprintf('locale/%s/locale.xml', $this->outLocale); $fp = fopen($outFile, 'wb'); if (!$fp) { printf('Failed to write to \'%s\'', $outFile); exit(1); } fwrite($fp, "\n" . "\n\n" . "\n\n" . sprintf("\n", $this->outLocale, DEFAULT_OUT_LOCALE_NAME) ); foreach ($localeData as $key => $message) { $outMessage = $this->fancifyString($message); if (strstr($outMessage, '<') || strstr($outMessage, '>')) { $outMessage = ''; } fwrite($fp, sprintf("\t%s\n", $key, $outMessage)); } fwrite($fp, "\n"); fclose($fp); } /** * Perform message string munging. * @param $str string * @return string */ function fancifyString($str) { $inHTML = 0; $inVar = 0; $outStr = ""; for ($i = 0, $len = strlen($str); $i < $len; $i++) { switch ($str[$i]) { case '{': $inVar++; break; case '}': $inVar--; break; case '<': $inHTML++; break; case '>': $inHTML--; break; } if ($inHTML == 0 && $inVar == 0) { $outStr .= strtr($str[$i], $this->replaceMap); } else { $outStr .= $str[$i]; } } return $outStr; } } $tool = &new genTestLocale(isset($argv) ? $argv : array()); $tool->execute(); ?>