if (!in_array($mo_file, $tar_files)) { continue; } $contents = false; I2CE::raiseError("Extracting {$mo_file}"); $contents = $tar->extractInString($mo_file); if (!$contents) { I2CE::raiseError("Bad extraction for {$mo_file}"); continue; } $mo_resource = fopen("php://temp", 'r+'); fputs($mo_resource, $contents); rewind($mo_resource); $translations_array[$module] = loadMO($mo_resource); } else { $po_file = $templates_dir . launchpad($module) . DIRECTORY_SEPARATOR . $locale . '.po'; if (!is_readable($po_file)) { I2CE::raiseError($po_file . " is not readable for {$module}"); continue; } $t_translations = loadPOT($po_file); foreach ($t_translations as $msg_id => $data) { if (!array_key_exists('msgstr', $data)) { unset($t_translations[$msg_id]); continue; } $msg_str = $data['msgstr']; if (!$msg_id || !$msg_str || $msg_id == $msg_str) { unset($t_translations[$msg_id]); continue; }
* @subpackage Core * @author Carl Leitner <*****@*****.**> * @copyright Copyright © 2008, 2008 IntraHealth International, Inc. * @version 1.0 */ $templates_dir = "." . DIRECTORY_SEPARATOR . "translations" . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; $set_configs = false; require_once "translate_base.php"; $templates = getTranslatableDocuments(false); $configs = getTranslatableConfigs(false); foreach (array_keys($found_modules) as $module) { if ((!array_key_exists($module, $templates) || !is_array($templates[$module])) && (!array_key_exists($module, $configs) || !$configs[$module])) { I2CE::raiseError("No translatable templates or configs for {$module}"); continue; } $lp_modules[] = launchpad($module); $modules[] = $module; } ksort($modules); do { $idx = chooseMenuIndex("Which module would you like to fixup a english source text for?", $lp_modules); $module = $modules[$idx]; $lp_module = $lp_modules[$idx]; if ((!array_key_exists($module, $templates) || !is_array($templates[$module])) && (!array_key_exists($module, $configs) || !$configs[$module])) { I2CE::raiseError("No translatable templates or configs for {$module}"); continue; } $template_dir = $templates_dir . $lp_module . DIRECTORY_SEPARATOR; $module_vers = ''; I2CE::getConfig()->setIfIsSet($module_vers, "/config/data/{$module}/version"); if (strlen($module_vers) == 0) {
if (array_key_exists($module, $configs)) { I2CE::raiseError("Checking for translatable configuration strings in {$module}"); getConfigurationStrings($module, $configs[$module], $mod_strings); } if (!array_key_exists($module, $templates)) { $templates[$module] = array(); } foreach ($templates[$module] as $path => $files) { foreach ($files as $file) { //strings is an array with keys the msgstr and values iether true or a translator's comment if (extractStringsFromDocument($file, $mod_strings) === false) { I2CE::raiseError("WARNING: Could not extract strings from {$file}. -- Skipping"); } } } $launch_module = launchpad($module); $pot_dir = $template_dir . DIRECTORY_SEPARATOR . $launch_module; if (!is_dir($pot_dir)) { if (!mkdir($pot_dir, 0775, true)) { usage("Could not make {$pot_dir}"); } } $pot_file = $pot_dir . DIRECTORY_SEPARATOR . $launch_module . '.pot'; $existing_template = loadPOT($pot_file); $changed_comments = true; $changed_plural = false; $meta = false; if ($existing_template === false) { $existing_template = array(); } if (array_key_exists('', $existing_template)) {
foreach ($files as $file) { $locale = basename($file, '.po'); $locales[$locale] = true; } $locales = array_keys($locales); } $found_modules = getAvailableModules(); if (count($found_modules) == 0) { usage("No modules found"); } if (!$locales || count($locales) == 0) { usage("No valid locales specified"); } I2CE::raiseError("Updating translations locales:\n\t" . implode(',', $locales)); foreach ($found_modules as $module => $top_module) { $launchpad_name = launchpad($module); $pot_file = $template_dir . DIRECTORY_SEPARATOR . $launchpad_name . DIRECTORY_SEPARATOR . $launchpad_name . '.pot'; $existing_template = loadPOT($pot_file); if (!is_array($existing_template) || count($existing_template) == 0) { continue; } $vers = ''; if (!I2CE::getConfig()->setIfIsSet($vers, "/config/data/{$module}/version") || strlen($vers) == 0) { I2CE::raiseError("No module version found -- Skipping"); continue; } $converted_template = array(); foreach ($existing_template as $msg_id => $data) { if ($msg_id != '') { $data['msgstr'] = solidifySource($data['msgstr']); }
if ($locales == false) { usage("Please specify locales"); } $found_modules = getAvailableModules(); $launchpad_modules = array(); foreach ($found_modules as $mod => $top_mod) { $launchpad_modules[launchpad($mod)] = $top_mod; } if (count($found_modules) == 0) { usage("No modules found"); } if (count($locales) == 0) { usage("No valid locales specified"); } I2CE::raiseError("Creating .po files for locales:\n\t" . implode(',', $locales)); $basename = launchpad(basename(getcwd())); foreach ($locales as $i => $locale) { $files = glob(getcwd() . DIRECTORY_SEPARATOR . $template_dir . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $locale . '.po'); $existing = array(); foreach ($files as $file) { $existing[basename(dirname($file))] = realpath($file); //key is launchpad module name } if (count($existing) == 0) { I2CE::raiseError("WARNING: the locale {$locale} has no .po files -- the created .po files wiil have no translations\n"); } else { I2CE::raiseError("Using existing translations:\n\t" . implode(',', array_keys($existing)) . "\nThe rest will be empty of translations"); } $archive = $basename . '-po-' . $locale . '.tgz'; $tar = new Archive_Tar(getcwd() . DIRECTORY_SEPARATOR . $archive_dir . DIRECTORY_SEPARATOR . $archive); $tar->setErrorHandling(PEAR_ERROR_CALLBACK, array('I2CE', 'raiseError'));
$count = -1; foreach ($pot_strings as $string => $details) { $count++; if (!$string) { continue; } if (!array_key_exists($string, $pot_master)) { $pot_master[$string] = array(); } if (!array_key_exists($string, $pots[$current_pkg])) { $pots[$current_pkg][$string] = array(); } $links = array(); foreach ($default_locales as $locale) { //https://translations.launchpad.net/ihris-manage/trunk/+pots/accident/pt_BR/+translate $links[] = '[https://translations.launchpad.net/' . strtolower($packages[$current_pkg]['top_module']) . '/trunk/+pots/' . launchpad($module) . '/' . $locale . '/' . $count . '/+translate ' . $locale . ']'; } $comm = ''; if (array_key_exists('comments', $details)) { foreach ($details['comments'] as $prefix => $comment_list) { if (count($comment_list) == 0 || !array_key_exists($prefix, $prefixes)) { continue; } foreach ($comment_list as &$c) { $c = preg_replace('/\\<a\\s+href=\'(.*?)\'\\>(.*?)\\<\\/a\\>/', '[$1 $2]', $c); } $comm .= "\n* " . $prefixes[$prefix] . "\n** " . implode("\n** ", $comment_list) . "\n"; } } $data = array('module' => $module, 'links' => $links, 'pkg' => $current_pkg, 'comments' => $comm); $pot_master[$string][] = $data;