From 095b3d81037f5a3b3de44444845651c9c4f5c411 Mon Sep 17 00:00:00 2001
From: Romain d'Alverny
Date: Thu, 24 May 2012 13:45:06 +0000
Subject: reporting tools
---
langs/diff.php | 56 +++++++++++++++++++++
langs/lib.php | 97 ++++++++++++++++++++++++++++++++++++
langs/report.php | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 300 insertions(+)
create mode 100644 langs/diff.php
create mode 100644 langs/lib.php
create mode 100644 langs/report.php
(limited to 'langs')
diff --git a/langs/diff.php b/langs/diff.php
new file mode 100644
index 000000000..f0518d5ad
--- /dev/null
+++ b/langs/diff.php
@@ -0,0 +1,56 @@
+« back to langs report';
+$s .= "Diff {$source_file} ({$diff['a']}) against {$target_file} ({$diff['b']})
";
+
+foreach (array('missing', 'notrans', 'extra') as $type) {
+
+ if (count($diff[$type]) > 0) {
+ $s .= sprintf('%d %s:
', count($diff[$type]), $type);
+ foreach ($diff[$type] as $l)
+ $s .= sprintf('%s
', htmlentities($l));
+ }
+}
+
+?>
+
+
+
+
+
+
+
+
+
+
+
diff --git a/langs/lib.php b/langs/lib.php
new file mode 100644
index 000000000..86b13bf6f
--- /dev/null
+++ b/langs/lib.php
@@ -0,0 +1,97 @@
+ count($fa),
+ 'bCount' => count($fb),
+ 'diff' => count($fa) - count($fb),
+ );
+ $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 . ': ' . $v;
+ }
+ }
+ }
+
+ return array(
+ 'a' => count($fa),
+ 'b' => count($fb),
+ 'missing' => $missing,
+ 'notrans' => $notrans,
+ 'extra' => $extra
+ );
+}
+
+
+if ( ! function_exists('glob_recursive'))
+{
+ // Does not support flag GLOB_BRACE
+
+ function glob_recursive($pattern, $flags = 0)
+ {
+ $files = glob($pattern, $flags);
+
+ foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
+ {
+ $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
+ }
+
+ return $files;
+ }
+}
+
+function _lang_file_switch($s, $l)
+{
+ return $l . substr(str_replace('.en.lang', '.' . $l . '.lang', $s), 2);
+}
+
+function get_lang_references()
+{
+ return glob_recursive('en/*', GLOB_MARK);
+}
+
+function get_other_langs()
+{
+ $ls = glob('*');
+ $re = array();
+ foreach ($ls as $l) {
+ if (!is_dir($l)) continue;
+ if ($l == 'en') continue;
+ $re[] = $l;
+ }
+ array_unshift($re, 'en');
+ return $re;
+}
\ No newline at end of file
diff --git a/langs/report.php b/langs/report.php
new file mode 100644
index 000000000..e85652aa2
--- /dev/null
+++ b/langs/report.php
@@ -0,0 +1,147 @@
+
+
+
+
+
+ www.mageia.org translation report
+
+
+
+
+
+ - TODO article/link on the Wiki: How to translate this Web site?
+
+
+ Report
+ ';
+
+ $s = '';
+ foreach ($enFiles as $f) {
+
+ if (is_dir($f)) continue;
+
+ $stats['en']['files'] += 1;
+
+ $s .= sprintf('%s | ',
+ $f, $f);
+
+ foreach ($otherLangs as $l) {
+
+ $langF = str_replace('.en.lang', '.' . $l . '.lang', $f);
+ $langF = $l . substr($langF, 2);
+
+ if (file_exists($langF)) {
+
+ $stats[$l]['files'] += 1;
+
+ $test = _lang_diff($f, $langF);
+
+ if (count($test['missing']) === 0
+ && count($test['notrans']) === 0) {
+
+ $extra = null;
+ if (count($test['extra']) > 0) {
+ $extra = '' . sprintf($diff_link, $f, $l) . '(+' . count($test['extra']) . ')';
+ }
+
+ $s .= sprintf('OK%s | ',
+ $langF, $extra);
+ }
+ else {
+ // special case, en
+ if ($l == 'en') {
+ $s .= '' . count($test['notrans']) . ' strings | ';
+ $stats['en']['strings'] += $test['a'];
+ $enStringsCount[$f] += $test['a'];
+
+ // regular case
+ } else {
+
+ $s .= sprintf('' . $diff_link,
+ $f, $l);
+
+ if (count($test['missing']) > 0) {
+ $s .= count($test['missing']) . ' missing';
+ }
+ if (count($test['notrans']) > 0) {
+ $s .= count($test['notrans']) . ' untranslated';
+ }
+ $s .= ' | ';
+ }
+ }
+ $stats[$l]['strings'] += $test['b'];
+
+ } else {
+ $stats[$l]['files'] += 0;
+ $stats[$l]['strings'] += 0;
+ $s .= 'missing | ';
+ }
+ }
+ $s .= '
';
+ }
+
+ $th = '';
+ array_shift($otherLangs);
+ foreach ($otherLangs as $l) {
+ $th .= '' . $langs[$l] . ' ' . $l . ' | ';
+ }
+
+ $ths = '';
+ foreach ($stats as $l => $data) {
+ if ($l == 'en') continue;
+ $ths .= '' . $data['files'] . ' / ' . $data['strings'] . ' ' . round($data['strings'] / $stats['en']['strings'] * 100). '% | ';
+ }
+
+ echo <<
+
+
+ English |
+ {$th}
+ How to add a new language |
+
+
+ Reference |
+
+
+ {$stats['en']['files']} files |
+ {$stats['en']['strings']} strings |
+ {$ths}
+
+
+
+{$s}
+
+
+
+
+S;
+?>
+
+
\ No newline at end of file
--
cgit v1.2.1