';
$languages = array();
foreach ($otherLangs as $l) {
$stats['en']['files'] += 1;
$stats[$l]['files'] = 0;
$stats[$l]['strings'] = 0;
$s = sprintf('
%s %s | ',
$langs[$l], $l);
$cols = '';
foreach ($enFiles as $f) {
$enStringsCount[$f] = 0;
if ($f == '../_nav/langs/en.lang') {
$nav = true;
} else {
$nav = false;
}
$langF = str_replace('.en.lang', '.' . $l . '.lang', $f);
if ($nav) {
$langF = '../_nav/langs/' . $l . '.lang';
} else {
$langF = $l . substr($langF, 2);
}
$link = str_replace(array('en/', '.en.lang', 'index'), '', $f);
if ($nav) {
$dest_en = sprintf('%s/%s/%s', APP_ROOT, '_nav/langs', 'en.lang');
$dest_l = sprintf('%s/%s/%s', APP_ROOT, '_nav/langs', $l . '.lang');
} else {
$dest_en = sprintf('%s/%s/%s/%s', APP_ROOT, 'en', $link, 'index.php');
$dest_l = sprintf('%s/%s/%s/%s', APP_ROOT, $l, $link, 'index.php');
}
// if symlink e.g. does directly translated page exist?
if ((realpath($dest_l) == realpath($dest_en)) || $nav) {
$page_not_linked = '';
$old_page = '';
} else {
$page_not_linked = sprintf('old page still exists!', $l, $link);
$old_page = sprintf('by recycling old page', $l, $link);
}
if (file_exists($langF)) {
$stats[$l]['files'] += 1;
$test = _lang_diff($f, $langF);
$num_of_untranslated_strings = count($test['notrans']);
if ($link == 'about/constitution') {
$dest_constitution = sprintf('%s/%s/%s/%s_%s.md', APP_ROOT, $l, 'about/constitution', 'mageia.org_statutes', $l);
if ($l == 'en') {
$strings_en_constitution = count(array_unique(file($dest_constitution)));
}
$test['a'] += $strings_en_constitution; // add aproximate number of strings from constitution to translate
if(!is_readable($dest_constitution) || $l == 'en') {
$num_of_untranslated_strings += $strings_en_constitution; // add constitution strings as not translated
}
}
if ($nav) {
$mga = array();
$local_f = @file_get_contents('../_nav/langs/' . $l . '.lang');
$mognas_f = @file_get_contents('http://nav.mageia.org/langs/' . $l . '.lang');
if ($local_f != $mognas_f) {
$page_not_linked = 'difference in svn 1 & 2';
}
} else if ($link == 'downloads/get') {
$mga = array(
'view download OK page' => 'downloads/get/index.php?q=Mageia-2-dual-CD.iso&d=1" class="action"',
'view non existing file page' => 'downloads/get/index.php?q=Non_existing_file&d=1" class="action"',
);
} else if ($link == '2') {
$mga = array(
'A' => '2/download_index.php',
'B' => '2/for-pc/index.php',
'C' => '2/for-server/index.php',
'D' => '2/index.php',
);
} else if ($link == '3') {
$mga = array(
'A' => '3/download_index.php',
'B' => 'for-pc/index.php',
'C' => 'for-server/index.php',
'D' => '3/index.php',
);
} else {
$mga = array(
'view page' => $link,
);
}
$link = '';
foreach ($mga as $k => $v) {
$link .= sprintf('
%s', $l, $v, $k);
}
$link .= $page_not_linked . '
';
if (count($test['missing']) === 0
&& $num_of_untranslated_strings === 0) {
$extra = null;
if (count($test['extra']) > 0) {
$extra = ' ' . sprintf($diff_link, $f, $l) . '+' . count($test['extra']) . '';
}
$cols .= sprintf('OK%s%s | ',
$langF, $extra, $link);
$done = $test['a'];
} else {
// special case, en
if ($l == 'en') {
$cols .= '' . $num_of_untranslated_strings . ' strings | ';
$enStringsCount[$f] += $test['a'];
$done = $test['a'];
// regular case
} else {
$cols .= sprintf('' . $diff_link,
$f, $l);
if (count($test['missing']) > 0) {
$cols .= count($test['missing']) . ' missing ';
}
if ($num_of_untranslated_strings > 0) {
$cols .= $num_of_untranslated_strings . ' untranslated ';
}
if (count($test['extra']) > 0) {
$cols .= count($test['extra']) . ' extra';
}
$cols .= '';
$cols .= $link . ' | ';
$done = $test['a'] - $num_of_untranslated_strings - count($test['missing']);
}
}
$stats[$l]['strings'] += $done;
} else {
$cols .= sprintf('add translation%s | ',
$f, $l, $old_page
);
}
$num_clmns_to_repeat = 9;
$num_of_col++;
if ($num_of_col % $num_clmns_to_repeat == 0 && $num_of_col <= count($enFiles) - ($num_clmns_to_repeat / 3)) {
if ($l == 'en') {
$cols .= $lang_coloumn = 'Language | ';
} else {
$cols .= $lang_coloumn = sprintf('%s %s | ', $langs[$l], $l);
}
}
}
$cols .= $lang_coloumn; // last coloumn
$num_of_col = 0; // reset counter of coloumns
$progress = floor($stats[$l]['strings'] / $stats['en']['strings'] * 100);
// special case, en
if ($l == 'en') {
$s .= sprintf('%d strings | ', $stats[$l]['strings']);
// regular case
} else {
$s .= sprintf(
'%d%% %d / %d | ',
$progress,
$stats[$l]['strings'],
$stats['en']['strings']
);
}
$s .= $cols;
$s .= '
---|
' . PHP_EOL;
$languages[$stats[$l]['strings'] . '-' . $l] = $s;
}
$en_language = array_shift($languages); // shift English for proper sorting
krsort($languages, SORT_NUMERIC);
$enFiles = array_map(function ($e) { return str_replace('en/', '', $e); }, $enFiles);
// add language coloumn repeating
$lang_line = array();
$num_of_h_col = 0;
foreach ($enFiles as $lang_chunk) {
$num_of_h_col++;
$lang_line[] = $lang_chunk;
if ($num_of_h_col % $num_clmns_to_repeat == 0 && $num_of_h_col <= count($enFiles) - ($num_clmns_to_repeat / 3)) {
$lang_line[] = ' ';
}
}
$lang_line[] = ' ';// last h coloumn
$thfiles = '
' . implode(' | ', $lang_line) . ' | ' . PHP_EOL;
$count = count($otherLangs);
$chunks = array_chunk($languages, $num_lines_to_repeat = 8); // add header repeating
$table_body = array();
foreach ($chunks as $chunk) {
$table_body = array_merge($table_body, $chunk, array(count($chunk) > ($num_lines_to_repeat / 2) ? '
| File | ' . $thfiles : ''));
}
array_unshift($table_body, $en_language); // unshift English back
$s = implode($table_body);
echo <<
{$count} languages |
Progress |
{$thfiles}
{$s}
S;
?>
---|