Skip to content

Commit 1f9217b

Browse files
flodoloTheoChevalier
authored andcommitted
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)
1 parent e2b495e commit 1f9217b

10 files changed

Lines changed: 67 additions & 39 deletions

File tree

app/classes/Transvision/Project.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ public static function isDesktopRepository($repo)
9797
}
9898

9999
/**
100-
* Get the list of locales available for a repository
100+
* Get the list of locales available for a repository, exclude a
101+
* subset if needed
101102
*
102103
* @param string $repository ID of the repository
104+
* @param array $ignored Array of excluded locales
103105
*
104106
* @return array A sorted list of locales
105107
*/
106-
public static function getRepositoryLocales($repository)
108+
public static function getRepositoryLocales($repository, $ignored = [])
107109
{
108110
$file_name = APP_SOURCES . "{$repository}.txt";
109111
$supported_locales = [];
@@ -118,6 +120,10 @@ public static function getRepositoryLocales($repository)
118120
}
119121
sort($supported_locales);
120122

123+
if (! empty($ignored)) {
124+
$supported_locales = array_diff($supported_locales, $ignored);
125+
}
126+
121127
return $supported_locales;
122128
}
123129

app/models/check_variables.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<?php
22
namespace Transvision;
33

4-
$source = Utils::getRepoStrings(Project::getReferenceLocale($repo), $repo);
4+
$reference_locale = Project::getReferenceLocale($repo);
5+
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
6+
// If the requested locale is not available, fall back to the first
7+
if (! in_array($locale, $supported_locales)) {
8+
$locale = array_shift($supported_locales);
9+
}
10+
11+
$source = Utils::getRepoStrings($reference_locale, $repo);
512
$target = Utils::getRepoStrings($locale, $repo);
613

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

1219
// Build the target locale switcher
13-
$target_locales_list = Utils::getHtmlSelectOptions(
14-
Project::getRepositoryLocales($repo),
15-
$locale
16-
);
20+
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);
1721

1822
$source = array_map(['Transvision\AnalyseStrings', 'cleanUpEntities'], $source);
1923
$target = array_map(['Transvision\AnalyseStrings', 'cleanUpEntities'], $target);

app/models/consistency.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
true
99
);
1010

11-
$target_locales_list = Utils::getHtmlSelectOptions(
12-
Project::getRepositoryLocales($repo),
13-
$locale
14-
);
11+
$reference_locale = Project::getReferenceLocale($repo);
12+
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
13+
// If the requested locale is not available, fall back to the first
14+
if (! in_array($locale, $supported_locales)) {
15+
$locale = array_shift($supported_locales);
16+
}
17+
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);
1518

1619
$available_filters = [
1720
'all' => 'All products',
@@ -36,8 +39,6 @@
3639
true
3740
);
3841

39-
$reference_locale = Project::getReferenceLocale($repo);
40-
4142
// Set a default for the number of strings to display
4243
$strings_number = 0;
4344

app/models/empty_strings.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
true
1212
);
1313

14-
$target_locales_list = Utils::getHtmlSelectOptions(
15-
Project::getRepositoryLocales($repo),
16-
$locale
17-
);
18-
1914
$reference_locale = Project::getReferenceLocale($repo);
15+
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
16+
// If the requested locale is not available, fall back to the first
17+
if (! in_array($locale, $supported_locales)) {
18+
$locale = array_shift($supported_locales);
19+
}
20+
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);
2021

2122
$reference_strings = Utils::getRepoStrings($reference_locale, $repo);
2223
$locale_strings = Utils::getRepoStrings($locale, $repo);

app/models/showrepos.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
// Filter out empty strings and known exceptions from reference strings
1313
$reference_locale = Project::getReferenceLocale($repo);
14+
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
15+
1416
$is_desktop_repo = in_array($repo, $desktop_repos);
1517
$filter_strings = function ($value, $id) use ($is_desktop_repo) {
1618
// Ignore empty strings
@@ -35,10 +37,6 @@
3537
};
3638
$reference_strings = array_filter(Utils::getRepoStrings($reference_locale, $repo), $filter_strings, ARRAY_FILTER_USE_BOTH);
3739

38-
// Get supported locales, ignore the reference locale
39-
$supported_locales = Project::getRepositoryLocales($repo);
40-
$supported_locales = array_diff($supported_locales, [$reference_locale]);
41-
4240
// Reference locale count
4341
$string_count = [];
4442
$reference_count = count($reference_strings);

app/models/unchanged_strings.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
$repo,
88
true
99
);
10-
$target_locales_list = Utils::getHtmlSelectOptions(
11-
Project::getRepositoryLocales($repo),
12-
$locale
13-
);
10+
11+
$reference_locale = Project::getReferenceLocale($repo);
12+
// Exclude all en-* from this view
13+
$supported_locales = array_filter(Project::getRepositoryLocales($repo), function($loc) {
14+
return ! Strings::startsWith($loc, 'en-');
15+
});
16+
// If the requested locale is not available, fall back to the first
17+
if (! in_array($locale, $supported_locales)) {
18+
$locale = array_shift($supported_locales);
19+
}
20+
21+
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);
1422

1523
// Load strings
1624
$strings_locale = Utils::getRepoStrings($locale, $repo);

app/models/unlocalized_words.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<?php
22
namespace Transvision;
33

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

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
"repositories": [
33
{
44
"type": "vcs",
5-
"url": "https://github.com/mozilla-l10n/phpclass-bugzilla"
5+
"url": "https://github.com/mozilla-l10n/phpclass-bugzilla",
6+
"no-api": true
67
},
78
{
89
"type": "vcs",
9-
"url": "https://github.com/mozilla-l10n/phpclass-cache"
10+
"url": "https://github.com/mozilla-l10n/phpclass-cache",
11+
"no-api": true
1012
},
1113
{
1214
"type": "vcs",
13-
"url": "https://github.com/mozilla-l10n/phpclass-json"
15+
"url": "https://github.com/mozilla-l10n/phpclass-json",
16+
"no-api": true
1417
},
1518
{
1619
"type": "vcs",
17-
"url": "https://github.com/pascalchevrel/Verif/"
20+
"url": "https://github.com/pascalchevrel/Verif/",
21+
"no-api": true
1822
},
1923
{
2024
"type": "package",

tests/testfiles/config/central.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
en-US
22
fr
3+
it

tests/units/Transvision/Project.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ public function testIsDesktopRepository($a, $b)
6666
public function getRepositoryLocalesDP()
6767
{
6868
return [
69-
['central', ['en-US', 'fr']],
70-
['release', ['en-US']],
69+
['central', ['en-US', 'fr', 'it'], []],
70+
['central', ['fr', 'it'], ['en-US']],
71+
['central', ['it'], ['en-US', 'fr']],
72+
['release', ['en-US'], []],
7173
];
7274
}
7375

7476
/**
7577
* @dataProvider getRepositoryLocalesDP
7678
*/
77-
public function testGetRepositoryLocales($a, $b)
79+
public function testGetRepositoryLocales($a, $b, $c)
7880
{
7981
$obj = new _Project();
8082
$this
81-
->array($obj->getRepositoryLocales($a))
82-
->isEqualTo($b);
83+
->array($obj->getRepositoryLocales($a, $b))
84+
->isEqualTo($c);
8385
}
8486

8587
public function getLocaleRepositoriesDP()

0 commit comments

Comments
 (0)