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 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'translator/func.php') 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; } -- cgit v1.2.3