[Svn] r2173 - trunk/translator

trac at roundcube.net trac at roundcube.net
Thu Dec 18 15:44:12 CET 2008


Author: alec
Date: 2008-12-18 08:44:12 -0600 (Thu, 18 Dec 2008)
New Revision: 2173

Modified:
   trunk/translator/func.php
   trunk/translator/index.php
   trunk/translator/styles.css
Log:
- added localization stats table


Modified: trunk/translator/func.php
===================================================================
--- trunk/translator/func.php	2008-12-18 12:00:06 UTC (rev 2172)
+++ trunk/translator/func.php	2008-12-18 14:44:12 UTC (rev 2173)
@@ -130,7 +130,65 @@
 	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 --------//
 
 $header = array();

Modified: trunk/translator/index.php
===================================================================
--- trunk/translator/index.php	2008-12-18 12:00:06 UTC (rev 2172)
+++ trunk/translator/index.php	2008-12-18 14:44:12 UTC (rev 2173)
@@ -115,7 +115,10 @@
 	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>
 

Modified: trunk/translator/styles.css
===================================================================
--- trunk/translator/styles.css	2008-12-18 12:00:06 UTC (rev 2172)
+++ trunk/translator/styles.css	2008-12-18 14:44:12 UTC (rev 2173)
@@ -95,7 +95,33 @@
 	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;
+}
+
 /*****************/
 
 

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list