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
*
* @return array
*/
function _po_diff($locale, $resource, $source_l = NULL, $path = 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 ('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);
}
}
$pot_strings = array();
$untrans = array();
$fuzzy_or_missing = array();
$num_of_original_strings = 0;
if (FALSE != $source_l) {
foreach ($source_l as $escaped_string => $subarray) {
if (!empty($escaped_string)) { // filter out header
$msgctxt = array();
foreach ($subarray[0] as $key => $unused) {
if (isset($subarray["msgctxt"][$key])) {
$msgctxt[$key] = $subarray["msgctxt"][$key];
} else {
$msgctxt[$key] = TRUE;
}
$num_of_original_strings++;
}
$pot_strings[$escaped_string] = $msgctxt;
}
}
}
$fuzzy_or_missing = $pot_strings;
$untrans = $pot_strings;
if (FALSE != $target_l) {
foreach ($target_l as $escaped_string => $subarray) {
if (!empty($escaped_string)) { // filter out header
foreach ($subarray[0] as $key => $msgstr) {
// remove present string
unset($fuzzy_or_missing[$escaped_string][$key]);
if (!empty($msgstr)) {
// remove translated string
if(is_array($msgstr)) { // are there any plural strings present?
$erase_plural_key = TRUE;
foreach ($msgstr as $nplural) {
if (empty($nplural)) {
$erase_plural_key = FALSE;
}
}
// if all plural keys are translated, remove msgstr for that msgid
if ($erase_plural_key) {
unset($untrans[$escaped_string][$key]);
}
} else {
unset($untrans[$escaped_string][$key]);
}
}
}
}
}
}
$arrays = array($fuzzy_or_missing, $untrans);
foreach ($arrays as &$current_array) {
$strings = array();
$cnt = 0;
foreach ($current_array as $escaped_string => $msgctxt) {
if(!empty($msgctxt)) {
$keys = array_keys($msgctxt);
if(is_numeric($keys[0])) {
$index = $cnt;
} else {
$index = $keys[0];
}
$strings[$index] = $escaped_string;
$cnt++;
}
}
$current_array = $strings;
}
unset($current_array);
list($fuzzy_or_missing, $untrans) = $arrays;
$untrans = array_diff($untrans, $fuzzy_or_missing);
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
'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("/(