Completed
Push — master ( a14a40...35a644 )
by Adam
03:19
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/* PROJECT:     ReactOS Translation Tool
3
 * LICENSE:     GPL
4
 * AUTHORS:     Adam Stachowicz <[email protected]>
5
 * AUTHOR URL:	http://it-maniak.pl/
6
 */
7
8
include_once('header.php');
9
?>
10
11
<h1>Search missing translation strings</h1>
12
13
<div id="body">
14
15
<?php
16
17
require_once('config.php');
18
?>
19
20
<center>
21
<form method="GET" class="form-horizontal">
22
<fieldset>
23
<legend>Please type your <a href="https://beta.wikiversity.org/wiki/List_of_ISO_639-1_codes">language code in ISO 639-1</a>. For example: pl for Polish, de for German</legend>
24
    <div class="form-group">
25
        <label class="col-md-4 control-label" for="lang">Language code:</label>
26
        <div class="col-md-4">
27
            <input type="text" value="<?php echo isset($_SESSION['lang']) ? $_SESSION['lang'] : "" ?>" id="lang" name="lang" class="form-control input-md" required="required" autofocus="autofocus" pattern="[A-Za-z]{2}" title="Two letter language code"/>
28
        </div>
29
    </div>
30
    <div class="form-group">
31
        <label class="col-md-4 control-label" for="dir">Directories:</label>
32
        <div class="col-md-4">
33
        <select id="dir" name="dir" class="form-control">
34
            <option value="1">base, boot</option>
35
            <option value="2" <?php if(isset($_GET["dir"]) && $_GET["dir"] == '2'){echo("selected");}?>>dll</option>
36
            <option value="3" <?php if(isset($_GET["dir"]) && $_GET["dir"] == '3'){echo("selected");}?>>media, subsystems, win32ss</option>
37
            <option value="100" <?php if(isset($_GET["dir"]) && $_GET["dir"] == '100'){echo("selected");}?>>All ReactOS Source dir</option>
38
        </select>
39
        </div>
40
    </div>
41
    <div class="form-group">
42
        <button type="submit" class="btn btn-primary">Search</button>
43
    </div>
44
</fieldset>
45
</form>
46
</center>
47
<br/>
48
49
<?php
50
if (isset($_GET["lang"]) && !empty($_GET["lang"]) && isset($_GET["dir"]) && is_numeric($_GET["dir"]))
51
{
52
    // Switch for directories
53 View Code Duplication
    switch ($_GET["dir"])
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        case "1":
56
            $directory1 = new RecursiveDirectoryIterator($ROSDir. "base/applications");
57
            $directory2 = new RecursiveDirectoryIterator($ROSDir. "base/setup");
58
            $directory3 = new RecursiveDirectoryIterator($ROSDir. "base/shell");
59
            $directory4 = new RecursiveDirectoryIterator($ROSDir. "base/system");
60
            $directory5 = new RecursiveDirectoryIterator($ROSDir. "boot/freeldr/fdebug");
61
62
            $it = new AppendIterator();
63
            $it->append(new RecursiveIteratorIterator( $directory1 ));
64
            $it->append(new RecursiveIteratorIterator( $directory2 ));
65
            $it->append(new RecursiveIteratorIterator( $directory3 ));
66
            $it->append(new RecursiveIteratorIterator( $directory4 ));
67
            $it->append(new RecursiveIteratorIterator( $directory5 ));
68
            break;
69
70
        case "2":
71
            $directory6 = new RecursiveDirectoryIterator($ROSDir. "dll/cpl");
72
            $directory7 = new RecursiveDirectoryIterator($ROSDir. "dll/shellext");
73
            $directory8 = new RecursiveDirectoryIterator($ROSDir. "dll/win32");
74
75
            $it = new AppendIterator();
76
            $it->append(new RecursiveIteratorIterator( $directory6 ));
77
            $it->append(new RecursiveIteratorIterator( $directory7 ));
78
            $it->append(new RecursiveIteratorIterator( $directory8 ));
79
            break;
80
81
        case "3":
82
            $directory9 = new RecursiveDirectoryIterator($ROSDir. "media/themes");
83
            $directory10 = new RecursiveDirectoryIterator($ROSDir. "subsystems/mvdm/ntvdm");
84
            $directory11 = new RecursiveDirectoryIterator($ROSDir. "win32ss/user");
85
86
            $it = new AppendIterator();
87
            $it->append(new RecursiveIteratorIterator( $directory9 ));
88
            $it->append(new RecursiveIteratorIterator( $directory10 ));
89
            $it->append(new RecursiveIteratorIterator( $directory11 ));
90
            break;
91
92
        // Search in source dir - only for test
93
        case "100":
94
            $directory1 = new RecursiveDirectoryIterator($ROSDir);
95
96
            $it = new AppendIterator();
97
            $it->append(new RecursiveIteratorIterator( $directory1 ));
98
            break;
99
100
        default:
101
            echo "Something is wrong! Please try again.";
102
            exit;
103
    }
104
105
    function diff_versions($leftContent, $rightContent)
106
    {
107
        $leftVersion = $rightVersion = null;
0 ignored issues
show
$rightVersion is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
$leftVersion is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
108
109
        // FIXME: Search multi-line with ""some text""
110
        $pattern = "/^(?!FONT|\\s*\\*|\\#\\include|\\s*\\ICON)[^\"\\n]*\"\\K(?!\\s*(?:\"|\\n))([^\"]+)/m";
111
112
        if (preg_match_all($pattern, $leftContent, $matches) <= 0)
113
        {
114
            throw new Exception('Left content has no version line.');
115
        }
116
117
        $leftVersion = $matches[1];
118
119
        if (preg_match_all($pattern, $rightContent, $matches) <= 0)
120
        {
121
            throw new Exception('Right content has no version line.');
122
        }
123
124
        $rightVersion = $matches[1];
125
126
        return array(
127
            'diff' => array_intersect($leftVersion, $rightVersion),
128
            'leftVersion' => $leftVersion,
129
            'rightVersion' => $rightVersion,
130
        );
131
    }
132
133
    function exceptions_error_handler($severity, $message, $filename, $lineno)
134
    {
135
        if (error_reporting() == 0)
136
        {
137
            return;
138
        }
139
        if (error_reporting() & $severity)
140
        {
141
            throw new ErrorException($message, 0, $severity, $filename, $lineno);
142
        }
143
    }
144
145
    set_error_handler('exceptions_error_handler');
146
147
    $regex = new RegexIterator($it, '/^.+'. $langDir .'.+('. $originLang .')\.'. $fileExt .'$/i', RecursiveRegexIterator::GET_MATCH);
148
149
    $missing = $allStrings = 0;
150
151
    $lang = htmlspecialchars($_GET["lang"]);
152
    // Search for eg. PL,Pl,pl
153
    $fileSearch = strtoupper($lang) .",". ucfirst($lang) .",". strtolower($lang);
154
155
    // ReactOS and Wine Strings - array
156
    $ignoredROSStrings = file($ROSSpellFilename, FILE_IGNORE_NEW_LINES);
157
    $ignoredWineStrings = file($wineSpellFilename, FILE_IGNORE_NEW_LINES);
158
159
    $regex->rewind();
160
    while($regex->valid())
161
    {
162
        if (!$regex->isDot())
163
        {
164
            $file = glob($regex->getPathInfo() ."/*{". $fileSearch ."}*.". $fileExt, GLOB_BRACE);
165
166
            $isFile = array_filter($file);
167
168
            if (empty($isFile))
169
            {
170
                echo '<b>No translation</b> for path '. $regex->getPathInfo() .'<hr>';
171
            } else
172
            {
173
                $fileContent1 = file_get_contents($regex->key());
174
                $fileContent2 = file_get_contents($file[0]);
175
176
                $array = diff_versions($fileContent1, $fileContent2);
177
178
                if ($array['diff'])
179
                {
180
                    echo $regex->getPathInfo() .'<br><br>';
181
182
                    $currentMissing = $missing;
183
184
                    foreach ($array['leftVersion'] as $index => $english)
185
                    {
186
                        // Catch offset error
187
                        try
188
                        {
189
                            // Check if this same and ignore some words
190
                            if ($english === $array['rightVersion'][$index] && !in_array($english, $ignoredROSStrings) && !in_array($english, $ignoredWineStrings))
191
                            {
192
                            	echo "<b>Missing translation:</b> ". htmlspecialchars($english) ."<br>";
193
                                $missing++;
194
                            }
195
                            $allStrings++;
196
                        } catch (Exception $e)
197
                        {
198
                            echo "Missing stuff in your language<br>";
199
                            $allStrings++;
200
                            $missing++;
201
                        }
202
                    }
203
                    if ($currentMissing == $missing)
204
                    	echo "Seems OK :) Some strings was ignored by ReactOS and Wine spell files.<br>";
205
206
                    echo "<hr>";
207
                }
208
            }
209
        }
210
        $regex->next();
211
    }
212
    echo "<h3>All strings for english: $allStrings</h3>";
213
    echo "<h3>Missing translations for your language ($lang): $missing</h3>";
214
215
    // Rounded percent
216
    $percent = round((($allStrings - $missing) / $allStrings) * 100, 2);
217
    echo "<h3>Language $lang translated in $percent%</h3>";
218
}
219
220
include_once('footer.php');
221