From e64de1211dcd79182da17857ad751554581cf1ef Mon Sep 17 00:00:00 2001 From: Francesco Lodolo Date: Mon, 10 May 2021 15:55:53 +0200 Subject: [PATCH] Improve error recovery in unlocalized-all view (#1013) --- app/controllers/unlocalized_words.php | 12 +++++++----- app/models/unlocalized_words.php | 2 +- app/models/unlocalized_words_all.php | 24 ++++++++++++++++++++---- app/views/unlocalized_words_all.php | 10 +++++++++- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/app/controllers/unlocalized_words.php b/app/controllers/unlocalized_words.php index 5de83bc5..38afab8d 100644 --- a/app/controllers/unlocalized_words.php +++ b/app/controllers/unlocalized_words.php @@ -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'; diff --git a/app/models/unlocalized_words.php b/app/models/unlocalized_words.php index 339516d6..7467748c 100644 --- a/app/models/unlocalized_words.php +++ b/app/models/unlocalized_words.php @@ -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); diff --git a/app/models/unlocalized_words_all.php b/app/models/unlocalized_words_all.php index e27b7552..543df950 100644 --- a/app/models/unlocalized_words_all.php +++ b/app/models/unlocalized_words_all.php @@ -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. @@ -50,8 +68,6 @@ 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 @@ -59,7 +75,7 @@ function filter_strings($locale, $repo, $strings_reference) */ 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'; diff --git a/app/views/unlocalized_words_all.php b/app/views/unlocalized_words_all.php index 3c2f7660..98c14fa9 100644 --- a/app/views/unlocalized_words_all.php +++ b/app/views/unlocalized_words_all.php @@ -28,7 +28,15 @@ $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 = []; } ?>