Exemplo n.º 1
0
function writeOutPOT($file, $top_module, $module, $module_vers, $strings_template)
{
    $out = createPOT($top_module, $module, $module_vers, $strings_template);
    if ($out === false) {
        return false;
    }
    I2CE::raiseError("Looking at {$file}");
    if (file_exists($file)) {
        I2CE::raiseError("Looking at {$file} -- exists");
        //first let's check to see if the only difference is the date.  if so then don't make any changes.
        if ($in = file_get_contents($file)) {
            $reg = '/"POT-Creation-Date:.*/';
            $t_out = preg_replace($reg, '', $out);
            $in = preg_replace($reg, '', $in);
            if (strcmp($in, $t_out) === 0) {
                I2CE::raiseError(basename($file) . ' has not changes');
                return true;
            }
        }
        if (!unlink($file)) {
            I2CE::raiseError("Could not remove existing .pot file for {$module} and there are not strings to translate");
            return false;
        }
    }
    if (is_string($out)) {
        if (!file_put_contents($file, $out)) {
            I2CE::raiseError("WARNING: Unable to create translation template at {$file}\n");
            return false;
        }
    }
    return true;
}
        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}");
}
    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)) {
            I2CE::raiseError("Could not write:" . $po_file, E_USER_ERROR);
        }
        I2CE::raiseError("Wrote:" . $po_file);
    }
}
        continue;
    }
    $trans = $translations_array[$ws_module];
    $untrans = array();
    foreach ($pot as $msgid => &$data) {
        if (strlen(trim($msgid)) == 0) {
            continue;
        }
        if (!array_key_exists($msgid, $trans) || !is_string($trans[$msgid])) {
            $untrans[] = $msgid;
            continue;
        }
        if (strlen(trim($trans[$msgid])) == 0) {
            $untrans[] = $msgid;
            continue;
        }
        $data['msgstr'] = $trans[$msgid];
    }
    if (count($untrans) > 0) {
        I2CE::raiseError("{$module} has the following untranslated strings:" . print_r($untrans, true));
    }
    unset($data);
    $po_file = createPOT($top_module, $module, $vers, $pot);
    if (!is_string($po_file)) {
        continue;
    }
    if (!file_put_contents($l_file, $po_file)) {
        I2CE::raiseError("Could not write:" . $l_file, E_USER_ERROR);
    }
    I2CE::raiseError("Wrote:" . $l_file);
}