From 0b6a58bd7036592aedccf68c76210fda200ea0bf Mon Sep 17 00:00:00 2001 From: thomasb Date: Thu, 18 Dec 2008 18:04:51 +0000 Subject: Use update_from_svn() to get localization files for stats; Store stats file in (writeable) localization folder; Increase cache time to 12 hours; Some style tweaks git-svn-id: https://svn.roundcube.net/trunk@2178 208e9e7b-5314-0410-a742-e7e81cd9613c --- translator/func.php | 27 ++++++++++++++------------- translator/index.php | 8 +++++--- translator/styles.css | 4 ++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/translator/func.php b/translator/func.php index ec530f79c..fce85fa70 100644 --- a/translator/func.php +++ b/translator/func.php @@ -42,7 +42,7 @@ function update_from_svn($lang, $file) $headers = true; if ($fp && !$err && ($fl = @fopen(LANGDIR."$lang_prefix$file", 'w'))) { - // echo '
Update from SVN: '.$lang_dir.$file.'
'; + echo '\n"; while (!feof($fp)) { $line = fgets($fp, 4096); @@ -130,12 +130,12 @@ function build_localization($lang, $file) return $out; } -function count_lines($filename) +function count_lines($lang, $file) { $count = 0; $lines = array(); - if(file_exists($filename)) + if ($filename = update_from_svn($lang, $file)) $lines = file($filename); // count lines starting with $ ($labels/$messages) @@ -146,17 +146,18 @@ function count_lines($filename) return $count; } -function localization_stats() +function localization_stats($force = false) { + $cachefile = LANGDIR . 'langstats.txt'; // use saved file (cache) - if(file_exists('langstats.txt')) - if(filemtime('langstats.txt') + 60*60*2 > time()) - return file_get_contents('langstats.txt'); + if (!$force && file_exists($cachefile)) + if (filemtime($cachefile) + 60*60*12 > time()) + return file_get_contents($cachefile); - $us_count = count_lines(LANGDIR.'/'.ORIGINAL.'/'.LABELS); - $us_count += count_lines(LANGDIR.'/'.ORIGINAL.'/'.MESSAGES); + $us_count = count_lines(ORIGINAL, LABELS); + $us_count += count_lines(ORIGINAL, MESSAGES); - include(LANGDIR.'/index.inc'); + include(LANGDIR . 'index.inc'); $i = 0; foreach ((array)$rcube_languages as $l_key => $l_value) @@ -164,8 +165,8 @@ function localization_stats() if ($l_key == ORIGINAL) continue; - $count = count_lines(LANGDIR.'/'.$l_key.'/'.LABELS); - $count += count_lines(LANGDIR.'/'.$l_key.'/'.MESSAGES); + $count = count_lines($l_key, LABELS); + $count += count_lines($l_key, MESSAGES); $percent = ($count * 100) / $us_count; $rows[] = sprintf("%s%.1f %%\n", @@ -184,7 +185,7 @@ function localization_stats() $result .= ''; // save to cache file - file_put_contents('langstats.txt', $result); + file_put_contents($cachefile, $result); return $result; } diff --git a/translator/index.php b/translator/index.php index 54253f8c1..9e033515c 100644 --- a/translator/index.php +++ b/translator/index.php @@ -115,9 +115,11 @@ if (isset($_POST["save"]) && $file && $lang) echo '

'; echo "\n"; } -else - - echo '
'.localization_stats().'
'; +else if (empty($file)) +{ + echo '

Current completeness status

'; + echo '
'.localization_stats().'
'; +} ?> diff --git a/translator/styles.css b/translator/styles.css index 49e884df5..e37211b73 100644 --- a/translator/styles.css +++ b/translator/styles.css @@ -103,7 +103,7 @@ table.stats td { table.langstats { width: 300px; border-collapse: collapse; - border: 1px #999 solid; + border: 1px #bbb solid; } td.lang { @@ -119,7 +119,7 @@ td.percent { } td.zebra { - background-color: silver; + background-color: #eaeaea; } /*****************/ -- cgit v1.2.3