| | |
| | | #!/usr/bin/env php |
| | | <?php |
| | | /* |
| | | |
| | | +-----------------------------------------------------------------------+ |
| | | | bin/importgettext.sh | |
| | | | | |
| | |
| | | +-----------------------------------------------------------------------+ |
| | | | Author: Thomas Bruederli <roundcube@gmail.com> | |
| | | +-----------------------------------------------------------------------+ |
| | | |
| | | $Id$ |
| | | |
| | | */ |
| | | |
| | | define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); |
| | | define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); |
| | | require INSTALL_PATH.'program/include/clisetup.php'; |
| | | |
| | | if ($argc < 2) { |
| | |
| | | foreach ($out as $outfn => $texts) { |
| | | $lang = preg_match('!/([a-z]{2}(_[A-Z]{2})?)[./]!', $outfn, $m) ? $m[1] : ''; |
| | | $varname = strpos($outfn, 'messages.inc') !== false ? 'messages' : 'labels'; |
| | | |
| | | |
| | | $header = <<<EOF |
| | | <?php |
| | | |
| | |
| | | +-----------------------------------------------------------------------+ |
| | | | Author: %-62s| |
| | | +-----------------------------------------------------------------------+ |
| | | @version $Id$ |
| | | */ |
| | | |
| | | $%s = array(); |
| | | |
| | | EOF; |
| | | |
| | | $output = sprintf($header, $lang, $varname.'.inc', date('Y'), $texts['_translator'], $varname); |
| | | $author = preg_replace('/\s*<Unknown>/i', '', $texts['_translator']); |
| | | $output = sprintf($header, $lang, $varname.'.inc', date('Y'), $author, $varname); |
| | | |
| | | foreach ($texts as $label => $value) { |
| | | if ($label[0] != '_') |
| | | if (is_array($value)) { var_dump($outfn, $label, $value); exit; } |
| | | if ($label[0] != '_' && strlen($value)) |
| | | $output .= sprintf("\$%s['%s'] = '%s';\n", $varname, $label, strtr(addcslashes($value, "'"), array("\r" => '', "\n" => '\n'))); |
| | | } |
| | | |
| | | $output .= "\n"; |
| | | $dir = dirname($outfn); |
| | | @mkdir($dir, 664, true); |
| | | @mkdir($dir, 0755, true); |
| | | if (file_put_contents($outfn, $output)) |
| | | echo "-> $outfn\n"; |
| | | } |
| | |
| | | { |
| | | $out = array(); |
| | | $lines = file($fn); |
| | | $language = 'xx_XX'; |
| | | $language = ''; |
| | | $translator = ''; |
| | | |
| | | // get language code from file name |
| | | if (preg_match('/-([a-z_]+).po$/i', $fn, $m)) |
| | | $language = expand_langcode($m[1]); |
| | | |
| | | $is_header = true; |
| | | $msgid = null; |
| | |
| | | foreach ($dests as $dest) { |
| | | list($file, $label) = explode(':', $dest); |
| | | $out[$file][$label] = $msgstr; |
| | | $out[$file]['_translator'] = $translator; |
| | | } |
| | | } |
| | | |
| | | |
| | | $msgid = null; |
| | | $msgstr = ''; |
| | | $dests = array(); |
| | |
| | | $out[$file]['_translator'] = $translator; |
| | | } |
| | | } |
| | | |
| | | return $out; |
| | | |
| | | return $language ? $out : array(); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | function expand_langcode($lang) |
| | | { |
| | | static $rcube_language_aliases; |
| | | static $rcube_language_aliases, $rcube_languages; |
| | | |
| | | if (!$rcube_language_aliases) |
| | | include(INSTALL_PATH . 'program/localization/index.inc'); |
| | | |
| | | if ($rcube_language_aliases[$lang]) |
| | | return $rcube_language_aliases[$lang]; |
| | | else if (strlen($lang) == 2) |
| | | else if (strlen($lang) == 2 && !isset($rcube_languages[$lang])) |
| | | return strtolower($lang) . '_' . strtoupper($lang); |
| | | else |
| | | return $lang; |
| | | } |
| | | |
| | | |
| | | ?> |
| | | ?> |