From 498a8e85f358a26617b7758f6cdcb950d52b7405 Mon Sep 17 00:00:00 2001 From: alec Date: Thu, 18 Dec 2008 14:44:12 +0000 Subject: - added localization stats table git-svn-id: https://svn.roundcube.net/trunk@2173 208e9e7b-5314-0410-a742-e7e81cd9613c --- translator/func.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'translator/func.php') diff --git a/translator/func.php b/translator/func.php index 4dbaf5709..ec530f79c 100644 --- a/translator/func.php +++ b/translator/func.php @@ -130,6 +130,64 @@ function build_localization($lang, $file) return $out; } +function count_lines($filename) +{ + $count = 0; + $lines = array(); + + if(file_exists($filename)) + $lines = file($filename); + + // count lines starting with $ ($labels/$messages) + foreach($lines as $line) + if(strpos($line, '$') === 0) + $count++; + + return $count; +} + +function localization_stats() +{ + // use saved file (cache) + if(file_exists('langstats.txt')) + if(filemtime('langstats.txt') + 60*60*2 > time()) + return file_get_contents('langstats.txt'); + + $us_count = count_lines(LANGDIR.'/'.ORIGINAL.'/'.LABELS); + $us_count += count_lines(LANGDIR.'/'.ORIGINAL.'/'.MESSAGES); + + include(LANGDIR.'/index.inc'); + + $i = 0; + foreach ((array)$rcube_languages as $l_key => $l_value) + { + if ($l_key == ORIGINAL) + continue; + + $count = count_lines(LANGDIR.'/'.$l_key.'/'.LABELS); + $count += count_lines(LANGDIR.'/'.$l_key.'/'.MESSAGES); + $percent = ($count * 100) / $us_count; + + $rows[] = sprintf("%s%.1f %%\n", + ($i%2 ? ' zebra' : ''), htmlspecialchars($l_value), ($i%2 ? ' zebra' : ''), $percent); + + $i++; + } + + // format output tables + $result = '
'; + for($i=0; $i