Completed
Pull Request — master (#9)
by
unknown
01: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
include_once 'langcodes.php';
10
?>
11
12
<h1>Search missing translation strings</h1>
13
14
<div id="body">
15
<center>
16
    <form method="GET" class="form-horizontal">
17
        <fieldset>
18
            <legend>Please choose your language and the directories, where you want to search for untranslated strings, from the lists below.</legend>
19
            <div class="form-group">
20
                <label class="col-md-4 control-label" for="lang">Language:</label>
21
                <div class="col-md-4">
22
                    <select id="lang" name="lang" class="form-control">
23
                        <option value="" selected disabled hidden>Choose here</option>
24
                        <?php foreach ($langcodes as $language) {
25
    echo"<option value='$language[0]'>$language[1]</option>";
26
}?>
27
                    </select>
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') {
36
    echo 'selected';
37
}?>>dll</option>
38
                    <option value="3" <?php if (isset($_GET['dir']) && $_GET['dir'] == '3') {
39
    echo 'selected';
40
}?>>media, subsystems, win32ss</option>
41
                    <option value="100" <?php if (isset($_GET['dir']) && $_GET['dir'] == '100') {
42
    echo 'selected';
43
}?>>All ReactOS Source dir</option>
44
                </select>
45
                </div>
46
            </div>
47
            <div class="form-group">
48
                <button type="submit" class="btn btn-primary">Search</button>
49
            </div>
50
        </fieldset>
51
    </form>
52
</center>
53
<br>
54
55
<?php
56
if (isset($_GET['lang']) && !empty($_GET['lang']) && isset($_GET['dir']) && is_numeric($_GET['dir'])) {
57
    $it = new AppendIterator();
58
59
    // Switch for directories
60 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...
61
        case '1':
62
            $directories = [
63
                new RecursiveDirectoryIterator($ROSDir.'base/applications'),
64
                new RecursiveDirectoryIterator($ROSDir.'base/setup'),
65
                new RecursiveDirectoryIterator($ROSDir.'base/shell'),
66
                new RecursiveDirectoryIterator($ROSDir.'base/system'),
67
                new RecursiveDirectoryIterator($ROSDir.'boot/freeldr/fdebug'),
68
            ];
69
            break;
70
71
        case '2':
72
            $directories = [
73
                new RecursiveDirectoryIterator($ROSDir.'dll/cpl'),
74
                new RecursiveDirectoryIterator($ROSDir.'dll/shellext'),
75
                new RecursiveDirectoryIterator($ROSDir.'dll/win32'),
76
            ];
77
            break;
78
79
        case '3':
80
            $directories = [
81
                new RecursiveDirectoryIterator($ROSDir.'media/themes'),
82
                new RecursiveDirectoryIterator($ROSDir.'subsystems/mvdm/ntvdm'),
83
                new RecursiveDirectoryIterator($ROSDir.'win32ss/user'),
84
            ];
85
            break;
86
87
        case '100':
88
            $directories = [
89
                new RecursiveDirectoryIterator($ROSDir),
90
            ];
91
            break;
92
93
        default:
94
            echo 'Something is wrong! Please try again.';
95
            exit;
96
    }
97
98
    foreach ($directories as $directory) {
99
        $it->append(new RecursiveIteratorIterator($directory));
100
    }
101
102
    function diff_versions($leftContent, $rightContent)
103
    {
104
        $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...
105
106
        $pattern = '/^(?!FONT|\\s*\\*|\\#\\include|\\s*\\ICON)[^"\\n]*"\\K(?!\\s*(?:"|\\n))([^"]+)/m';
107
108
        if (preg_match_all($pattern, $leftContent, $matches) <= 0) {
109
            throw new Exception('Left content has no version line.');
110
        }
111
112
        $leftVersion = $matches[1];
113
114
        if (preg_match_all($pattern, $rightContent, $matches) <= 0) {
115
            throw new Exception('Right content has no version line.');
116
        }
117
118
        $rightVersion = $matches[1];
119
120
        return [
121
            'diff'         => array_intersect($leftVersion, $rightVersion),
122
            'leftVersion'  => $leftVersion,
123
            'rightVersion' => $rightVersion,
124
        ];
125
    }
126
127
    function exceptions_error_handler($severity, $message, $filename, $lineno)
128
    {
129
        if (error_reporting() == 0) {
130
            return;
131
        }
132
        if (error_reporting() & $severity) {
133
            throw new ErrorException($message, 0, $severity, $filename, $lineno);
134
        }
135
    }
136
137
    set_error_handler('exceptions_error_handler');
138
139
    $regex = new RegexIterator($it, '/^.+'.$langDir.'.+('.$originLang.')\.'.$fileExt.'$/i', RecursiveRegexIterator::GET_MATCH);
140
141
    $missing = $allStrings = 0;
142
143
    $lang = htmlspecialchars($_GET['lang']);
144
    // Search for eg. PL,Pl,pl
145
    $fileSearch = strtoupper($lang).','.ucfirst($lang).','.strtolower($lang);
146
147
    // ReactOS and Wine Strings - array
148
    $ignoredROSStrings = file($ROSSpellFilename, FILE_IGNORE_NEW_LINES);
149
    $ignoredWineStrings = file($wineSpellFilename, FILE_IGNORE_NEW_LINES);
150
151
    $regex->rewind();
152
    while ($regex->valid()) {
153
        if (!$regex->isDot()) {
154
            $file = glob($regex->getPathInfo().'/*{'.$fileSearch.'}*.'.$fileExt, GLOB_BRACE);
155
156
            $isFile = array_filter($file);
157
158
            if (empty($isFile)) {
159
                echo '<b>No translation</b> for path '.$regex->getPathInfo().'<hr>';
160
            } else {
161
                $fileContent1 = file_get_contents($regex->key());
162
                $fileContent2 = file_get_contents($file[0]);
163
164
                $array = diff_versions($fileContent1, $fileContent2);
165
166
                if ($array['diff']) {
167
                    $currentMissing = $missing;
168
                    $missingTextMessage = null;
169
170
                    foreach ($array['leftVersion'] as $index => $english) {
171
                        // Catch offset error
172
                        try {
173
                            // Check if this same and ignore some words
174
                            if ($english === $array['rightVersion'][$index] && !in_array($english, $ignoredROSStrings) && !in_array($english, $ignoredWineStrings)) {
175
                                $missingTextMessage .= '<b>Missing translation:</b> '.htmlspecialchars($english).'<br>';
176
                                $missing++;
177
                            }
178
                            $allStrings++;
179
                        } catch (Exception $e) {
180
                            $missingTextMessage .= 'Missing stuff in your language<br>';
181
                            $allStrings++;
182
                            $missing++;
183
                        }
184
                    }
185
186
                    if ($currentMissing == $missing) {
187
                        $messageForFile = 'Seems <b>OK :)</b> Some strings was ignored by ReactOS and Wine spell files.<br>';
188
                    } elseif ($detailsTag) {
189
                        $messageForFile = '<details open><summary><strong>Click here to see/hide missing translations in file ('.($missing - $currentMissing).')</strong></summary>'.$missingTextMessage.'</details>';
190
                    } else {
191
                        $messageForFile = $missingTextMessage;
192
                    }
193
194
                    if ($currentMissing != $missing || $showTranslationOK) {
195
                        $pathFromRoot = str_replace($ROSDir, '', $regex->getPathInfo());
196
                        echo $regex->getPathInfo().' (<a href="https://github.com/reactos/reactos/tree/master/'.$pathFromRoot.'">Go to GitHub</a>)<br><br>'.$messageForFile.'<hr>';
197
                    }
198
                }
199
            }
200
        }
201
        $regex->next();
202
    }
203
204
    $languppercase = strtoupper($lang);
205
206
    echo "<h3>All strings for english: $allStrings</h3>";
207
    echo "<h3>Missing translations for your language ($languppercase): $missing</h3>";
208
209
    // Rounded percent
210
    $percent = round((($allStrings - $missing) / $allStrings) * 100, 2);
211
    echo "<h3>Language $languppercase translated in $percent%</h3>";
212
}
213
214
include_once 'footer.php';
215