Skip to content

Commit

Permalink
Ignore en-US in some views (#876)
Browse files Browse the repository at this point in the history
* Ignore en-US in some views

* Add fallback to first locale in unchanged_strings

* Use Trusty for Travis-CI tests (no-api parameter)
  • Loading branch information
flodolo authored and TheoChevalier committed Jul 31, 2017
1 parent e2b495e commit 1f9217b
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 39 deletions.
10 changes: 8 additions & 2 deletions app/classes/Transvision/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ public static function isDesktopRepository($repo)
}

/**
* Get the list of locales available for a repository
* Get the list of locales available for a repository, exclude a
* subset if needed
*
* @param string $repository ID of the repository
* @param array $ignored Array of excluded locales
*
* @return array A sorted list of locales
*/
public static function getRepositoryLocales($repository)
public static function getRepositoryLocales($repository, $ignored = [])
{
$file_name = APP_SOURCES . "{$repository}.txt";
$supported_locales = [];
Expand All @@ -118,6 +120,10 @@ public static function getRepositoryLocales($repository)
}
sort($supported_locales);

if (! empty($ignored)) {
$supported_locales = array_diff($supported_locales, $ignored);
}

return $supported_locales;
}

Expand Down
14 changes: 9 additions & 5 deletions app/models/check_variables.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<?php
namespace Transvision;

$source = Utils::getRepoStrings(Project::getReferenceLocale($repo), $repo);
$reference_locale = Project::getReferenceLocale($repo);
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
// If the requested locale is not available, fall back to the first
if (! in_array($locale, $supported_locales)) {
$locale = array_shift($supported_locales);
}

$source = Utils::getRepoStrings($reference_locale, $repo);
$target = Utils::getRepoStrings($locale, $repo);

// Set up channel selector, ignore mozilla.org
Expand All @@ -10,10 +17,7 @@
$channel_selector = Utils::getHtmlSelectOptions($channels, $repo, true);

// Build the target locale switcher
$target_locales_list = Utils::getHtmlSelectOptions(
Project::getRepositoryLocales($repo),
$locale
);
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);

$source = array_map(['Transvision\AnalyseStrings', 'cleanUpEntities'], $source);
$target = array_map(['Transvision\AnalyseStrings', 'cleanUpEntities'], $target);
Expand Down
13 changes: 7 additions & 6 deletions app/models/consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
true
);

$target_locales_list = Utils::getHtmlSelectOptions(
Project::getRepositoryLocales($repo),
$locale
);
$reference_locale = Project::getReferenceLocale($repo);
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
// If the requested locale is not available, fall back to the first
if (! in_array($locale, $supported_locales)) {
$locale = array_shift($supported_locales);
}
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);

$available_filters = [
'all' => 'All products',
Expand All @@ -36,8 +39,6 @@
true
);

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

// Set a default for the number of strings to display
$strings_number = 0;

Expand Down
11 changes: 6 additions & 5 deletions app/models/empty_strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
true
);

$target_locales_list = Utils::getHtmlSelectOptions(
Project::getRepositoryLocales($repo),
$locale
);

$reference_locale = Project::getReferenceLocale($repo);
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
// If the requested locale is not available, fall back to the first
if (! in_array($locale, $supported_locales)) {
$locale = array_shift($supported_locales);
}
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);

$reference_strings = Utils::getRepoStrings($reference_locale, $repo);
$locale_strings = Utils::getRepoStrings($locale, $repo);
Expand Down
6 changes: 2 additions & 4 deletions app/models/showrepos.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

// Filter out empty strings and known exceptions from reference strings
$reference_locale = Project::getReferenceLocale($repo);
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);

$is_desktop_repo = in_array($repo, $desktop_repos);
$filter_strings = function ($value, $id) use ($is_desktop_repo) {
// Ignore empty strings
Expand All @@ -35,10 +37,6 @@
};
$reference_strings = array_filter(Utils::getRepoStrings($reference_locale, $repo), $filter_strings, ARRAY_FILTER_USE_BOTH);

// Get supported locales, ignore the reference locale
$supported_locales = Project::getRepositoryLocales($repo);
$supported_locales = array_diff($supported_locales, [$reference_locale]);

// Reference locale count
$string_count = [];
$reference_count = count($reference_strings);
Expand Down
16 changes: 12 additions & 4 deletions app/models/unchanged_strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
$repo,
true
);
$target_locales_list = Utils::getHtmlSelectOptions(
Project::getRepositoryLocales($repo),
$locale
);

$reference_locale = Project::getReferenceLocale($repo);
// Exclude all en-* from this view
$supported_locales = array_filter(Project::getRepositoryLocales($repo), function($loc) {
return ! Strings::startsWith($loc, 'en-');
});
// If the requested locale is not available, fall back to the first
if (! in_array($locale, $supported_locales)) {
$locale = array_shift($supported_locales);
}

$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);

// Load strings
$strings_locale = Utils::getRepoStrings($locale, $repo);
Expand Down
11 changes: 7 additions & 4 deletions app/models/unlocalized_words.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
namespace Transvision;

$target_locales_list = Utils::getHtmlSelectOptions(
Project::getRepositoryLocales($repo),
$locale
);
$reference_locale = Project::getReferenceLocale($repo);
// Exclude all en-* from this view
$supported_locales = array_filter(Project::getRepositoryLocales($repo), function($loc) {
return ! Strings::startsWith($loc, 'en-');
});

$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mozilla-l10n/phpclass-bugzilla"
"url": "https://github.com/mozilla-l10n/phpclass-bugzilla",
"no-api": true
},
{
"type": "vcs",
"url": "https://github.com/mozilla-l10n/phpclass-cache"
"url": "https://github.com/mozilla-l10n/phpclass-cache",
"no-api": true
},
{
"type": "vcs",
"url": "https://github.com/mozilla-l10n/phpclass-json"
"url": "https://github.com/mozilla-l10n/phpclass-json",
"no-api": true
},
{
"type": "vcs",
"url": "https://github.com/pascalchevrel/Verif/"
"url": "https://github.com/pascalchevrel/Verif/",
"no-api": true
},
{
"type": "package",
Expand Down
1 change: 1 addition & 0 deletions tests/testfiles/config/central.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
en-US
fr
it
12 changes: 7 additions & 5 deletions tests/units/Transvision/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,22 @@ public function testIsDesktopRepository($a, $b)
public function getRepositoryLocalesDP()
{
return [
['central', ['en-US', 'fr']],
['release', ['en-US']],
['central', ['en-US', 'fr', 'it'], []],
['central', ['fr', 'it'], ['en-US']],
['central', ['it'], ['en-US', 'fr']],
['release', ['en-US'], []],
];
}

/**
* @dataProvider getRepositoryLocalesDP
*/
public function testGetRepositoryLocales($a, $b)
public function testGetRepositoryLocales($a, $b, $c)
{
$obj = new _Project();
$this
->array($obj->getRepositoryLocales($a))
->isEqualTo($b);
->array($obj->getRepositoryLocales($a, $b))
->isEqualTo($c);
}

public function getLocaleRepositoriesDP()
Expand Down

0 comments on commit 1f9217b

Please sign in to comment.