diff --git a/dev/translation/sanity_check_en_langfiles.php b/dev/translation/sanity_check_en_langfiles.php
index fdc0f738431..a3b3911c77f 100644
--- a/dev/translation/sanity_check_en_langfiles.php
+++ b/dev/translation/sanity_check_en_langfiles.php
@@ -18,20 +18,7 @@
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/";
+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 :)
";
+
+
+// STEP 1 - Search duplicates keys
+
+
+// directory containing the php and lang files
+$htdocs = "../../htdocs/";
+
// directory containing the english lang files
$workdir = $htdocs."langs/en_US/";
+
$files = scandir($workdir);
+if (empty($files))
+{
+ echo "Can't scan workdir = ".$workdir;
+ exit;
+}
+
$exludefiles = array('.','..','README');
$files = array_diff($files,$exludefiles);
$langstrings_3d = array();
@@ -154,11 +103,12 @@ foreach ($files AS $file) {
if (substr($row,0,1) !== '#') {
// don't want lines without the separator (why should those even be here, anyway...)
if (strpos($row,'=')!==false) {
- $row_array = explode('=',$row);
+ $row_array = explode('=',$row); // $row_array[0] = key
$langstrings_3d[$path_file['basename']][$line+1]=$row_array[0];
+ $langstrings_3dtrans[$path_file['basename']][$line+1]=$row_array[1];
$langstrings_full[]=$row_array[0];
$langstrings_dist[$row_array[0]]=$row_array[0];
- }
+ }
}
}
}
@@ -167,16 +117,16 @@ foreach ($files AS $file) {
foreach ($langstrings_3d AS $filename => $file) {
foreach ($file AS $linenum => $value) {
$keys = array_keys($langstrings_full, $value);
- if (count($keys)>1) {
+ if (count($keys)>1)
+ {
foreach ($keys AS $key) {
- $dups[$value][$filename][$linenum] = '';
+ $dups[$value][$filename][$linenum] = trim($langstrings_3dtrans[$filename][$linenum]);
}
}
}
}
echo "Duplicate strings in lang files in $workdir - ".count($dups)." found
";
-echo "";
echo "
";
echo "| # | String | File and lines |
";
@@ -190,22 +140,27 @@ foreach ($dups as $string => $pages) {
echo "";
foreach ($pages AS $page => $lines ) {
echo "$page ";
- foreach ($lines as $line => $nothing) {
- echo "($line) ";
+ foreach ($lines as $line => $translatedvalue) {
+ //echo "($line - ".(substr($translatedvalue,0,20)).") ";
+ echo "($line - ".htmlentities($translatedvalue).") ";
}
echo " ";
}
- echo " | ";
+ echo "\n";
}
echo "";
echo "
";
-if ($_REQUEST['unused'] == 'true') {
+// STEP 2 - Search key not used
- foreach ($langstrings_dist AS $value){
+
+if (! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true')
+{
+ foreach ($langstrings_dist AS $value)
+ {
$search = '\'trans("'.$value.'")\'';
- $string = 'grep -R -m 1 -F --include=*.php '.$search.' '.$htdocs.'*';
+ $string = 'grep -R -m 1 -F --exclude=includes/* --include=*.php '.$search.' '.$htdocs.'*';
exec($string,$output);
if (empty($output)) {
$unused[$value] = true;
@@ -216,6 +171,9 @@ if ($_REQUEST['unused'] == 'true') {
echo "Strings in en_US that are never used
";
echo "";
print_r($unused);
+ echo "
";
}
+
+echo "\n";
echo "";
-echo "";
\ No newline at end of file
+echo "";