From 7cec7879e43e03e9997e632c8b0e7459be079b48 Mon Sep 17 00:00:00 2001 From: Tommaso Basilici Date: Sat, 18 Apr 2015 22:18:46 +0200 Subject: [PATCH 1/2] issue #2584 - output on a table + search for unused strings --- dev/translation/sanity_check_en_langfiles.php | 165 +++++++++++++++++- 1 file changed, 162 insertions(+), 3 deletions(-) diff --git a/dev/translation/sanity_check_en_langfiles.php b/dev/translation/sanity_check_en_langfiles.php index 17dab085259..b6c3bcac440 100644 --- a/dev/translation/sanity_check_en_langfiles.php +++ b/dev/translation/sanity_check_en_langfiles.php @@ -1,5 +1,5 @@ +/* Copyright (c) 2015 Tommaso Basilici * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,8 +15,129 @@ * along with this program. If not, see . */ +echo ""; +echo ""; + +echo ""; + +echo ""; +echo "

If you call this file with the argument \"?unused=true\" it searches for the translation strings that exist in en_US but are never used

"; +echo "

IMPORTANT: that can take quite a lot of time (up to 10 minutes), you need to tune the max_execution_time on your php.ini accordingly

"; +echo "

Happy translating :)

"; + +// directory containing the php and lang files +$htdocs = "../../htdocs/"; // directory containing the english lang files -$workdir = "../../htdocs/langs/en_US/"; +$workdir = $htdocs."langs/en_US/"; $files = scandir($workdir); $exludefiles = array('.','..','README'); @@ -36,6 +157,7 @@ foreach ($files AS $file) { $row_array = explode('=',$row); $langstrings_3d[$path_file['basename']][$line+1]=$row_array[0]; $langstrings_full[]=$row_array[0]; + $langstrings_dist[$row_array[0]]=$row_array[0]; } } } @@ -55,6 +177,43 @@ foreach ($langstrings_3d AS $filename => $file) { echo "

Duplicate strings in lang files in $workdir

"; echo "
";
-print_r($dups);
 
+echo " ";
+echo "";
+echo "";
+foreach ($dups as $string => $pages) {
+	echo "";
+	echo "";
+	echo "";
+}
+echo "";
+echo "
StringFile and lines
$string"; + foreach ($pages AS $page => $lines ) { + echo "$page "; + foreach ($lines as $line => $nothing) { + echo "($line) "; + } + echo "
"; + } + echo "
"; + + +if ($_REQUEST['unused'] == 'true') { + + foreach ($langstrings_dist AS $value){ + $search = '\'trans("'.$value.'")\''; + $string = 'grep -R -m 1 -F --include=*.php '.$search.' '.$htdocs.'*'; + exec($string,$output); + if (empty($output)) { + $unused[$value] = true; + echo $value.'
'; + } + } + + echo "

Strings in en_US that are never used

"; + echo "
";
+	print_r($unused);
+}
+echo "";
+echo "";
 ?>
\ No newline at end of file

From 38cfbe48977a0a08a1f27b85605fa5a349cd5bd1 Mon Sep 17 00:00:00 2001
From: Tommaso Basilici 
Date: Sat, 18 Apr 2015 22:37:23 +0200
Subject: [PATCH 2/2] issue #2584 - added a counter

---
 dev/translation/sanity_check_en_langfiles.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/dev/translation/sanity_check_en_langfiles.php b/dev/translation/sanity_check_en_langfiles.php
index b6c3bcac440..b1ccca39dee 100644
--- a/dev/translation/sanity_check_en_langfiles.php
+++ b/dev/translation/sanity_check_en_langfiles.php
@@ -175,14 +175,17 @@ foreach ($langstrings_3d AS $filename => $file) {
 	}
 }
 
-echo "

Duplicate strings in lang files in $workdir

"; +echo "

Duplicate strings in lang files in $workdir - ".count($dups)." found

"; echo "
";
 
 echo " ";
-echo "";
+echo "";
 echo "";
+$count = 0;
 foreach ($dups as $string => $pages) {
+	$count++;
 	echo "";
+	echo "";
 	echo "";
 	echo "
StringFile and lines
#StringFile and lines
$count$string"; foreach ($pages AS $page => $lines ) {