Skip to content

Commit b521cef

Browse files
committed
Consistency view: add filters for components (fixes issue #697)
Also add Project::isDesktopRepository method
1 parent b8a98db commit b521cef

File tree

10 files changed

+194
-6
lines changed

10 files changed

+194
-6
lines changed

app/classes/Transvision/Consistency.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function findDuplicates($strings_array)
5252
*/
5353
public static function filterStrings($strings_array, $repo)
5454
{
55-
if (in_array($repo, Project::getDesktopRepositories())) {
55+
if (Project::isDesktopRepository($repo)) {
5656
$repository_type = 'desktop';
5757
} elseif (in_array($repo, Project::getGaiaRepositories())) {
5858
$repository_type = 'gaia';
@@ -114,4 +114,25 @@ public static function filterStrings($strings_array, $repo)
114114

115115
return $strings_array;
116116
}
117+
118+
/**
119+
* Filter out strings that belong to a group of components
120+
*
121+
* @param array $strings_array Array of strings in the form
122+
* string_id => string_value
123+
* @param array $components Array of component names
124+
*
125+
* @return array Array of filtered strings, with strings belonging
126+
* to requested components removed
127+
*/
128+
public static function filterComponents($strings_array, $components)
129+
{
130+
foreach ($strings_array as $key => $value) {
131+
if (in_array(explode('/', $key)[0], $components)) {
132+
unset($strings_array[$key]);
133+
}
134+
}
135+
136+
return $strings_array;
137+
}
117138
}

app/classes/Transvision/Project.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function getGaiaRepositories()
134134
}
135135

136136
/**
137-
* Get the list of repositories for Desktop Applications
137+
* Get the list of repositories for desktop applications
138138
*
139139
* @return array list of local repositories folder names
140140
*/
@@ -147,6 +147,17 @@ public static function getDesktopRepositories()
147147
);
148148
}
149149

150+
/**
151+
* Check if the repository belongs to a desktop application
152+
*
153+
* @param string $repository ID of the repository
154+
* @return boolean True if repository is used for a desktop application
155+
*/
156+
public static function isDesktopRepository($repo)
157+
{
158+
return in_array($repo, self::getDesktopRepositories());
159+
}
160+
150161
/**
151162
* Get the list of locales available for a repository
152163
*

app/classes/Transvision/VersionControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function getVCS($repo)
4646
public static function VCSRepoName($repo)
4747
{
4848
// Desktop
49-
if (in_array($repo, Project::getDesktopRepositories())) {
49+
if (Project::isDesktopRepository($repo)) {
5050
$repo = strtoupper($repo == 'central' ? 'trunk' : $repo) . '_L10N';
5151
}
5252

app/models/consistency.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@
1313
$locale
1414
);
1515

16+
$available_filters = [
17+
'all' => 'All products',
18+
'firefox' => 'Firefox for desktop and Android',
19+
'seamonkey' => 'SeaMonkey',
20+
'thunderbird' => 'Thunderbird',
21+
];
22+
23+
if (isset($_GET['filter'])) {
24+
$selected_filter = isset($available_filters[$_GET['filter']])
25+
? Utils::secureText($_GET['filter'])
26+
: 'all';
27+
} else {
28+
$selected_filter = 'all';
29+
}
30+
$filter_visibility = Project::isDesktopRepository($repo)
31+
? ''
32+
: 'style="display: none;"';
33+
$filter_selector = Utils::getHtmlSelectOptions(
34+
$available_filters,
35+
$selected_filter,
36+
true
37+
);
38+
1639
$reference_locale = Project::getReferenceLocale($repo);
1740

1841
// Set a default for the number of strings to display
@@ -25,6 +48,36 @@
2548
if (! empty($source_strings)) {
2649
// Remove known problematic strings
2750
$duplicated_strings_english = Consistency::filterStrings($source_strings, $repo);
51+
52+
// Filter out components
53+
switch ($selected_filter) {
54+
case 'firefox':
55+
$excluded_components = [
56+
'calendar', 'chat', 'editor', 'extensions', 'mail', 'suite',
57+
];
58+
break;
59+
case 'seamonkey':
60+
$excluded_components = [
61+
'browser', 'calendar', 'chat', 'extensions', 'mail', 'mobile',
62+
];
63+
break;
64+
case 'thunderbird':
65+
$excluded_components = [
66+
'browser', 'extensions', 'mobile', 'suite',
67+
];
68+
break;
69+
default:
70+
$excluded_components = [];
71+
break;
72+
}
73+
$filter_message = empty($excluded_components)
74+
? ''
75+
: 'Currently excluding the following folders: ' . implode(', ', $excluded_components) . '.';
76+
$duplicated_strings_english = Consistency::filterComponents(
77+
$duplicated_strings_english,
78+
$excluded_components
79+
);
80+
2881
// Find strings that are identical in English
2982
$duplicated_strings_english = Consistency::findDuplicates($duplicated_strings_english);
3083
}

app/models/health_status.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
$strings[$ref_locale][$repo] = $cache_filtered_strings($ref_locale, $ref_locale . $repo . 'filteredstrings');
7676

7777
// If Desktop, parse the strings to get components
78-
if (in_array($repo, Project::getDesktopRepositories())) {
78+
if (Project::isDesktopRepository($repo)) {
7979
foreach (Project::getComponents($strings[$locale][$repo]) as $component) {
8080
$filter_pattern = function ($locale_code) use ($component, $repo, $strings) {
8181
return array_filter(

app/views/consistency.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@
2323
</fieldset>
2424
<?php endif; ?>
2525

26+
<fieldset class="desktop_repo_only" <?=$filter_visibility?>>
27+
<label>Filter consistency for</label>
28+
<select name="filter" title="Filters" id="simplesearch_filter">
29+
<?=$filter_selector?>
30+
</select>
31+
</fieldset>
32+
2633
<input type="submit" value="Go" alt="Go" />
34+
<p class="desktop_repo_only" id="filter_message"><?=$filter_message?></p>
2735
</fieldset>
2836
</form>
29-
3037
<?php
3138
if ($strings_number == 0) {
3239
echo '<div class="message"><p>No inconsistent translations found.</p></div>';
@@ -45,7 +52,8 @@
4552
$search_link = "/?sourcelocale={$reference_locale}"
4653
. "&locale={$locale}"
4754
. "&repo={$repo}"
48-
. '&search_type=strings&recherche=' . urlencode($data['source']);
55+
. '&search_type=strings&recherche=' . urlencode($data['source'])
56+
. '&perfect_match=perfect_match';
4957
echo "<tr>\n";
5058
echo '<td>';
5159
echo '<a href="' . $search_link . '" title="Search for this string">' . Utils::secureText($data['source']) . "</a></td>\n";

tests/units/Transvision/Consistency.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,59 @@ public function testFilterStrings($a, $b, $c)
110110
->array($obj->filterStrings($a, $b))
111111
->isEqualTo($c);
112112
}
113+
114+
public function filterComponents_DP()
115+
{
116+
return [
117+
[
118+
[
119+
'browser/chrome/browser/preferences/applicationManager.dtd:appManager.style' => 'width: 30em; min-height: 20em;',
120+
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
121+
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
122+
'browser/defines.inc:MOZ_LANGPACK_CREATOR' => 'L\'équipe FrenchMozilla',
123+
'dom/chrome/accessibility/win/accessible.properties:press' => 'Appuyer',
124+
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
125+
'dom/chrome/accessibility/AccessFu.properties:notation-phasorangle' => 'angle de phaseur',
126+
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
127+
],
128+
['browser', 'dom'],
129+
[
130+
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
131+
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
132+
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
133+
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
134+
],
135+
],
136+
[
137+
[
138+
'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page',
139+
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
140+
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
141+
'dom/chrome/accessibility/win/accessible.properties:press' => 'Appuyer',
142+
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
143+
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
144+
],
145+
[],
146+
[
147+
'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page',
148+
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
149+
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
150+
'dom/chrome/accessibility/win/accessible.properties:press' => 'Appuyer',
151+
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
152+
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
153+
],
154+
],
155+
];
156+
}
157+
158+
/**
159+
* @dataProvider filterComponents_DP
160+
*/
161+
public function testFilterComponents($a, $b, $c)
162+
{
163+
$obj = new _Consistency();
164+
$this
165+
->array($obj->filterComponents($a, $b))
166+
->isEqualTo($c);
167+
}
113168
}

tests/units/Transvision/Project.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ public function testGetDesktopRepositories()
7474
->isEqualTo($repos);
7575
}
7676

77+
public function isDesktopRepositoryDP()
78+
{
79+
return [
80+
['central', true],
81+
['release', true],
82+
['firefox_ios', false],
83+
['mozilla_org', false],
84+
['randomrepo', false],
85+
];
86+
}
87+
88+
/**
89+
* @dataProvider isDesktopRepositoryDP
90+
*/
91+
public function testIsDesktopRepository($a, $b)
92+
{
93+
$obj = new _Project();
94+
$this
95+
->boolean($obj->isDesktopRepository($a))
96+
->isEqualTo($b);
97+
}
98+
7799
public function getRepositoryLocalesDP()
78100
{
79101
return [

web/js/base.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ $(document).ready(function() {
3333
$('#simplesearch_repository').on('change', function(){
3434
// Store locale currently selected
3535
var current_locale = $('#simplesearch_locale').val();
36+
var repository_id = this.value;
3637

3738
// Empty the select
3839
$('#simplesearch_locale')
@@ -46,6 +47,14 @@ $(document).ready(function() {
4647
.text(locale));
4748
});
4849

50+
// Hide elements (e.g. filters in Consistency view) if it's not a desktop repository
51+
var desktop_repositories = ['central', 'aurora', 'beta', 'release'];
52+
if (desktop_repositories.indexOf(repository_id) === -1) {
53+
$('.desktop_repo_only').hide();
54+
} else {
55+
$('.desktop_repo_only').show();
56+
}
57+
4958
// Try to select the same locale previously selected.
5059
$('#simplesearch_locale option[value="' + current_locale + '"]')
5160
.prop('selected', true);

web/style/transvision.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,15 @@ fieldset {
754754
margin: 0 auto;
755755
}
756756

757+
#consistency #simplesearch_filter {
758+
width: 200px;
759+
}
760+
761+
#consistency #filter_message {
762+
font-size: 0.9em;
763+
margin-top: -10px;
764+
}
765+
757766
/* Gaia comparison view */
758767
.added_string {
759768
color: #008000;

0 commit comments

Comments
 (0)