aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/develop/lang_duplicates.php
blob: 5a77c79543f67ce3a0312b714ef0568323012984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html>
	<head>
		<title>Duplicate Language Keys</title>
	</head>
	<body>
<?php
// -------------------------------------------------------------
//
// $Id$
//
// @copyright (c) 2005 phpBB Group 
// @license http://opensource.org/licenses/gpl-license.php GNU Public License 
// 
// -------------------------------------------------------------
// Thanks to arod-1

define('IN_PHPBB', 1);
$phpEx = substr(strrchr(__FILE__, '.'), 1);
$phpbb_root_path='./../';
include($phpbb_root_path . 'common.'.$phpEx);

$mode = request_var('mode', '');

$modules = find_modules($phpbb_root_path . 'language/en');

$kkeys = $keys = array();
$langdir = dirname(__FILE__);

if (isset($lang))
{
	unset($lang);
}

foreach($modules as $module)
{
	require_once("$langdir$module");
	if (isset($lang))
	{
		$kkeys[$module] = $lang;
		$keys[] = $module;
		unset($lang);
	}
}

$equal = $case = $diff = 0;
$output = array();

while ($module = array_shift($keys))
{
	$keys_1 = array_keys($kkeys[$module]);

	foreach ($keys as $other_module)
	{
		$keys_2 = array_keys($kkeys[$other_module]);

		foreach(array_intersect($keys_1, $keys_2) as $dup)
		{
			if ($kkeys[$module][$dup] == $kkeys[$other_module][$dup])
			{
				$compare = "Equal";
				$equal++;
			}
			else if (strcasecmp($kkeys[$module][$dup], $kkeys[$other_module][$dup]) == 0)
			{
				$compare = "Differ in case";
				$case++;
			}
			else
			{
				$compare = "'{$kkeys[$module][$dup]}' - '{$kkeys[$other_module][$dup]}'";
				$diff++;
			}

			$color = '';
			if ((basename($module) == "common.$phpEx") || (basename($other_module) == "common.$phpEx"))
			{
				$color = ' style="color:#B00000;"';
			}

			switch ($mode)
			{
				case 'module':
					$output[$module][] = "<tr$color><td>" . ((isset($output[$module])) ? '&nbsp;' : "<b>$module</b>" ) . "</td><td>$dup</td><td>$other_module</td><td>$compare</td></tr>";
				break;

				default:
					$output[$dup][] = "<tr$color><td><b>$dup</b></td><td>$module</td><td>$other_module</td><td>$compare</td></tr>";
				break;
			}
		}
	}
}//var_dump($output);

echo "<p><a href=\"lang_duplicates.php\">By Key</a> <a href=\"lang_duplicates.php?mode=module\">By Module</a></p><p>Equal: <b>$equal</b>, Differ in case only: $case, differ in content: $diff</p>";
switch ($mode)
{
	case 'module':
		echo "<table cellpadding=\"4\"><tr><th>Key</th><th>First File</th><th>Second File</th><th>Difference</th></tr>";
		foreach ($output as $module => $html)
		{
			echo implode('', $html);
		}
	break;

	default:
		ksort($output);
		echo "<table cellpadding=\"4\"><tr><th>File</th><th>Key</th><th>Conflicting File</th><th>Difference</th></tr>";
		foreach ($output as $dup)
		{
			echo implode('', $dup);
		}
	break;
}

echo "</table>";


function find_modules($dirname)
{
	$list = glob("$dirname/*.php");

	foreach(glob("$dirname/*", GLOB_ONLYDIR) as $name)
	{
		$list =  array_merge($list, find_modules($name));
	}
	return $list;
}

?>
	</body>
</html>