$module_vers = '';
 I2CE::getConfig()->setIfIsSet($module_vers, "/config/data/{$module}/version");
 if (strlen($module_vers) == 0) {
     I2CE::raiseError("No module version found -- Skipping");
     continue;
 }
 $avail_locales = array();
 foreach (glob($template_dir . '*.po') as $avail_locale) {
     $avail_locales[basename($avail_locale, '.po')] = $avail_locale;
 }
 $pot_file = $template_dir . $lp_module . '.pot';
 if (!is_readable($pot_file)) {
     I2CE::raiseError($pot_file . " is not readable for {$module}");
     continue;
 }
 $old_translations = loadPOT($pot_file);
 $sources = array_keys($old_translations);
 foreach ($sources as $i => $source) {
     if (strlen(trim($source)) == 0) {
         unset($sources[$i]);
         continue;
     }
 }
 $old_src = chooseMenuValue("Which string would you like to change?", $sources);
 do {
     $new_src = trim(ask("What is the new source?"));
 } while (!simple_prompt("Replace:\n\t{$old_src}\nto:\n\t{$new_src}"));
 if (simple_prompt("Would you like to preserve the existing translations in the .po files for the locales " . implode(",", array_keys($avail_locales)) . "?")) {
     foreach ($avail_locales as $avail_locale => $avail_locale_file) {
         I2CE::raiseError("Updateing {$lp_module}'s {$avail_locale}.po");
         $loc_translations = loadPot($avail_locale_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;
         }
         $t_translations[$msg_id] = $msg_str;
     }
     $translations_array[$module] = $t_translations;
 }
 if (!is_array($translations_array[$module]) || count($translations_array[$module]) == 0) {
     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)) {
     //remove metat data for the time being so we can easily check for new/changed/removed strings below.
     $meta = $existing_template[''];
     unset($existing_template['']);
     if (array_key_exists('msgstr', $meta)) {
         if (preg_match('/^\\s*Project\\-Id\\-Version\\:\\s*(\\S+)\\@(\\S+)[ \\t]+([0-9a-zA-Z\\.]+)\\s*$/im', $meta['msgstr'], $matches)) {
             if ($top_module !== $matches[1]) {
                 I2CE::raiseError("Changed top-level module");
             } else {
 }
 $pot_contents = createPOT($top_module, $module, $vers, $converted_template, true);
 if (!is_string($pot_contents)) {
     continue;
 }
 if (!file_put_contents($pot_file, $pot_contents)) {
     I2CE::raiseError("Could not write:" . $pot_file, E_USER_ERROR);
 }
 I2CE::raiseError("Wrote:" . $pot_file);
 foreach ($locales as $locale) {
     $po_file = $template_dir . DIRECTORY_SEPARATOR . $launchpad_name . DIRECTORY_SEPARATOR . $locale . '.po';
     if (!is_readable($po_file)) {
         //I2CE::raiseError($po_file  . " is not readable for $module");
         continue;
     }
     $existing_translations = loadPOT($po_file);
     if (!is_array($existing_translations) || count($existing_translations) == 0) {
         continue;
     }
     $converted_translations = array();
     foreach ($existing_translations as $msg_id => $data) {
         if ($msg_id != '') {
             $data['msgstr'] = solidifySource($data['msgstr']);
         }
         $converted_translations[solidifySource($msg_id)] = $data;
     }
     $po_contents = createPOT($top_module, $module, $vers, $converted_translations, true);
     if (!is_string($po_contents)) {
         continue;
     }
     if (!file_put_contents($po_file, $po_contents)) {
require_once "translate_base.php";
if (!$args['rev']) {
    usage("No revision specified");
}
getAvailableModules();
$changed_pos = array();
foreach ($found_modules as $module => $top_module) {
    $launch_module = launchpad($module);
    $pot_dir = $templates_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';
    if (!is_array($current_template = loadPOT($pot_file))) {
        continue;
    }
    $po_files = glob(dirname($pot_file) . DIRECTORY_SEPARATOR . "*.po");
    foreach ($po_files as $po_file) {
        if (!is_array($new_trans = loadPot($po_file))) {
            continue;
        }
        $old_content = array();
        exec("bzr cat -r " . $args['rev'] . " " . $po_file, $old_content);
        $old_content = $old_content;
        if (!is_array($old_trans = loadPotByContent($old_content))) {
            continue;
        }
        $changed = 0;
        foreach ($current_template as $english_source => $data) {
        usage("Could not create tar {$archive} in {$archive_dir}");
    }
    foreach ($existing as $l_mod => $file) {
        if (!array_key_exists($l_mod, $launchpad_modules)) {
            I2CE::raiseError("The module {$l_mod} has a .pot files but is not a module in the system -- skipping");
            continue;
        }
        if (!$tar->addModify($file, $l_mod, dirname($file))) {
            usage("Could not add {$file}");
        }
        unset($launchpad_modules[$l_mod]);
    }
    if (count($launchpad_modules) > 0) {
        I2CE::raiseError("The following:\n\t" . implode(",", array_keys($launchpad_modules)) . "\ndid not have an existing .po file.  Creating a blank one");
    }
    foreach ($launchpad_modules as $l_mod => $top_mod) {
        $po = loadPOT(getcwd() . DIRECTORY_SEPARATOR . $template_dir . DIRECTORY_SEPARATOR . $l_mod . DIRECTORY_SEPARATOR . $l_mod . '.pot');
        if (!is_array($po) || count($po) < 1) {
            //I2CE::raiseError("Problem with .pot for $l_mod.  Skipping");  no translations
            continue;
        }
        $cs = $po['']['comments'][''];
        array_unshift($cs, "{$locale} translation for " . $basename);
        $po['']['comments'][''] = $cs;
        $po = createPOT($top_mod, $l_mod, false, $po);
        if (!$tar->addString($l_mod . DIRECTORY_SEPARATOR . $locale . '.po', $po)) {
            I2CE::raiseError("Could not add untranslated {$l_mod}");
        }
    }
    I2CE::raiseError("Created {$archive} in {$archive_dir}");
}
Пример #7
0
 unset($def_locale_line);
 //$default_locales = array('fr','sw','it','es','pt','ar');
 $file = basename(__FILE__) . "/../modules/Pages/modules/LocaleSelector/modules/DefaultLocales/DefaultLocales.xml";
 foreach ($found_modules as $module => $top_module) {
     $current_pkg = false;
     $current_pkg = $module_packages[$module];
     if (!array_key_exists($module, $module_packages)) {
         I2CE::raiseError("Could not deterine which package {$module} resides in");
         //should not happen
         continue;
     }
     $pot_file = $packages[$current_pkg]['dir'] . DIRECTORY_SEPARATOR . $templates_dir . launchpad($module) . DIRECTORY_SEPARATOR . launchpad($module) . '.pot';
     if (!array_key_exists($current_pkg, $pots)) {
         $pots[$current_pkg] = array();
     }
     if (is_readable($pot_file) && count($pot_strings = loadPOT($pot_file)) > 1) {
         $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