count($fa),
'bCount' => count($fb),
'diff' => count($fa) - count($fb),
); unused var */
$missing = array();
$notrans = array();
$ka = array_keys($fa);
$kb = array_keys($fb);
$missing = array_diff($ka, $kb);
$extra = array_diff($kb, $ka);
// search for untranslated strings
foreach ($fa as $k => $v) {
if (array_key_exists($k, $fb)) {
if ($v == $fb[$k] || '' == $fb[$k]) {
$notrans[] = $k;
}
}
}
return array(
'a_name' => $a,
'b_name' => $b,
'a' => count($fa),
'b' => count($fb),
'missing' => $missing,
'notrans' => $notrans,
'extra' => $extra,
'dup_str' => $duplicates,
);
}
/**
* Diff pot and po files, to get:
* - source (pot) strings count
* - missing strings in target
* - untranslated strings in target
* - empty array for extra and duplicate strings for backward compatibility
*
* @param string $locale locale name ('sl')
* @param string $resource file name ('about/license')
* @param array $source_l array with source file strings (to avoid duplicated parsing)
* @param string $path directly passed path for nonlocal files
* @param array $compared array with strings for comparing
*
* @return array
*/
function _po_diff($locale, $resource, $source_l = NULL, $path = NULL, $compared = NULL)
{
if (is_null($path)) {
if (NULL == $source_l) {
$source_l = read_translation_file('en', $resource);
}
$target_l = read_translation_file($locale, $resource);
} else {
if (NULL == $source_l) {
$source_path_filename = sprintf('%s/%s.pot', $path, $resource);
$source_l = phpmo_parse_po_file($source_path_filename);
if (FALSE == $source_l) {
$source_l = array(array());
}
}
if ('en' == $locale) {
$target_l = $source_l;
} else {
$locale = locale_hyphen_underscore($locale, true);
$target_path_filename = sprintf('%s/%s.po', $path, $locale);
$target_l = phpmo_parse_po_file($target_path_filename);
if (FALSE == $target_l) {
$target_l = array(array());
}
}
}
unset($source_l['']); // filter out header
unset($target_l['']); // filter out header
// process $source_l, $target_l and $compared
$num_of_original_strings = 0;
$fuzzy_or_missing = array();
$untrans = array();
$differences = array();
foreach ($source_l as $msgid => $subarray) {
foreach ($subarray as $context_or_num => $msgstr_subarray) {
$num_of_original_strings++; // Note: count plural msgid strings also as one
if (array_key_exists('msgid_plural', $msgstr_subarray)) {
$msgid_plural = $msgstr_subarray['msgid_plural'];
} else {
$msgid_plural = NULL;
}
// process $target_l translation
if (!isset($target_l[$msgid])) {
// adding fuzzy or missing string or plurals
$fuzzy_or_missing[$msgid] = $subarray;
$msgstr_target_l = NULL;
} else {
$msgstr_target_l = $target_l[$msgid][$context_or_num];
// are there any plurals untranslated?
$untranslated_plural_target_l = FALSE;
if (!is_null($msgid_plural)) {
// filter out msgid_plural
unset($msgstr_target_l['msgid_plural']);
foreach ($msgstr_target_l as $nplural) {
if (empty($nplural)) {
$untranslated_plural_target_l = TRUE;
}
}
}
// untranslated string
if ($untranslated_plural_target_l || empty($msgstr_target_l[0])) {
$untrans[$msgid] = $subarray; // adding untranslated string or plurals
}
}
// process $compared translation
if (!is_null($compared)) {
unset($compared['']); // filter out header
// if there is a translation for this string in $compared
if (isset($compared[$msgid][$context_or_num])) {
$msgstr_compared = $compared[$msgid][$context_or_num];
} else {
$msgstr_compared[0] = '';
}
if ($msgstr_target_l != $msgstr_compared) {
$differences[$msgid]['target_l'][$context_or_num] = $msgstr_target_l;
$differences[$msgid]['compared'][$context_or_num] = $msgstr_compared;
}
}
}
}
return array(
'a' => $num_of_original_strings, // # of original strings
// 'b' => count($po_strings), // # of target strings
'source_strings' => $source_l, // array of original strings
'fuzzy_or_missing' => $fuzzy_or_missing, // array of fuzzy or missing strings
'notrans' => $untrans, // array of untranslated strings
'differences' => $differences, // array of different strings from two translations
'extra' => array(),
'dup_str' => array(),
);
}
/**
* Diff English and translated ts files, to get:
* - source (ts) strings count
* - missing strings in target
* - untranslated strings in target
* - empty array for extra and duplicate strings for backward compatibility
*
* @param string $locale locale name ('sl')
* @param string $resource file name ('mageiaSync')
* @param array $source_l array with source file strings (to avoid duplicated parsing)
* @param string $path directly passed path for nonlocal files
*
* @return array
*/
function _ts_diff($locale, $resource, $source_l = NULL, $path = NULL)
{
$source_path_filename = sprintf('%s%s_%s.ts', $path, $resource, $locale); // mageiaSync_sl.ts
$source_strings = array();
$untranslated_strings = array();
$obsoleted_strings = array();
// read .ts file
$file_handle = @fopen($source_path_filename, 'r');
if ($file_handle === false) {
// Could not open file resource
return false;
}
// iterate over lines
while(($line = fgets($file_handle, 65536)) !== false) {
// count lines
if (false !== strpos($line, '')) {
preg_match_all("/(