| | |
| | | #!/usr/bin/env php |
| | | <?php |
| | | /* |
| | | |
| | | +-----------------------------------------------------------------------+ |
| | | | bin/exportgettext.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) { |
| | |
| | | $srcdir = unslashify(realpath($argv[1])); |
| | | $destdir = unslashify($argv[2]); |
| | | $layout = 'launchpad'; # or 'narro'; |
| | | $langcode_map = array( |
| | | 'hy_AM' => 'hy', |
| | | 'ar_SA' => 'ar', |
| | | 'az_AZ' => 'az', |
| | | 'bg_BG' => 'bg', |
| | | 'bs_BA' => 'bs', |
| | | 'ca_ES' => 'ca', |
| | | 'cs_CZ' => 'cs', |
| | | 'cy_GB' => 'cy', |
| | | 'da_DK' => 'da', |
| | | 'et_EE' => 'et', |
| | | 'el_GR' => 'el', |
| | | 'eu_ES' => 'eu', |
| | | 'fa_IR' => 'fa', |
| | | 'ga_IE' => 'ga', |
| | | 'ka_GE' => 'ka', |
| | | 'gl_ES' => 'gl', |
| | | 'he_IL' => 'he', |
| | | 'hi_IN' => 'hi', |
| | | 'hr_HR' => 'hr', |
| | | 'ja_JP' => 'ja', |
| | | 'ko_KR' => 'ko', |
| | | 'km_KH' => 'km', |
| | | 'ms_MY' => 'ms', |
| | | 'mr_IN' => 'mr', |
| | | 'ml_IN' => 'ml', |
| | | 'pl_PL' => 'pl', |
| | | 'si_LK' => 'si', |
| | | 'sl_SI' => 'sl', |
| | | 'sq_AL' => 'sq', |
| | | 'sr_CS' => 'sr', |
| | | 'sv_SE' => 'sv', |
| | | 'uk_UA' => 'uk', |
| | | 'vi_VN' => 'vi', |
| | | ); |
| | | |
| | | |
| | | // converting roundcube localization dir |
| | |
| | | } |
| | | } |
| | | } |
| | | // converting plugin localization |
| | | // converting single localization directory |
| | | else if (is_dir($srcdir)) { |
| | | load_en_US($srcdir.'/en_US.inc'); |
| | | if (is_file($srcdir.'/en_US.inc')) // plugin localization |
| | | load_en_US($srcdir.'/en_US.inc'); |
| | | else |
| | | load_en_US(realpath($srcdir.'/../en_US')); // single language |
| | | convert_dir($srcdir, $destdir); |
| | | } |
| | | // converting a single file |
| | |
| | | } |
| | | else if (is_file($fn)) { |
| | | include($fn); |
| | | $texts = array_merge($texts, (array)$labels); |
| | | $texts = array_merge($texts, (array)$labels, (array)$messages); |
| | | } |
| | | |
| | | $GLOBALS['en_US'] = $texts; |
| | |
| | | */ |
| | | function convert_file($fn, $outfn) |
| | | { |
| | | global $layout; |
| | | global $layout, $langcode_map; |
| | | |
| | | $basename = basename($fn); |
| | | $srcname = str_replace(INSTALL_PATH, '', $fn); |
| | |
| | | $is_pot = true; |
| | | } |
| | | // launchpad is very picky about file names |
| | | else if ($layout == 'launchpad' && preg_match($regex = '!/([a-z]{2})_([A-Z]{2})!', $outfn, $m) && $m[1] == strtolower($m[2])) { |
| | | $outfn = preg_replace($regex, '/\1', $outfn); |
| | | else if ($layout == 'launchpad' && preg_match($regex = '!/([a-z]{2})_([A-Z]{2})!', $outfn, $m)) { |
| | | if ($shortlang = $langcode_map[$lang]) |
| | | $outfn = preg_replace($regex, '/'.$shortlang, $outfn); |
| | | else if ($m[1] == strtolower($m[2])) |
| | | $outfn = preg_replace($regex, '/\1', $outfn); |
| | | } |
| | | |
| | | include($fn); |
| | | $texts = $labels ? $labels : $messages; |
| | | $texts = array_merge($labels, $messages); |
| | | |
| | | // write header |
| | | $header = <<<EOF |
| | |
| | | msgstr "" |
| | | "Project-Id-Version: %s\\n" |
| | | "Report-Msgid-Bugs-To: \\n" |
| | | "POT-Creation-Date: %s\\n" |
| | | "PO-Revision-Date: %s\\n" |
| | | "%s: %s\\n" |
| | | "Last-Translator: \\n" |
| | | "Language-Team: Translations <hello@roundcube.net>\\n" |
| | | "Language: %s\\n" |
| | |
| | | "Content-Transfer-Encoding: 8bit\\n" |
| | | EOF; |
| | | |
| | | $out = sprintf($header, $srcname, $product, date('c'), date('c'), $lang); |
| | | $out = sprintf($header, $srcname, $product, $is_pot ? "POT-Creation-Date" : "PO-Revision-Date", date('c'), $shortlang ? $shortlang : $lang); |
| | | $out .= "\n"; |
| | | |
| | | $messages = array(); |
| | | foreach ((array)$texts as $label => $msgstr) { |
| | | $msgid = $GLOBALS['en_US'][$label] ?: $label; |
| | | $msgid = $is_pot ? $msgstr : ($GLOBALS['en_US'][$label] ?: $label); |
| | | $messages[$msgid][] = $label; |
| | | } |
| | | |
| | | |
| | | foreach ($messages as $msgid => $labels) { |
| | | $out .= "\n"; |
| | | foreach ($labels as $label) |
| | |
| | | { |
| | | $out = ""; |
| | | $lines = explode("\n", wordwrap(stripslashes($str))); |
| | | foreach ($lines as $line) |
| | | $out .= '"' . addcslashes($line, '"') . "\"\n"; |
| | | $last = count($lines) - 1; |
| | | foreach ($lines as $i => $line) |
| | | $out .= '"' . addcslashes($line, '"') . ($i < $last ? ' ' : '') . "\"\n"; |
| | | return rtrim($out); |
| | | } |
| | | |
| | | ?> |
| | | ?> |