$value) {
$current_key = $key;
if ($needle === $value OR (is_array($value) && recursive_array_search($needle, $value) !== FALSE)) {
return $current_key;
}
}
return FALSE;
}
include 'lib.php';
$one_language = isset($_GET['l']) ? strip_tags(trim($_GET['l'])) : NULL;
$one_resource = isset($_GET['r']) ? strip_tags(trim($_GET['r'])) : NULL;
$one_language_all_resources = FALSE;
$all_languages_only_one_resource = FALSE;
if (isset($one_language) && $one_language != 'all') {
$one_language_all_resources = TRUE;
$otherLangs = array('en', $one_language);
} else {
$otherLangs = get_other_langs();
}
if (isset($one_resource) && $one_resource != 'all') {
$all_languages_only_one_resource = TRUE;
$enFiles = array($one_resource);
} else {
$enFiles = array_merge(array('../_nav/langs/en.pot'), get_lang_references('*.pot')); // added navigation file
}
$num_of_enFiles = count($enFiles);
$report = array();
$ok_link = '
';
$diff_link = '
%s
';
$add_trans = '';
$unique_lines_in_eng_constitution = array();
$number_of_unique_lines_in_eng_constitution = 0;
foreach ($otherLangs as $l) {
foreach ($enFiles as $f) {
$references = '';
$page_not_linked = '';
$old_page = '';
$resource = _extract_resource($f);
$resource_filename = str_replace('index', '', $resource);
$mga = array('view page' => $resource_filename);
$langF = _po_file_switch($f, $l);
if (strstr($f, '../_nav/langs/en.') !== FALSE) {
$nav = TRUE;
$dest_en = sprintf('%s/%s/%s', G_APP_ROOT, '_nav/langs', 'en.pot');
$dest_l = sprintf('%s/%s/%s', G_APP_ROOT, '_nav/langs', $l . '.po');
$langF = '../_nav/langs/' . $l . '.po' . (($l == 'en') ? 't' : '');
} else {
$nav = FALSE;
$dest_en = sprintf('%s/%s/%s/%s', G_APP_ROOT, 'en', $resource_filename, 'index.php');
$dest_l = sprintf('%s/%s/%s/%s', G_APP_ROOT, $l, $resource_filename, 'index.php');
}
// if symlink e.g. does directly translated page exist?
if ((realpath($dest_l) != realpath($dest_en)) && !$nav) {
$page_not_linked = sprintf('old page still exists!', $l, $resource_filename);
$old_page = sprintf(' by recycling
old page', $l, $resource_filename);
}
$add_new_translation = sprintf($add_trans, $f, $l, $old_page);
if (file_exists($langF)) {
$test = _po_diff($l, $resource);
$num_of_fuzzy_or_missing_strings = count($test['fuzzy_or_missing']);
$num_of_untranslated_strings = count($test['notrans']);
if ($nav) {
$mga = array('see navigation' => '');
} else if ($resource_filename == 'downloads/get') {
$mga = array(
'view page A' => 'downloads/get/index.php?q=Mageia-2-dual-CD.iso&d=1',
'B' => 'downloads/get/index.php?q=Non_existing_file&d=1',
);
} else if ($resource_filename == '2') {
$mga = array(
'view page A' => '2/index.php',
'B' => '2/download_index.php',
'C' => '2/for-pc/index.php',
'D' => '2/for-server/index.php',
);
} else if ($resource_filename == '3') {
$mga = array(
'view page A' => '3/index.php',
'B' => '3/download_index.php',
'C' => '3/for-pc/index.php',
'D' => '3/for-server/index.php',
);
} else if ($resource_filename == '4') {
$mga = array(
'view page A' => '4/index.php',
'B' => '4/download_index.php',
);
} else if ($resource_filename == 'cauldron') {
$mga = array('view page' => '5/download_index.php');
} else if ($resource_filename == 'documentation') {
$mga = array(
'view page doc' => 'doc/index.php',
'archive' => 'doc/archive.php',
);
} else if ($resource_filename == 'about/constitution') {
$constitution_results = aproximate_number_of_untranslated_constitution_lines(G_APP_ROOT, $l, $unique_lines_in_eng_constitution);
if ($l == 'en') {
$unique_lines_in_eng_constitution = $constitution_results['unique_lines_in_constitution'];
$number_of_unique_lines_in_eng_constitution = count($unique_lines_in_eng_constitution);
}
$test['a'] += $number_of_unique_lines_in_eng_constitution; // add aproximate number of lines from constitution to translate
$num_of_untranslated_strings += $constitution_results['aproximate_number_of_untranslated_lines'];
} else if ($resource_filename == 'about/license') {
require_once('../en/about/license/license.php');
$license_numbers = load_license_numbers($l, TRUE);
if ($l == 'en') {
$number_of_unique_lines_in_eng_license = $license_numbers["all"];
}
$test['a'] += $license_numbers["all"]; // add aproximate number of untranslated sentences from license
$num_of_untranslated_strings += $license_numbers["untran"]; // add number of all license sentences
}
$link = '';
foreach ($mga as $k => $v) {
$link .= sprintf('
%s', $l, $v, $k);
}
$link .= $page_not_linked; // . '
';
if ($num_of_fuzzy_or_missing_strings === 0 && $num_of_untranslated_strings === 0) {
$references .= sprintf($ok_link, $link, $langF);
} else {
if(($num_of_fuzzy_or_missing_strings + $num_of_untranslated_strings) < $test['a']) {
$references .= sprintf($diff_link, $link, $f, $l);
$fuzzy = FALSE;
if ($num_of_fuzzy_or_missing_strings > 0) {
$references .= $num_of_fuzzy_or_missing_strings . ' fuzzy or missing';
$fuzzy = TRUE;
}
if ($num_of_untranslated_strings > 0) {
$references .= ($fuzzy ? ', ' : '') . $num_of_untranslated_strings . ' untranslated';
}
$references .= '
';
} else {
$references .= $add_new_translation;
}
}
} else { // file $langF doesn't exists
$references .= $add_new_translation;
$test = _po_diff('en', $resource);
$num_of_fuzzy_or_missing_strings = 0;
$num_of_untranslated_strings = count($test['notrans']);
if ($resource_filename == 'about/constitution') { // add aproximate number of all lines from constitution
$test['a'] += $number_of_unique_lines_in_eng_constitution;
$num_of_untranslated_strings += $number_of_unique_lines_in_eng_constitution;
}
if ($resource_filename == 'about/license') { // add number of all license sentences
$test['a'] += $number_of_unique_lines_in_eng_license;
$num_of_untranslated_strings += $number_of_unique_lines_in_eng_license;
}
}
$report[] = array(
'language' => $l,
'resource_filename' => $f,
'num_of_all_strings' => $test['a'],
'num_of_fuzzy_or_missing_strings' => $num_of_fuzzy_or_missing_strings,
'num_of_untranslated_strings' => $num_of_untranslated_strings,
'references' => $references,
);
}
}
$total_num_of_strings = 0; // total of all source strings
$language_summary = array();
$resource_summary = array();
foreach ($report as $resource_data) {
if ($resource_data['language'] == 'en') {
$total_num_of_strings += $resource_data['num_of_all_strings'];
}
// don't add if there is a need to store languages only for one resource
if(!$all_languages_only_one_resource || $resource_data['resource_filename'] == $one_resource) {
$key_exists = recursive_array_search($resource_data['language'], $language_summary); // is language already in the $language_summary array?
if($resource_data['resource_filename'] == $one_resource) {
$temp_var[0]['language'] = $resource_data['language'];
$temp_var[0]['num_of_all_strings'] = $resource_data['num_of_all_strings'];
$temp_var[0]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
$temp_var[0]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
$temp_var[0]['references'] = $resource_data['references'];
$language_summary[] = $temp_var[0];
unset($temp_var[0]); // clear var
} else {
if ($key_exists !== FALSE) {
$language_summary[$key_exists]['num_of_all_strings'] += $resource_data['num_of_all_strings'];
$language_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] += $resource_data['num_of_fuzzy_or_missing_strings'];
$language_summary[$key_exists]['num_of_untranslated_strings'] += $resource_data['num_of_untranslated_strings'];
} else {
if($key_exists === FALSE) {
$key_exists = count($language_summary);
}
$language_summary[$key_exists]['language'] = $resource_data['language'];
$language_summary[$key_exists]['num_of_all_strings'] = $resource_data['num_of_all_strings'];
$language_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
$language_summary[$key_exists]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
$language_summary[$key_exists]['references'] = $resource_data['references'];
}
}
}
// don't add if there is a need to store resources only for one language
if(!$one_language_all_resources || ($resource_data['language'] == $one_language || $resource_data['language'] == 'en')) {
$key_exists = recursive_array_search($resource_data['resource_filename'], $resource_summary); // is resource already in the $resource_summary array?
if($resource_data['language'] == 'en') {
$temp_var[0]['resource_filename'] = $resource_data['resource_filename'];
$temp_var[0]['num_of_all_strings'] = $resource_data['num_of_all_strings'];
$temp_var[0]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
$temp_var[0]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
$temp_var[0]['references'] = $resource_data['references'];
$resource_summary[] = $temp_var[0];
unset($temp_var[0]); // clear var
} else {
if($one_language_all_resources) {
if($key_exists === FALSE) {
$key_exists = count($resource_summary);
}
$resource_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
$resource_summary[$key_exists]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
$resource_summary[$key_exists]['references'] = $resource_data['references'];
} else if ($key_exists !== FALSE) {
$resource_summary[$key_exists]['num_of_all_strings'] += $resource_data['num_of_all_strings'];
$resource_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] += $resource_data['num_of_fuzzy_or_missing_strings'];
$resource_summary[$key_exists]['num_of_untranslated_strings'] += $resource_data['num_of_untranslated_strings'];
}
}
}
}
foreach ($language_summary as &$single_language_summary) {
$single_language_summary['num_of_translated_strings'] =
$single_language_summary['num_of_all_strings'] -
$single_language_summary['num_of_fuzzy_or_missing_strings'] -
$single_language_summary['num_of_untranslated_strings'];
}
unset($single_language_summary); // foreach by reference
foreach ($resource_summary as &$single_resource_summary) {
$single_resource_summary['num_of_translated_strings'] =
$single_resource_summary['num_of_all_strings'] -
$single_resource_summary['num_of_fuzzy_or_missing_strings'] -
$single_resource_summary['num_of_untranslated_strings'];
}
unset($single_resource_summary); // foreach by reference
if ($one_language_all_resources) {
$report_text = '