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();
if (FALSE != $source_l) {
foreach ($source_l as $escaped_string => $subarray) {
if (!empty($subarray["msgid"])) { // filter out header
$pot_strings[$escaped_string] = $subarray["msgid"];
}
}
}
if (FALSE != $target_l) {
foreach ($target_l as $escaped_string => $subarray) {
if (!empty($subarray["msgid"])) { // filter out header
$po_strings[$escaped_string] = $subarray["msgstr"][0];
}
}
}
foreach ($pot_strings as $escaped_string => $translated_string) {
if (isset($po_strings[$escaped_string])) {
if (empty($po_strings[$escaped_string])) {
$untrans[] = $escaped_string;
}
} else {
$fuzzy_or_missing[] = $escaped_string;
}
}
return array(
'a' => count($pot_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("/(