forked from Saibamen/ReactOS-Translation-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding.php
147 lines (129 loc) · 6.23 KB
/
encoding.php
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/* PROJECT: ReactOS Translation Tool
* LICENSE: GPL
* AUTHORS: Adam Stachowicz <[email protected]>
* AUTHOR URL: http://it-maniak.pl/
*/
include_once 'header.php';
include_once 'langcodes.php';
?>
<h1>Search for wrong encoded files</h1>
<div id="body">
<center>
<form method="GET" class="form-horizontal">
<fieldset>
<legend>Please choose your language and the directories, where you want to search for untranslated strings, from the lists below.</legend>
<div class="form-group">
<label class="col-md-4 control-label" for="lang">Language:</label>
<div class="col-md-4">
<select id="lang" name="lang" class="form-control" required="required">
<?php
foreach ($langcodes as $language) {
echo '<option value="'.$language[0].'" ';
if (isset($_SESSION['lang']) && $language[0] == $_SESSION['lang']) {
echo 'selected';
}
echo '>'.$language[1].'</option>';
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="dir">Directories:</label>
<div class="col-md-4">
<select id="dir" name="dir" class="form-control">
<option value="1">base, boot</option>
<option value="2" <?php if (isset($_GET['dir']) && $_GET['dir'] == '2') {
echo 'selected';
}?>>dll</option>
<option value="3" <?php if (isset($_GET['dir']) && $_GET['dir'] == '3') {
echo 'selected';
}?>>media, subsystems, win32ss</option>
<option value="100" <?php if (isset($_GET['dir']) && $_GET['dir'] == '100') {
echo 'selected';
}?>>All ReactOS Source dir</option>
</select>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</fieldset>
</form>
</center>
<br>
<?php
if (isset($_GET['lang']) && !empty($_GET['lang']) && isset($_GET['dir']) && is_numeric($_GET['dir'])) {
$it = new AppendIterator();
// Switch for directories
switch ($_GET['dir']) {
case '1':
$directories = [
new RecursiveDirectoryIterator($ROSDir.'base/applications'),
new RecursiveDirectoryIterator($ROSDir.'base/setup'),
new RecursiveDirectoryIterator($ROSDir.'base/shell'),
new RecursiveDirectoryIterator($ROSDir.'base/system'),
new RecursiveDirectoryIterator($ROSDir.'boot/freeldr/fdebug'),
];
break;
case '2':
$directories = [
new RecursiveDirectoryIterator($ROSDir.'dll/cpl'),
new RecursiveDirectoryIterator($ROSDir.'dll/shellext'),
new RecursiveDirectoryIterator($ROSDir.'dll/win32'),
];
break;
case '3':
$directories = [
new RecursiveDirectoryIterator($ROSDir.'media/themes'),
new RecursiveDirectoryIterator($ROSDir.'subsystems/mvdm/ntvdm'),
new RecursiveDirectoryIterator($ROSDir.'win32ss/user'),
];
break;
case '100':
$directories = [
new RecursiveDirectoryIterator($ROSDir),
];
break;
default:
echo 'Something is wrong! Please try again.';
exit;
}
foreach ($directories as $directory) {
$it->append(new RecursiveIteratorIterator($directory));
}
$regex = new RegexIterator($it, '/^.+'.$langDir.'.+('.$originLang.')\.'.$fileExt.'$/i', RecursiveRegexIterator::GET_MATCH);
$allWrongEnc = 0;
$lang = htmlspecialchars($_GET['lang']);
// Search for eg. PL,Pl,pl
$fileSearch = strtoupper($lang).','.ucfirst($lang).','.strtolower($lang);
// UTF-8 BOM starts with EF BB BF
define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF));
$regex->rewind();
while ($regex->valid()) {
if (!$regex->isDot()) {
$file = glob($regex->getPathInfo().'/*{'.$fileSearch.'}*.'.$fileExt, GLOB_BRACE);
$isFile = array_filter($file);
if (!empty($isFile)) {
$text = file_get_contents($file[0]);
// UTF-8 is good
if (mb_check_encoding($text, 'UTF-8')) {
$first3 = substr($text, 0, 3);
// But UTF-8 with BOM not!
if ($first3 === UTF8_BOM) {
echo 'Detected <b>UTF-8 BOM</b> in '.$file[0].'<br>';
$allWrongEnc++;
}
} else {
// Other encoding
echo 'Detected <b>other encoding</b> in '.$file[0].'<br>';
$allWrongEnc++;
}
}
}
$regex->next();
}
echo "<h3>All files with wrong encoding: $allWrongEnc</h3>";
}
include_once 'footer.php';