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