diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-12-18 14:44:12 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-12-18 14:44:12 +0000 |
| commit | 498a8e85f358a26617b7758f6cdcb950d52b7405 (patch) | |
| tree | 149774d7b233fb5c344771d1ce17c998b7cec791 /translator/func.php | |
| parent | 3831821cb8b02318946e9503df2ee0a16e833244 (diff) | |
- added localization stats table
git-svn-id: https://svn.roundcube.net/trunk@2173 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'translator/func.php')
| -rw-r--r-- | translator/func.php | 58 |
1 files changed, 58 insertions, 0 deletions
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("<tr><td class=\"lang%s\">%s</td><td class=\"percent%s\">%.1f %%</td></tr>\n", + ($i%2 ? ' zebra' : ''), htmlspecialchars($l_value), ($i%2 ? ' zebra' : ''), $percent); + + $i++; + } + + // format output tables + $result = '<table class="stats"><tr><td><table class="langstats">'; + for($i=0; $i<count($rows)/2; $i++) + $result .= $rows[$i]; + $result .= '</table></td><td><table class="langstats">'; + for(; $i<count($rows); $i++) + $result .= $rows[$i]; + $result .= '</td></tr></table>'; + + // save to cache file + file_put_contents('langstats.txt', $result); + + return $result; +} // -------- EOF func --------// |
