Skip to content

Commit

Permalink
Consistency view: add filters for components (fixes issue #697)
Browse files Browse the repository at this point in the history
Also add Project::isDesktopRepository method
  • Loading branch information
flodolo committed Mar 21, 2016
1 parent b8a98db commit b521cef
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 6 deletions.
23 changes: 22 additions & 1 deletion app/classes/Transvision/Consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function findDuplicates($strings_array)
*/
public static function filterStrings($strings_array, $repo)
{
if (in_array($repo, Project::getDesktopRepositories())) {
if (Project::isDesktopRepository($repo)) {
$repository_type = 'desktop';
} elseif (in_array($repo, Project::getGaiaRepositories())) {
$repository_type = 'gaia';
Expand Down Expand Up @@ -114,4 +114,25 @@ public static function filterStrings($strings_array, $repo)

return $strings_array;
}

/**
* Filter out strings that belong to a group of components
*
* @param array $strings_array Array of strings in the form
* string_id => string_value
* @param array $components Array of component names
*
* @return array Array of filtered strings, with strings belonging
* to requested components removed
*/
public static function filterComponents($strings_array, $components)
{
foreach ($strings_array as $key => $value) {
if (in_array(explode('/', $key)[0], $components)) {
unset($strings_array[$key]);
}
}

return $strings_array;
}
}
13 changes: 12 additions & 1 deletion app/classes/Transvision/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function getGaiaRepositories()
}

/**
* Get the list of repositories for Desktop Applications
* Get the list of repositories for desktop applications
*
* @return array list of local repositories folder names
*/
Expand All @@ -147,6 +147,17 @@ public static function getDesktopRepositories()
);
}

/**
* Check if the repository belongs to a desktop application
*
* @param string $repository ID of the repository
* @return boolean True if repository is used for a desktop application
*/
public static function isDesktopRepository($repo)
{
return in_array($repo, self::getDesktopRepositories());
}

/**
* Get the list of locales available for a repository
*
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Transvision/VersionControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function getVCS($repo)
public static function VCSRepoName($repo)
{
// Desktop
if (in_array($repo, Project::getDesktopRepositories())) {
if (Project::isDesktopRepository($repo)) {
$repo = strtoupper($repo == 'central' ? 'trunk' : $repo) . '_L10N';
}

Expand Down
53 changes: 53 additions & 0 deletions app/models/consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@
$locale
);

$available_filters = [
'all' => 'All products',
'firefox' => 'Firefox for desktop and Android',
'seamonkey' => 'SeaMonkey',
'thunderbird' => 'Thunderbird',
];

if (isset($_GET['filter'])) {
$selected_filter = isset($available_filters[$_GET['filter']])
? Utils::secureText($_GET['filter'])
: 'all';
} else {
$selected_filter = 'all';
}
$filter_visibility = Project::isDesktopRepository($repo)
? ''
: 'style="display: none;"';
$filter_selector = Utils::getHtmlSelectOptions(
$available_filters,
$selected_filter,
true
);

$reference_locale = Project::getReferenceLocale($repo);

// Set a default for the number of strings to display
Expand All @@ -25,6 +48,36 @@
if (! empty($source_strings)) {
// Remove known problematic strings
$duplicated_strings_english = Consistency::filterStrings($source_strings, $repo);

// Filter out components
switch ($selected_filter) {
case 'firefox':
$excluded_components = [
'calendar', 'chat', 'editor', 'extensions', 'mail', 'suite',
];
break;
case 'seamonkey':
$excluded_components = [
'browser', 'calendar', 'chat', 'extensions', 'mail', 'mobile',
];
break;
case 'thunderbird':
$excluded_components = [
'browser', 'extensions', 'mobile', 'suite',
];
break;
default:
$excluded_components = [];
break;
}
$filter_message = empty($excluded_components)
? ''
: 'Currently excluding the following folders: ' . implode(', ', $excluded_components) . '.';
$duplicated_strings_english = Consistency::filterComponents(
$duplicated_strings_english,
$excluded_components
);

// Find strings that are identical in English
$duplicated_strings_english = Consistency::findDuplicates($duplicated_strings_english);
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/health_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
$strings[$ref_locale][$repo] = $cache_filtered_strings($ref_locale, $ref_locale . $repo . 'filteredstrings');

// If Desktop, parse the strings to get components
if (in_array($repo, Project::getDesktopRepositories())) {
if (Project::isDesktopRepository($repo)) {
foreach (Project::getComponents($strings[$locale][$repo]) as $component) {
$filter_pattern = function ($locale_code) use ($component, $repo, $strings) {
return array_filter(
Expand Down
12 changes: 10 additions & 2 deletions app/views/consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@
</fieldset>
<?php endif; ?>

<fieldset class="desktop_repo_only" <?=$filter_visibility?>>
<label>Filter consistency for</label>
<select name="filter" title="Filters" id="simplesearch_filter">
<?=$filter_selector?>
</select>
</fieldset>

<input type="submit" value="Go" alt="Go" />
<p class="desktop_repo_only" id="filter_message"><?=$filter_message?></p>
</fieldset>
</form>

<?php
if ($strings_number == 0) {
echo '<div class="message"><p>No inconsistent translations found.</p></div>';
Expand All @@ -45,7 +52,8 @@
$search_link = "/?sourcelocale={$reference_locale}"
. "&locale={$locale}"
. "&repo={$repo}"
. '&search_type=strings&recherche=' . urlencode($data['source']);
. '&search_type=strings&recherche=' . urlencode($data['source'])
. '&perfect_match=perfect_match';
echo "<tr>\n";
echo '<td>';
echo '<a href="' . $search_link . '" title="Search for this string">' . Utils::secureText($data['source']) . "</a></td>\n";
Expand Down
55 changes: 55 additions & 0 deletions tests/units/Transvision/Consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,59 @@ public function testFilterStrings($a, $b, $c)
->array($obj->filterStrings($a, $b))
->isEqualTo($c);
}

public function filterComponents_DP()
{
return [
[
[
'browser/chrome/browser/preferences/applicationManager.dtd:appManager.style' => 'width: 30em; min-height: 20em;',
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
'browser/defines.inc:MOZ_LANGPACK_CREATOR' => 'L\'équipe FrenchMozilla',
'dom/chrome/accessibility/win/accessible.properties:press' => 'Appuyer',
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
'dom/chrome/accessibility/AccessFu.properties:notation-phasorangle' => 'angle de phaseur',
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
],
['browser', 'dom'],
[
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
],
],
[
[
'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page',
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
'dom/chrome/accessibility/win/accessible.properties:press' => 'Appuyer',
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
],
[],
[
'browser/pdfviewer/viewer.properties:last_page.label' => 'Aller à la dernière page',
'extensions/irc/chrome/ceip.dtd:window.size' => 'width: 42em;',
'mail/chrome/messenger/importDialog.dtd:window.macWidth' => '45em',
'dom/chrome/accessibility/win/accessible.properties:press' => 'Appuyer',
'shared/date/date.properties:days-until-long[many]' => 'dans {{value}} jours',
'apps/system/accessibility.properties:accessibility-listItemsCount[two]' => '{{count}} éléments',
],
],
];
}

/**
* @dataProvider filterComponents_DP
*/
public function testFilterComponents($a, $b, $c)
{
$obj = new _Consistency();
$this
->array($obj->filterComponents($a, $b))
->isEqualTo($c);
}
}
22 changes: 22 additions & 0 deletions tests/units/Transvision/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ public function testGetDesktopRepositories()
->isEqualTo($repos);
}

public function isDesktopRepositoryDP()
{
return [
['central', true],
['release', true],
['firefox_ios', false],
['mozilla_org', false],
['randomrepo', false],
];
}

/**
* @dataProvider isDesktopRepositoryDP
*/
public function testIsDesktopRepository($a, $b)
{
$obj = new _Project();
$this
->boolean($obj->isDesktopRepository($a))
->isEqualTo($b);
}

public function getRepositoryLocalesDP()
{
return [
Expand Down
9 changes: 9 additions & 0 deletions web/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $(document).ready(function() {
$('#simplesearch_repository').on('change', function(){
// Store locale currently selected
var current_locale = $('#simplesearch_locale').val();
var repository_id = this.value;

// Empty the select
$('#simplesearch_locale')
Expand All @@ -46,6 +47,14 @@ $(document).ready(function() {
.text(locale));
});

// Hide elements (e.g. filters in Consistency view) if it's not a desktop repository
var desktop_repositories = ['central', 'aurora', 'beta', 'release'];
if (desktop_repositories.indexOf(repository_id) === -1) {
$('.desktop_repo_only').hide();
} else {
$('.desktop_repo_only').show();
}

// Try to select the same locale previously selected.
$('#simplesearch_locale option[value="' + current_locale + '"]')
.prop('selected', true);
Expand Down
9 changes: 9 additions & 0 deletions web/style/transvision.css
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,15 @@ fieldset {
margin: 0 auto;
}

#consistency #simplesearch_filter {
width: 200px;
}

#consistency #filter_message {
font-size: 0.9em;
margin-top: -10px;
}

/* Gaia comparison view */
.added_string {
color: #008000;
Expand Down

0 comments on commit b521cef

Please sign in to comment.