Пример #1
0
function createPOT($top_module, $module, $module_vers, $strings_template, $preserve_date = false)
{
    if (!$module) {
        I2CE::raiseError("No module");
        return false;
    }
    if ($module_vers) {
        if (!array_key_exists('', $strings_template)) {
            $comments = array('' => array("Translation Template of {$top_module} module (" . $module . " Version " . $module_vers . ")", "Copyright (C) " . date("Y") . " <*****@*****.**> Capacity Project partnership via IntraHealth International, Inc."));
            $msgstr = "Project-Id-Version: {$top_module}@{$module} {$module_vers}\n";
            $msgstr .= "POT-Creation-Date: " . date("Y-m-d H:iO") . "\n";
            $msgstr .= "Last-Translator: Intrahealth <*****@*****.**>\n";
            $msgstr .= "Language-Team: Intrahealth <*****@*****.**>\n";
            $msgstr .= "MIME-Version: 1.0\n";
            $msgstr .= "Content-Type: text/plain; charset=utf-8\n";
            $msgstr .= "Content-Transfer-Encoding: 8bit\n";
            $msgstr .= "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n";
            $strings_template = array_merge(array('' => array('comments' => $comments, 'msgstr' => $msgstr)), $strings_template);
        } else {
            $msgstr = explode("\n", $strings_template['']['msgstr']);
            foreach ($msgstr as &$str) {
                if (!$preserve_date) {
                    $str = preg_replace('/^\\s*POT\\-Creation\\-Date.*$/i', "POT-Creation-Date: " . date("Y-m-d H:iO"), $str);
                }
                $str = preg_replace('/^\\s*Project\\-Id\\-Version.*$/i', "Project-Id-Version: {$top_module}@{$module} {$module_vers}", $str);
            }
            $strings_template['']['msgstr'] = implode("\n", $msgstr);
            if (array_key_exists('comments', $strings_template['']) && is_array($strings_template['']['comments']) && array_key_exists('', $strings_template['']['comments']) && is_array($strings_template['']['comments'][''])) {
                foreach ($strings_template['']['comments'][''] as &$str) {
                    $str = preg_replace('/^\\s*Translation Template of.*$/i', "Translation Template of {$top_module} module (" . $module . " Version " . $module_vers . ")", $str);
                }
            }
        }
    }
    I2CE::raiseError("Module {$module} has " . count($strings_template) . " strings");
    if (count($strings_template) == 1) {
        //there are no strings to translate.
        return true;
    }
    $out = createPOContent($strings_template);
    if (!$out) {
        return true;
    }
    return $out;
}
            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) {
            if (!array_key_exists($english_source, $old_trans) || !is_array($old_trans[$english_source]) || !array_key_exists('msgstr', $old_trans[$english_source]) || !trim($old_trans[$english_source]['msgstr'])) {
                continue;
            }
            if (!array_key_exists($english_source, $new_trans) || !is_array($new_trans[$english_source]) || !array_key_exists('msgstr', $new_trans[$english_source]) || !trim($new_trans[$english_source]['msgstr'])) {
                echo "{$po_file}: " . $old_trans[$english_source]['msgstr'] . " missing ({$english_source})\n";
                $changed++;
                $new_trans[$english_source] = $old_trans[$english_source];
            }
        }
        if ($changed == 0 || !prompt("Save  " . $po_file . " with {$changed} missing translations?", $save)) {
            continue;
        }
        if (!($content = createPOContent($new_trans))) {
            echo "Could not create content for {$po_file}\n";
            continue;
        }
        if (!file_put_contents($po_file, $content)) {
            echo "Could not save {$po_file}\n";
        }
    }
}