summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--translator/func.php58
-rw-r--r--translator/index.php3
-rw-r--r--translator/styles.css26
3 files changed, 87 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 --------//
diff --git a/translator/index.php b/translator/index.php
index 807159e30..54253f8c1 100644
--- a/translator/index.php
+++ b/translator/index.php
@@ -115,6 +115,9 @@ if (isset($_POST["save"]) && $file && $lang)
echo '<p><input id="hilight" class="button" type="button" value="Select all" onclick="javascript:this.form.text_area.focus();this.form.text_area.select();" /></p>';
echo "\n</form></div>";
}
+else
+
+ echo '<div align="center">'.localization_stats().'</div>';
?>
</div>
diff --git a/translator/styles.css b/translator/styles.css
index 0e02c05ab..49e884df5 100644
--- a/translator/styles.css
+++ b/translator/styles.css
@@ -95,6 +95,32 @@ fieldset {
font-size: x-small;
}
+table.stats td {
+ width: 350px;
+ vertical-align: top;
+}
+
+table.langstats {
+ width: 300px;
+ border-collapse: collapse;
+ border: 1px #999 solid;
+}
+
+td.lang {
+ width: 240px;
+ white-space: nowrap;
+ text-align: left;
+}
+
+td.percent {
+ width: 60px;
+ white-space: nowrap;
+ text-align: right;
+}
+
+td.zebra {
+ background-color: silver;
+}
/*****************/