aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--langs/diff.php56
-rw-r--r--langs/lib.php97
-rw-r--r--langs/report.php147
3 files changed, 300 insertions, 0 deletions
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 @@
+<?php
+/**
+ * Report the diff of 's' file
+ * against matching file in language 'l', if it exists.
+*/
+
+$source_file = isset($_GET['s']) ? trim($_GET['s']) : null;
+$target_lang = isset($_GET['l']) ? trim($_GET['l']) : null;
+
+if (is_null($source_file) ||
+ is_null($target_lang)) {
+
+ die('kthxbai');
+}
+
+if (!file_exists($source_file)) {
+ die('no source');
+}
+
+include 'lib.php';
+include '../langs.inc.php';
+
+$target_file = _lang_file_switch($source_file, $target_lang);
+
+if (!file_exists($target_file)) {
+ die('no target');
+}
+
+$diff = _lang_diff($source_file, $target_file);
+
+$s = '<a href="report.php">&laquo; back to langs report</a>';
+$s .= "<h1>Diff {$source_file} ({$diff['a']}) against {$target_file} ({$diff['b']})</h1>";
+
+foreach (array('missing', 'notrans', 'extra') as $type) {
+
+ if (count($diff[$type]) > 0) {
+ $s .= sprintf('<h2>%d %s:</h2>', count($diff[$type]), $type);
+ foreach ($diff[$type] as $l)
+ $s .= sprintf('<blockquote><p><pre>%s</pre></p></blockquote>', htmlentities($l));
+ }
+}
+
+?><!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="robot" content="noindex,nofollow,nosnippet">
+ <style>
+ blockquote { background: #eee; padding: 0.1em 1em; }
+ </style>
+</head>
+<body>
+ <?php echo $s; ?>
+<hr>
+</body>
+</html>
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 @@
+<?php
+/**
+*/
+
+include '../langs.inc.php';
+
+/**
+ * Diff two .lang files, to get:
+ * - strings count of each
+ * - missing strings (in $a, not in $b)
+ * - extra strings (in $b, not in $a)
+ * - untranslated strings (same in $a and $b, or empty in $b)
+ *
+ * @param string $a file name
+ * @param string $b file name
+ *
+ * @return array
+ *
+ * @todo some strings may be left untranslated on purpose
+*/
+function _lang_diff($a, $b)
+{
+ $fa = _lang_return($a);
+ $fb = _lang_return($b);
+
+ $ret = array(
+ 'aCount' => 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 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="robots" content="noindex,nofollow,nosnippet">
+ <title>www.mageia.org translation report</title>
+ <style>
+ .ok a,
+ .strings a,
+ .missing a {
+ text-decoration: none;
+ color: inherit;
+ }
+ .ok { color: darkgreen; background: lightgreen; text-align: center; }
+ .strings { background: orange; }
+ .missing { background: darkorange; }
+ .strings, .missing { font-size: 80%; }
+ .number, .strings, .missing { text-align: right; }
+ .small { font-size: 80%; }
+
+ </style>
+</head>
+<body>
+ <h1><a href="//www.mageia.org/">www.mageia.org</a> translation report</h1>
+ <ul>
+ <li>TODO article/link on the Wiki: How to translate this Web site?</li>
+ </ul>
+ <hr>
+ <h2>Report</h2>
+ <?php
+ /**
+ */
+ include 'lib.php';
+
+ $enFiles = get_lang_references();
+ $otherLangs = get_other_langs();
+
+ $enStringsCount = array();
+ $report = array();
+ $stats = array();
+
+ $diff_link = '<a href="diff.php?s=%s&l=%s" title="see detailed diff">';
+
+ $s = '';
+ foreach ($enFiles as $f) {
+
+ if (is_dir($f)) continue;
+
+ $stats['en']['files'] += 1;
+
+ $s .= sprintf('<tr><td><a href="%s">%s</a></td>',
+ $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 = '<span class="small">' . sprintf($diff_link, $f, $l) . '(+' . count($test['extra']) . ')</a></span>';
+ }
+
+ $s .= sprintf('<td class="ok"><a href="%s" title="get a copy of the file">OK</a>%s</td>',
+ $langF, $extra);
+ }
+ else {
+ // special case, en
+ if ($l == 'en') {
+ $s .= '<td class="number">' . count($test['notrans']) . ' strings</td>';
+ $stats['en']['strings'] += $test['a'];
+ $enStringsCount[$f] += $test['a'];
+
+ // regular case
+ } else {
+
+ $s .= sprintf('<td class="strings">' . $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 .= '</a></td>';
+ }
+ }
+ $stats[$l]['strings'] += $test['b'];
+
+ } else {
+ $stats[$l]['files'] += 0;
+ $stats[$l]['strings'] += 0;
+ $s .= '<td class="missing">missing</td>';
+ }
+ }
+ $s .= '</tr>';
+ }
+
+ $th = '';
+ array_shift($otherLangs);
+ foreach ($otherLangs as $l) {
+ $th .= '<th>' . $langs[$l] . '<br>' . $l . '</th>';
+ }
+
+ $ths = '';
+ foreach ($stats as $l => $data) {
+ if ($l == 'en') continue;
+ $ths .= '<th>' . $data['files'] . ' / ' . $data['strings'] . '<br>' . round($data['strings'] / $stats['en']['strings'] * 100). '%</th>';
+ }
+
+ echo <<<S
+<table border="1">
+<thead>
+ <tr>
+ <th colspan="2">English</th>
+ {$th}
+ <th><a href="">How to add a new language</a></th>
+ </tr>
+ <tr>
+ <th colspan="2">Reference</th>
+ </tr>
+ <tr>
+ <th>{$stats['en']['files']} files</th>
+ <th col="scol">{$stats['en']['strings']} strings</th>
+ {$ths}
+ </tr>
+</thead>
+<tbody>
+{$s}
+</tbody>
+</table>
+
+<hr>
+S;
+?>
+</body>
+</html> \ No newline at end of file