Skip to content

Commit 9861250

Browse files
flodolopascalchevrel
authored andcommitted
Clean up showrepos code, remove JSON option (#720)
1 parent 4e41272 commit 9861250

File tree

7 files changed

+136
-104
lines changed

7 files changed

+136
-104
lines changed

app/controllers/showrepos.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
require_once INC . 'l10n-init.php';
3+
4+
// Include JS lib after $javascript_include gets reset in l10n-init.php.
5+
$javascript_include = ['/js/sorttable.js'];
6+
7+
include MODELS . 'showrepos.php';
8+
include VIEWS . 'showrepos.php';

app/inc/dispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
$css_include = ['health.css'];
8686
break;
8787
case 'stats':
88-
$view = 'showrepos';
88+
$controller = 'showrepos';
8989
$page_title = 'Status Overview';
9090
$page_descr = 'Repository status overview.';
9191
break;

app/models/showrepos.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
namespace Transvision;
3+
4+
// Ignore mozilla.org
5+
$repos = array_diff($repos, ['mozilla_org']);
6+
$channel_selector = '';
7+
foreach ($repos as $repo_name) {
8+
$selected_channel = ($repo_name == $repo) ? ' selected' : '';
9+
$channel_selector .= "\t<option {$selected_channel} value=\"{$repo_name}\">{$repos_nice_names[$repo_name]}</option>\n";
10+
}
11+
12+
// Filter out empty strings and known exceptions from reference strings
13+
$reference_locale = Project::getReferenceLocale($repo);
14+
$is_desktop_repo = in_array($repo, $desktop_repos);
15+
$filter_strings = function ($value, $id) use ($is_desktop_repo) {
16+
// Ignore empty strings
17+
if (! strlen($value)) {
18+
return false;
19+
}
20+
21+
// Exclude some known exceptions from desktop repositories
22+
if ($is_desktop_repo) {
23+
$exclusions = [
24+
'/branding/', '/dataman/', '/fennec-tile-testapp/',
25+
'/mozmill/', 'region.properties',
26+
];
27+
foreach ($exclusions as $exclusion) {
28+
if (strpos($id, $exclusion) !== false) {
29+
return false;
30+
}
31+
}
32+
}
33+
34+
return true;
35+
};
36+
$reference_strings = array_filter(Utils::getRepoStrings($reference_locale, $repo), $filter_strings, ARRAY_FILTER_USE_BOTH);
37+
38+
// Get supported locales, ignore the reference locale
39+
$supported_locales = Project::getRepositoryLocales($repo);
40+
$supported_locales = array_diff($supported_locales, [$reference_locale]);
41+
42+
// Reference locale count
43+
$string_count = [];
44+
$reference_count = count($reference_strings);
45+
46+
foreach ($supported_locales as $locale) {
47+
$locale_strings = array_filter(Utils::getRepoStrings($locale, $repo), 'strlen');
48+
$string_count[$locale] = [
49+
'total' => count($locale_strings),
50+
'missing' => count(array_diff_key($reference_strings, $locale_strings)),
51+
'identical' => count(array_intersect_assoc($reference_strings, $locale_strings)),
52+
];
53+
unset($locale_strings);
54+
}
55+
unset($reference_strings);
56+
57+
$table_data = [];
58+
foreach ($string_count as $locale => $stats) {
59+
$completion = $reference_count - $stats['missing'];
60+
61+
// Making sure we never divide by zero while computing percentage
62+
$completion = $reference_count == 0
63+
? 0
64+
: number_format($completion / $reference_count * 100);
65+
66+
if ($completion >= 99) {
67+
$confidence = 'Highest';
68+
} elseif ($completion >= 95) {
69+
$confidence = 'High';
70+
} elseif ($completion >= 90) {
71+
$confidence = 'High';
72+
} elseif ($completion >= 60) {
73+
$confidence = 'In progress';
74+
} elseif ($completion >= 50) {
75+
$confidence = 'Low';
76+
} elseif ($completion >= 30) {
77+
$confidence = 'Very Low';
78+
} elseif ($completion >= 10) {
79+
$confidence = 'Barely started';
80+
} elseif ($completion >= 1) {
81+
$confidence = 'Just started';
82+
} else {
83+
$confidence = 'No localization';
84+
}
85+
86+
$table_data[$locale] = [
87+
'total' => $stats['total'],
88+
'missing' => $stats['missing'],
89+
'translated' => ($stats['total'] - $stats['identical']),
90+
'identical' => $stats['identical'],
91+
'completion' => $completion,
92+
'confidence' => $confidence,
93+
];
94+
}

app/views/showrepos.php

Lines changed: 26 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,16 @@
11
<?php
22
namespace Transvision;
33

4-
$strings = [];
4+
// Include the common simple search form
5+
include __DIR__ . '/simplesearchform.php';
56

6-
// We only want software on this view, not websites
7-
unset($repos[array_search('mozilla_org', $repos)]);
7+
?>
8+
<p class="page_description">Note that it’s not possible to distinguish between untranslated
9+
strings and strings left blank on purpose.<br> For this reason the number of <em>Missing</em>
10+
string reported on this page might not be completely accurate.</p>
11+
<p class="page_description">Click on the column headers to order the table.</p>
812

9-
$repo = (isset($_GET['repo']) && in_array($_GET['repo'], $repos))
10-
? $_GET['repo']
11-
: 'gaia';
12-
13-
$channel_selector = '';
14-
15-
foreach ($repos as $val) {
16-
$ch = ($val == $repo) ? ' selected' : '';
17-
$channel_selector .= "\t<option" . $ch . " value=" . $val . ">" . $repos_nice_names[$val] . "</option>\n";
18-
}
19-
20-
// Using a callback with strlen() avoids filtering out numeric strings with a value of 0
21-
$strings['en-US'][$repo] = array_filter(Utils::getRepoStrings('en-US', $repo), 'strlen');
22-
$gaia_locales = Project::getRepositoryLocales($repo);
23-
24-
// We don't want en-US in the repos
25-
if ($key = array_search('en-US', $gaia_locales)) {
26-
unset($gaia_locales[$key]);
27-
}
28-
29-
$string_count = [];
30-
31-
// Reference locale count
32-
$count_reference = count($strings['en-US'][$repo]);
33-
34-
foreach ($gaia_locales as $val) {
35-
$strings[$val][$repo] = array_filter(Utils::getRepoStrings($val, $repo), 'strlen');
36-
$string_count[$val] = [
37-
'total' => count($strings[$val][$repo]),
38-
'missing' => count(array_diff_key($strings['en-US'][$repo], $strings[$val][$repo])),
39-
'identical' => count(array_intersect_assoc($strings['en-US'][$repo], $strings[$val][$repo])),
40-
];
41-
unset($strings[$val][$repo]);
42-
}
43-
44-
$json = [];
45-
$table = '
46-
<table id="showrepos_table">
13+
<table id="showrepos_table" class="sortable">
4714
<thead>
4815
<tr class="column_headers">
4916
<th>Locale</th>
@@ -52,64 +19,24 @@
5219
<th>Translated</th>
5320
<th>Identical</th>
5421
<th>Completion</th>
55-
<th>Status estimate</th>
22+
<th class="sorttable_nosort">Status estimate</th>
5623
</tr>
5724
</thead>
58-
<tbody>';
59-
60-
foreach ($string_count as $locale => $numbers) {
61-
$completion = $count_reference - $numbers['identical'] - $numbers['missing'];
62-
63-
// Making sure we never divide by zero while computing percentage
64-
$completion = $count_reference == 0 ? 0 : number_format($completion / $count_reference * 100);
65-
66-
if ($completion >= 99) {
67-
$confidence = 'Highest';
68-
} elseif ($completion >= 95) {
69-
$confidence = 'High';
70-
} elseif ($completion >= 90) {
71-
$confidence = 'High';
72-
} elseif ($completion >= 60) {
73-
$confidence = 'In progress';
74-
} elseif ($completion >= 50) {
75-
$confidence = 'Low';
76-
} elseif ($completion >= 30) {
77-
$confidence = 'very Low';
78-
} elseif ($completion >= 10) {
79-
$confidence = 'Barely started';
80-
} elseif ($completion >= 1) {
81-
$confidence = 'just started';
82-
} else {
83-
$confidence = 'No localization';
25+
<tbody>
26+
<?php
27+
foreach ($table_data as $locale => $stats) {
28+
$translated = $stats['total'] - $stats['identical'];
29+
echo "
30+
<tr id=\"{$locale}\">
31+
<th>{$locale}</th>
32+
<td>{$stats['total']}</td>
33+
<td>{$stats['missing']}</td>
34+
<td>{$translated}</td>
35+
<td>{$stats['identical']}</td>
36+
<td sorttable_customkey=\"{$stats['completion']}\">{$stats['completion']} %</td>
37+
<td>{$stats['confidence']}</td>
38+
</tr>\n";
8439
}
85-
86-
$json[$locale] = [
87-
'total' => $numbers['total'],
88-
'missing' => $numbers['missing'],
89-
'translated' => ($numbers['total'] - $numbers['identical']),
90-
'identical' => $numbers['identical'],
91-
'completion' => $completion,
92-
'confidence' => $confidence,
93-
];
94-
95-
$table .=
96-
"<tr id=\"{$locale}\">
97-
<th>{$locale}</th>
98-
<td>{$numbers['total']}</td>
99-
<td>{$numbers['missing']}</td>"
100-
. '<td>' . ($numbers['total'] - $numbers['identical']) . '</td>'
101-
. "<td>{$numbers['identical']}</td>
102-
<td>{$completion} %</td>
103-
<td>{$confidence}</td>
104-
</tr>";
105-
}
106-
107-
$table .= "</tbody>\n</table>\n";
108-
109-
if (isset($_GET['json'])) {
110-
include VIEWS . 'json.php';
111-
} else {
112-
// Include the common simple search form
113-
include __DIR__ . '/simplesearchform.php';
114-
echo $table;
115-
}
40+
?>
41+
</tbody>
42+
</table>

app/views/templates/base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130

131131
<?php if ($show_title == true): ?>
132132
<h2 id="page_title"><?= $page_title ?></h2>
133-
<h3 id="page_descrition"><?= $page_descr ?></h3>
133+
<p class="page_description"><?= $page_descr ?></p>
134134
<?php endif; ?>
135135

136136
<div id="pagecontent">

web/style/changelog.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
margin: 0;
2323
}
2424

25-
#changelog #page_descrition {
25+
#changelog .page_description {
2626
display: none;
2727
}
2828

web/style/transvision.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ h3 {
149149
padding-bottom: 0;
150150
}
151151

152-
#page_descrition {
153-
padding: 0;
152+
.page_description {
154153
font-size: 14px;
155154
font-weight: normal;
155+
margin: 5px auto 15px;
156+
padding: 0;
157+
text-align: center;
158+
width: 80%;
156159
}
157160

158161
#current {

0 commit comments

Comments
 (0)