Skip to content

Commit

Permalink
Improve error recovery in unlocalized-all view (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
flodolo authored May 10, 2021
1 parent f17a9c4 commit e64de12
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
12 changes: 7 additions & 5 deletions app/controllers/unlocalized_words.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@

switch ($page) {
case 'unlocalized_all':
$all_locales = array_diff($all_locales, ['en-US', 'en-ZA', 'en-GB', 'ja-JP-mac', 'ltg']);
// Filter out English variants and ja-JP-mac
$all_locales = array_filter($all_locales, function($l) {
return ($l != 'en' && ! Strings::startsWith($l, 'en-'));
});
$all_locales = array_diff($all_locales, ['ja-JP-mac']);
include MODELS . 'unlocalized_words_all.php';
include VIEWS . 'unlocalized_words_all.php';
break;
case 'unlocalized_json':
$all_locales = [];
$all_locales[] = $locale;
$all_locales = [$locale];
include MODELS . 'unlocalized_words_all.php';
$json = $unlocalized_words;
include VIEWS . 'json.php';
break;
default:
$all_locales = [];
$all_locales[] = $locale;
$all_locales = [$locale];
include MODELS . 'unlocalized_words.php';
include MODELS . 'unlocalized_words_all.php';
include VIEWS . 'unlocalized_words.php';
Expand Down
2 changes: 1 addition & 1 deletion app/models/unlocalized_words.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$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-');
return ! Strings::startsWith($loc, 'en-') && $loc != 'en';
});

$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);
24 changes: 20 additions & 4 deletions app/models/unlocalized_words_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,25 @@
use Cache\Cache;

// Filtering out stop words from results.
$stopwords = ['318419', '9999', '8601', '6667', '2000ms', '2000', '1990', '1024', '500', '360', '200', '140', '120', '100', '45em', '30em', '26em', '22em', '6ch', '005', '128px', 'adobe', 'android', 'ansi', 'ascii', 'aurora', 'doctype', 'e10s', 'ftp', 'gecko', 'gif', 'https', 'jpg', 'nntp', 'rgb', 'txt', 'unicode', 'usascii', 'vcard', 'wwwexamplecom', 'b-163', 'k-163', 'nist', 'secg', 'sect113r1', 'sect113r2', 'sect131r1', 'sect131r2', 'sect163k1', 'sect163r1', 'sect163r2', 'sect193r1', 'sect193r2', 'secp112r1', 'secp112r2', 'secp128r1', 'secp128r2', 'secp160k1', 'secp160r1', 'secp160r2', 'secp192k1', 'secp224k1', 'secp224r1', 'secp256k1', 'secp384r1', 'secp521r1','javascript', 'prime256v1', 'c2tnb191v2', 'sect239k1', 'c2onb239v4', 'c2onb191v5', 'c2pnb163v2', 'c2tnb191v1', 'c2pnb163v3', 'c2pnb208w1', 'c2tnb431r1', 'c2tnb239v1', 'c2tnb239v2', 'c2tnb239v3', 'sect409r1', 'c2tnb359v1', 'c2tnb191v3', 'c2pnb272w1', 'c2onb191v4', 'c2pnb368w1', 'c2onb239v5', 'c2pnb163v1', 'c2pnb176v1', 'sect233k1', 'sect409k1', 'c2pnb304w1', 'iii', 'sect233r1', 'sect283r1', 'sect283k1', 'sect571r1', 'sect571k1', 'iframe', 'enctype', 'charset', 'chrome', 'pprint', 'mozcmd', 'prime239v3', 'prime239v1', 'prime192v2', 'prime239v2', 'prime192v3', 'prime192v1', 'srcdir', 'newsrc',
$stopwords = [
'318419', '9999', '8601', '6667', '2000ms', '2000', '1990', '1024', '500',
'360', '200', '140', '120', '100', '45em', '30em', '26em', '22em', '6ch',
'005', '128px', 'adobe', 'android', 'ansi', 'ascii', 'aurora', 'doctype',
'e10s', 'ftp', 'gecko', 'gif', 'https', 'jpg', 'nntp', 'rgb', 'txt',
'unicode', 'usascii', 'vcard', 'wwwexamplecom', 'b-163', 'k-163', 'nist',
'secg', 'sect113r1', 'sect113r2', 'sect131r1', 'sect131r2', 'sect163k1',
'sect163r1', 'sect163r2', 'sect193r1', 'sect193r2', 'secp112r1',
'secp112r2', 'secp128r1', 'secp128r2', 'secp160k1', 'secp160r1',
'secp160r2', 'secp192k1', 'secp224k1', 'secp224r1', 'secp256k1',
'secp384r1', 'secp521r1','javascript', 'prime256v1', 'c2tnb191v2',
'sect239k1', 'c2onb239v4', 'c2onb191v5', 'c2pnb163v2', 'c2tnb191v1',
'c2pnb163v3', 'c2pnb208w1', 'c2tnb431r1', 'c2tnb239v1', 'c2tnb239v2',
'c2tnb239v3', 'sect409r1', 'c2tnb359v1', 'c2tnb191v3', 'c2pnb272w1',
'c2onb191v4', 'c2pnb368w1', 'c2onb239v5', 'c2pnb163v1', 'c2pnb176v1',
'sect233k1', 'sect409k1', 'c2pnb304w1', 'iii', 'sect233r1', 'sect283r1',
'sect283k1', 'sect571r1', 'sect571k1', 'iframe', 'enctype', 'charset',
'chrome', 'pprint', 'mozcmd', 'prime239v3', 'prime239v1', 'prime192v2',
'prime239v2', 'prime192v3', 'prime192v1', 'srcdir', 'newsrc',
];

// Build arrays for the search form.
Expand Down Expand Up @@ -50,16 +68,14 @@ function filter_strings($locale, $repo, $strings_reference)
return $strings;
}

$all_locales = array_diff($all_locales, ['en-US', 'en-ZA', 'en-GB', 'ja-JP-mac', 'ltg']);

/*
For unlocalized and unlocalized-json, the cache for $unlocalized_words
should be the same as the cache file used for a single locale on
unlocalized-all.
*/
switch ($page) {
case 'unlocalized-all':
$cache_id = $repo . $page . 'unlocalized_words';
$cache_id = $repo . $page . 'unlocalized_words_all';
break;
default:
$cache_id = $repo . $page . $locale . 'unlocalized_words';
Expand Down
10 changes: 9 additions & 1 deletion app/views/unlocalized_words_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
</thead>
<tbody>
<?php foreach ($unlocalized_words as $english_term => $locales) :
if (! $locales) {
if (empty($locales) || is_string($locales)) {
// TODO: remove logs, see https://github.com/mozfr/transvision/issues/1010
if (is_string($locales)) {
error_log("unlocalized-all: locales is a string for \"{$english_term}\". locales var: {$locales}.");
error_log("unlocalized-all: cache-id is {$cache_id}.");
}
if (empty($locales)) {
error_log("unlocalized-all: empty list of locales for {$english_term}, creating empty array.");
}
$locales = [];
}
?>
Expand Down

0 comments on commit e64de12

Please sign in to comment.