Permalink
Browse files

Implement translation completion statistics

  • Loading branch information...
nextghost committed Jun 20, 2012
1 parent 70410a0 commit ae8b479a904a60fc8e02d6171808d344ed7addf7
Showing with 69 additions and 8 deletions.
  1. +62 −4 action.php
  2. +2 −0 lang/cs/lang.php
  3. +2 −0 lang/en/lang.php
  4. +0 −4 syntax.php
  5. +3 −0 utils.php
View
@@ -441,11 +441,30 @@ public function handle_tpl_content_display(Doku_Event &$event, $param) {
global $ID;
if (!@file_exists(metaFN($ID, '.translate'))) {
return;
}
preg_match_all('/<a [^>]* class="wikilink1" title="([^"]*)"[^>]*>/', $event->data, $out, PREG_SET_ORDER);
# Gather internal links
foreach ($out as $link) {
if (isset($status[$link[1]])) {
continue;
}
# Calculate translation status for each link
$status[$link[1]] = $this->_translationStatus($link[1]);
}
# Write translation status next to each link
while (list($key, $value) = each($status)) {
if (empty($value)) {
continue;
}
# Erase everything between markers
$event->data = preg_replace("/<!-- DOKUTRANSLATE ERASE START -->.*<!-- DOKUTRANSLATE ERASE STOP -->/sm", '', $event->data);
$event->data = preg_replace("#<a ([^>]*) class=\"wikilink1\" title=\"$key\"([^>]*)>(.*)</a>#U", "<a \\1 class=\"wikilink1\" title=\"$key\"\\2>\\3</a> ($value)", $event->data);
}
} else {
# Erase everything between markers
$event->data = preg_replace("/<!-- DOKUTRANSLATE ERASE START -->.*<!-- DOKUTRANSLATE ERASE STOP -->/sm", '', $event->data);
}
}
# Generic event eater
@@ -459,6 +478,45 @@ public function handle_disabled(Doku_Event &$event, $param) {
return;
}
function _translationStatus($id) {
if (!@file_exists(metaFN($id, '.translate'))) {
return '';
}
$meta = unserialize(io_readFile(metaFN($id, '.translate'), false));
$total = 0;
$reviewme = false;
while (list($key, $value) = each($meta)) {
$rating = empty($value['reviews']) ? 0 : 4;
foreach ($value['reviews'] as $review) {
$tmp = intval($review['quality']) * 2;
if ($review['incomplete']) {
$tmp--;
}
$tmp = $tmp < 0 ? 0 : $tmp;
$rating = $tmp < $rating ? $tmp : $rating;
}
$total += $rating;
if (needsReview($id, $meta, $key)) {
$reviewme = true;
}
}
$ret = sprintf($this->getLang('trans_percentage'), 25 * $total / count($meta));
if ($reviewme) {
$ret .= ', ' . $this->getLang('reviewme');
}
return $ret;
}
}
// vim:ts=4:sw=4:et:
View
@@ -21,5 +21,7 @@
$lang['add_review'] = 'Uložit hodnocení';
$lang['rend_incomplete'] = 'Neúplný';
$lang['review_header'] = 'Hodnocení překladu';
$lang['trans_percentage'] = '%d%% přeloženo';
$lang['reviewme'] = 'text potřebuje ohodnotit';
//Setup VIM: ex: et ts=4 :
View
@@ -27,5 +27,7 @@
$lang['add_review'] = 'Save Review';
$lang['rend_incomplete'] = 'Incomplete';
$lang['review_header'] = 'Translation Reviews';
$lang['trans_percentage'] = '%d%% translated';
$lang['reviewme'] = 'text waiting for your review';
//Setup VIM: ex: et ts=4 :
View
@@ -117,10 +117,6 @@ function parReviewClass($meta, $parid) {
return empty($classes[$clsid]) ? '' : $classes[$clsid];
}
function needsReview($id, $meta, $parid) {
return canReview($id, $meta, $parid) && !isset($meta[$parid]['reviews'][$_SERVER['REMOTE_USER']]);
}
class syntax_plugin_dokutranslate extends DokuWiki_Syntax_Plugin {
private $origIns = NULL;
private $meta = NULL;
View
@@ -114,7 +114,10 @@ function isModerator($id) {
function canReview($id, $meta, $parid) {
return isModerator($id) && $meta[$parid]['user'] != $_SERVER['REMOTE_USER'] && $meta[$parid]['ip'] != clientIP(true);
}
function needsReview($id, $meta, $parid) {
return canReview($id, $meta, $parid) && !isset($meta[$parid]['reviews'][$_SERVER['REMOTE_USER']]);
}
// vim:ts=4:sw=4:et:

0 comments on commit ae8b479

Please sign in to comment.