\n"); } # Clean each directory's files foreach (array('de-de', 'es-us', 'fr-fr', 'it-it', 'ko-kr', 'pt-br', 'zh-hk') as $l) { $dir = opendir("$argv[1]/$l"); if (!$dir) die; while (false !== $file = readdir($dir)) { # Only act on DTD and PROPERTIES files if (0 == preg_match('/^.*ext_uploadr3_(.*\.(?:dtd|properties)).txt.php$/', $file, $match)) { continue; } # Make sure the destination directory exists if (!file_exists("$locale/$l") && !mkdir("$locale/$l", 0755)) { echo "[error] Can't create locale $l\n"; continue; } # Clean PHP garbage out $text = file_get_contents("$argv[1]/$l/$file"); if (false === $text) { echo "[error] Reading $file\n"; continue; } $text = trim(preg_replace('/^<\?php.*\?>$/ms', '', $text)); # Process each string $lines = explode("\n", $text); $ii = sizeof($lines); $replace = array(); for ($i = 0; $i < $ii; ++$i) { # Escape & and " properly if (preg_match('/^()$/', $lines[$i], $s)) { $lines[$i] = $s[1] . str_replace('"', '"', preg_replace('/&(?!#\d\d;)/', '&', $s[2])) . $s[3]; } # Split up combined complicated strings if (preg_match('/^$/', $lines[$i], $s) && preg_match('/^(.+)\.joined$/', $s[1], $k)) { $parts = explode(' ', $s[2]); if (2 == sizeof($parts)) { $replace["{$k[1]}.1"] = "{$parts[0]} "; $replace["{$k[1]}.2"] = " {$parts[1]}"; $lines[$i] = ''; } } } # Replace split up versions with their translations for ($i = 0; $i < $ii; ++$i) { if (preg_match('/^$/', $lines[$i], $s) && isset($replace[$s[1]])) { $lines[$i] = ""; } } # Write and save $file = next($match); $file_p = fopen("$locale/$l/$file", 'w'); if (false === $file_p) { echo "[error] Opening $file\n"; continue; } if (false === fwrite($file_p, implode("\n", $lines))) { echo "[error] Writing $file\n"; } if (false === fclose($file_p)) { echo "[error] Closing $file\n"; } echo "[ok] finished writing $l/$file\n"; } closedir($dir); } ?>