Permalink
Browse files

Ignore en-US in some views (#876)

* 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 1f9217b0818ec1248badbb2f05572c692e30ebef
@@ -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 = [];
@@ -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;
}
@@ -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
@@ -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);
View
@@ -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',
@@ -36,8 +39,6 @@
true
);
$reference_locale = Project::getReferenceLocale($repo);
// Set a default for the number of strings to display
$strings_number = 0;
@@ -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);
View
@@ -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
@@ -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);
@@ -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);
@@ -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);
View
@@ -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",
@@ -1,2 +1,3 @@
en-US
fr
it
@@ -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()

0 comments on commit 1f9217b

Please sign in to comment.