| | |
| | | #!/usr/bin/env php |
| | | <?php |
| | | /* |
| | | |
| | | +-----------------------------------------------------------------------+ |
| | | | bin/exportgettext.sh | |
| | | | | |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2011, The Roundcube Dev Team | |
| | | | Licensed under the GNU GPLv3 | |
| | | | Licensed under the GNU General Public License | |
| | | | | |
| | | | PURPOSE: | |
| | | | Export PHP-based localization files to PO files for gettext | |
| | | +-----------------------------------------------------------------------+ |
| | | | 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 = slashify($argv[2]); |
| | | $layout = 'launchpad' # or 'narro'; |
| | | $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; |
| | |
| | | { |
| | | global $layout; |
| | | |
| | | $outdir = unslashify($outdir); |
| | | if (!is_dir($outdir)) // attempt to create destination dir |
| | | mkdir($outdir, 0777, true); |
| | | |
| | |
| | | */ |
| | | function convert_file($fn, $outfn) |
| | | { |
| | | global $layout; |
| | | global $layout, $langcode_map; |
| | | |
| | | $basename = basename($fn); |
| | | $srcname = str_replace(INSTALL_PATH, '', $fn); |
| | | $product = preg_match('!plugins/(\w+)!', $srcname, $m) ? 'roundcube-plugin-' . $m[1] : 'roundcubemail'; |
| | | $lang = preg_match('!/([a-z]{2}(_[A-Z]{2})?)[./]!', $outfn, $m) ? $m[1] : ''; |
| | | $labels = $messages = $seen = array(); |
| | | |
| | |
| | | $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 |
| | |
| | | #: %s |
| | | msgid "" |
| | | msgstr "" |
| | | "Project-Id-Version: roundcubemail\\n" |
| | | "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, 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) |
| | |
| | | function gettext_quote($str) |
| | | { |
| | | $out = ""; |
| | | $lines = explode("\n", $str); |
| | | $suffix = count($lines) > 1 ? '\n' : ''; |
| | | foreach ($lines as $line) |
| | | $out .= '"' . addcslashes($line, '"') . $suffix . "\"\n"; |
| | | $lines = explode("\n", wordwrap(stripslashes($str))); |
| | | $last = count($lines) - 1; |
| | | foreach ($lines as $i => $line) |
| | | $out .= '"' . addcslashes($line, '"') . ($i < $last ? ' ' : '') . "\"\n"; |
| | | return rtrim($out); |
| | | } |
| | | |
| | | ?> |
| | | ?> |