summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorJonas Häggqvist <rasher@rasher.dk>2010-01-31 00:44:07 +0000
committerJonas Häggqvist <rasher@rasher.dk>2010-01-31 00:44:07 +0000
commit31ca70b0400e807911ec910e444788f0728bcc12 (patch)
tree8227b3b87f412a1e2372c999c52b04b788939dda /index.php
parenta3e83b59437b2499ce65dc854198dd98d6abbe40 (diff)
downloadtranslate-31ca70b0400e807911ec910e444788f0728bcc12.tar.gz
translate-31ca70b0400e807911ec910e444788f0728bcc12.zip
Convert the frontpage to use smarty rather than terrible mixed code/layout.
git-svn-id: svn://svn.rockbox.org/rockbox/translate.rockbox.org@24393 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'index.php')
-rw-r--r--index.php248
1 files changed, 42 insertions, 206 deletions
diff --git a/index.php b/index.php
index c5e966a..a3968fa 100644
--- a/index.php
+++ b/index.php
@@ -2,237 +2,73 @@
error_reporting(E_ALL);
require_once('common.php');
-function qs($count) {
- return $count == 1 ? '' : 's';
-}
-
-function simpleduration($seconds) {
- $one_hour = 60*60;
- $one_day = 24*$one_hour;
- if ($seconds > 60*28 && $seconds < 60*32) {
- return "half an hour ago";
- }
- elseif ($seconds < $one_hour) {
- $minutes = floor($seconds/60);
- return sprintf("%d minute%s ago", $minutes, qs($minutes));
- }
- elseif ($seconds < $one_day) {
- $hours = floor($seconds/$one_hour);
- return sprintf("%d hour%s ago", $hours, qs($hours));
- }
- elseif ($seconds < 2*$one_day) {
- return "Yesterday";
- }
- elseif ($seconds < 7*$one_day) {
- $days = floor($seconds/$one_day);
- return sprintf("%d day%s ago", $days, qs($days));
- }
- elseif ($seconds < 2*30*$one_day) {
- $weeks = floor($seconds/(7*$one_day));
- return sprintf("%d week%s ago", $weeks, qs($weeks));
- }
- elseif ($seconds < 365*$one_day) {
- $months = floor($seconds/(30*$one_day));
- return sprintf("%d month%s ago", $months, qs($months));
- }
- else {
- $years = floor($seconds/(365*$one_day));
- return sprintf("%d year%s ago", $years, qs($years));
- }
-}
-
-function show_stats() {
- $languageinfo = languageinfo();
-
- $stats = (file_exists(STATS) ? unserialize(file_get_contents(STATS)) : array());
- ksort($stats);
- //*
function langsort($a, $b) {
// Sort by Name
$ap = $a['name'];
$bp = $b['name'];
// Sort by last update revision
- $ap = $a['Last update rev'];
- $bp = $b['Last update rev'];
+ $ap = $a['last_update_rev'];
+ $bp = $b['last_update_rev'];
// Sort by status
- $ap = ($a['Total strings'] - $a['Missing strings']) / $a['Total strings'];
- $bp = ($b['Total strings'] - $b['Missing strings']) / $b['Total strings'];
+ $ap = $a['percentage'];
+ $bp = $b['percentage'];
- $ac = $a['Changed desc'] + $a['Changed source'];
- $bc = $b['Changed desc'] + $b['Changed source'];
+ $ac = $a['desc'] + $a['source'];
+ $bc = $b['desc'] + $b['source'];
if ($ap == $bp) {
if ($ac != $bc) {
- return $ac < $bc ? -1 : 1;
+ return $ac > $bc ? -1 : 1;
}
else {
- return $a['name'] < $b['name'] ? -1 : 1;
+ return $a['name'] > $b['name'] ? -1 : 1;
}
}
return $ap < $bp ? 1 : -1;
}
- uasort($stats, 'langsort');
- //*/
-
- $langs = array();
- $versions = (file_exists(VERSIONS) ? file(VERSIONS) : array());
- foreach($versions as $line) {
- list($lang, $version) = explode(":", trim($line));
- $langs[$lang] = $version;
- }
-
- echo <<<END
-<h1>Rockbox translations</h1>
-<p>
-On this page you can see the current status of the various Rockbox translations.
-Ideally, all languages below should be at 100%. In reality though, this is not
-the case. You can help remedy this situation by clicking on the name of a
-language you speak and help translate Rockbox all within the comfort of your
-webbrowser. Alternatively, you can go to <a
-href="http://www.rockbox.org/twiki/bin/view/Main/LangFiles">this page</a> in the
-Rockbox wiki, which will tell you how to update languages the more manual, but
-possibly slightly safer way.
-</p>
-
-<h2>Current translation status</h2>
-<!--
+function get_stats() {
+ $languageinfo = languageinfo();
+ $stats['langstats'] = (file_exists(STATS) ? unserialize(file_get_contents(STATS)) : array());
+ $stats['summary'] = array('complete' => 0, 'good' => 0, 'normal' => 0, 'bad' => 0);
+ foreach($stats['langstats'] as $name => &$info) {
+ if ($name == 'summary') continue;
+ $info['percentage'] = ($info['total'] - $info['missing']) / $info['total'] * 100;
+ if (isset($languageinfo[$name])) {
+ $info = array_merge($info, $languageinfo[$name]);
+ }
+ // Set some defaults
+ else {
+ $info = array_merge($info, array(
+ 'name' => ucfirst($info['name']),
+ 'flag' => 'unknown',
+ 'code' => 'xx',
+ 'rtl' => 0,
+ ));
+ }
-END;
- $complete = 0;
- $good = 0;
- $normal = 0;
- $bad = 0;
- foreach($stats as $lang => $stat) {
- $percentage = ($stat['Total strings'] - $stat['Missing strings']) / $stat['Total strings'] * 100;
- $lang = isset($languageinfo[$lang]['name']) ? strip_tags($languageinfo[$lang]['name']) : ucfirst(strtolower($lang));
+ /* Count this language into the summary */
switch(true) {
- case $percentage == 100 && $stat['Changed source'] == 0 && $stat['Changed desc'] == 0:
- printf("COMPLETE: %3d%% - %s\n", $percentage, $lang);
- $complete++;
+ case $info['percentage'] == 100
+ && $info['source'] == 0
+ && $info['desc'] == 0:
+ $stats['summary']['complete']++;
break;
- case $percentage > 95;
- printf("GOOD: %3d%% - %s\n", $percentage, $lang);
- $good++;
+ case $info['percentage'] > 95;
+ $stats['summary']['good']++;
break;
- case $percentage > 50;
- printf("NORMAL: %3d%% - %s\n", $percentage, $lang);
- $normal++;
+ case $info['percentage'] > 50;
+ $stats['summary']['normal']++;
break;
default:
- printf("BAD: %3d%% - %s\n", $percentage, $lang);
- $bad++;
+ $stats['summary']['bad']++;
break;
}
}
- printf("-->\n<p>\n\t<ul>\n\t\t<li>%d complete translations</li>\n\t\t<li>%d good translations (&gt;95%% translated)</li>\n\t\t<li>%d decent translations (&gt;50%% translated)</li>\n\t\t<li>%d bad translations (&lt;50%% translated)</li>\n\t</ul>\n</p>\n\n", $complete, $good, $normal, $bad);
- echo <<<END
-<table>
- <thead>
- <tr>
- <td colspan='4'>Language</td>
- <td>Last update</td>
- <td>Progress</td>
- <td>Missing strings</td>
- <td>Changed description</td>
- <td>Changed source</td>
- </tr>
- </thead>
-END;
- foreach($stats as $lang => $stat) {
- $percentage = ($stat['Total strings'] - $stat['Missing strings']) / $stat['Total strings'] * 100;
- $img = isset($languageinfo[$lang]['flag']) && $languageinfo[$lang]['flag'] != '' && file_exists('flags/'.SMALL_FLAGSIZE.'/'.$languageinfo[$lang]['flag'].'.png') ? sprintf('<img class="flagthumb" src="flags/'.SMALL_FLAGSIZE.'/%s.png" %s />', $languageinfo[$lang]['flag'], array_pop(array_slice(getimagesize('flags/'.SMALL_FLAGSIZE.'/'.$languageinfo[$lang]['flag'].'.png'), 3, 1))) : '';
- if ($stat['Missing strings'] == 0 && $stat['Changed desc'] == 0 && $stat['Changed source'] == 0) {
- $format = "<tr class='good'><td>%s</td><td><a href='problems.php?lang=%s'><img style='border: none' src='warning.gif' width='16' height='16' /></td><td><a href='graphs/%s.png'><img style='border: none' src='graph.png' width='16' height='16' /></td><td><a href='edit.php?lang=%s'></a>%s</td><td><a href='http://svn.rockbox.org/viewvc.cgi?view=rev&revision=%d' title='%s'>%s</a></td><td><img title='%.2f%%' src='graph.php?p=%.2f'></td><td align='right'>%d</td><td align='right'>%d</td><td align='right'>%d</td></tr>\n";
- }
- elseif ($percentage < 50) {
- $format = "<tr class='poor'><td>%s</td><td><a href='problems.php?lang=%s'><img style='border: none' src='warning.gif' width='16' height='16' /></td><td><a href='graphs/%s.png'><img style='border: none' src='graph.png' width='16' height='16' /></td><td><a href='edit.php?lang=%s'>%s</a></td><td><a href='http://svn.rockbox.org/viewvc.cgi?view=rev&revision=%d' title='%s'>%s</a></td><td><img title='%.2f%%' src='graph.php?p=%.2f'></td><td align='right'>%d</td><td align='right'>%d</td><td align='right'>%d</td></tr>\n";
- }
- else {
- $format = "<tr><td>%s</td><td><a href='problems.php?lang=%s'><img style='border: none' src='warning.gif' width='16' height='16' /></td><td><a href='graphs/%s.png'><img style='border: none' src='graph.png' width='16' height='16' /></td><td><a href='edit.php?lang=%s'>%s</a></td><td><a href='http://svn.rockbox.org/viewvc.cgi?view=rev&revision=%d' title='%s'>%s</a></td><td><img title='%.2f%%' src='graph.php?p=%.2f'></td><td align='right'>%d</td><td align='right'>%d</td><td align='right'>%d</td></tr>\n";
- }
- printf($format,
- $img,
- $lang, $lang, $lang,
- isset($languageinfo[$lang]['name']) ? $languageinfo[$lang]['name'] : ucfirst(strtolower($lang)),
- $stat['Last update rev'],
- date(DATE_RFC2822, $stat['Last update']),
- simpleduration(time() - $stat['Last update']),
- $percentage,
- $percentage,
- $stat['Missing strings'],
- $stat['Changed desc'],
- $stat['Changed source']
- );
- }
- print("</table>");
-
-
- echo <<<END
-<h2>Perform automated cleanup</h2>
-<p>Using the form below, it's possible to perform automated cleanups of a
-translation. Be aware though, that this might produce unwanted results in some
-cases, so you're required to check the results rather than blindly trusting
-them.</p>
-
-<form action="fixlang.php" method="GET">
-<table>
- <tr>
- <td>Language</td>
- <td>
- <select name="lang">
-END;
- ksort($stats);
- foreach($stats as $lang => $stat) {
- printf(" <option value='%s'>%s</option>\n", $lang, $languageinfo[$lang]['name']);
- }
-echo <<<END
- </select>
- </td>
- </tr>
-END;
- $foo = array(
- array(
- 'id' => "voice",
- 'name' => "Copy voice strings",
- 'title' => "Copy translation to voice for phrases where string and voice are the same in the English language file"
- ),
- array(
- 'id' => "empty",
- 'name' => "Fix empty strings",
- 'title' => "Make empty and \"none\" strings match the English language file"
- ),
- array(
- 'id' => "sort",
- 'name' => "Sort in English order",
- 'title' => "Sort phrases in the same order as the English language file"
- ),
- array(
- 'id' => "sendfile",
- 'name' => "Save result as file",
- 'title' => "Prompt to save the result on disk"
- )
- );
- foreach($foo as $row) {
- // ;
- printf("<tr><td><label for='%s' title='%s'>%s</label></td><td><input type='checkbox' id='%s', name='%s' title='%s' /></td></tr>\n",
- $row['id'],
- $row['title'],
- $row['name'],
- $row['id'],
- $row['id'],
- $row['title']
- );
- }
-echo <<<END
- <tr>
- <td align="right" colspan="2"><input type="submit" /></td>
- </tr>
-</table>
-</form>
-END;
+ uasort($stats['langstats'], 'langsort');
+ return $stats;
}
+
-print_head();
-show_stats();
-print_foot();
+$stats = get_stats();
+$smarty->render('frontpage.tpl', $stats);
?>