I need some regular expression to split PO (language translation file) file's translated count , fuzzy count and total string count.
I used PHP for the program, I search every where but couldn't found.
please help me.
Try this regex,
$total = array();
$translated = array();
$extra ='';
// If fuzzy true then translated count = fuzzy count
if($fuzzy) {
$extra = '#, fuzzy\n';
}
$matched = preg_match_all('/'.$extra.'msgid\s+((?:".*(?<!\\\\)"\s*)+)\s+'.'msgstr\s+((?:".*(?<!\\\\)"\s*)+)/', $po_content, $matches);
for ($i = 0; $i < $matched; $i++) {
if(trim(substr(rtrim($matches[1][$i]), 1, -1))!="") {
$total[] = substr(rtrim($matches[1][$i]), 1, -1);
}
if(trim(substr(rtrim($matches[2][$i]), 1, -1))!="") {
if (strpos(substr(rtrim($matches[2][$i]), 1, -1), 'Language-Team')===false && strpos(substr(rtrim($matches[2][$i]), 1, -1), 'MIME-Version')===false ) {
$translated[] = substr(rtrim($matches[2][$i]), 1, -1);
}
}
}
Total count = count($total); Translated count = count($translated);