diff --git a/app/controllers/check_variables.php b/app/controllers/check_variables.php index 1cb0ad05..d14b4578 100644 --- a/app/controllers/check_variables.php +++ b/app/controllers/check_variables.php @@ -11,7 +11,7 @@ and display the results as JSON instead of loading view and template. */ if (isset($_GET['json'])) { - $json = $var_errors; + $json = array_column($var_errors, 'string_id'); include VIEWS . 'json.php'; die(); } diff --git a/app/controllers/commandkeys.php b/app/controllers/commandkeys.php index cca4d5a4..3d347e37 100644 --- a/app/controllers/commandkeys.php +++ b/app/controllers/commandkeys.php @@ -11,7 +11,7 @@ and display the results as JSON instead of loading view and template. */ if (isset($_GET['json'])) { - $json = $commandkey_results; + $json = array_column($commandkey_results, 'id'); include VIEWS . 'json.php'; die(); } diff --git a/app/models/accesskeys.php b/app/models/accesskeys.php index 966a0219..3ed3be2a 100644 --- a/app/models/accesskeys.php +++ b/app/models/accesskeys.php @@ -1,6 +1,8 @@ 'browser/chrome/browser/browser.properties:decoder.noCodecs.button', - 'browser/chrome/browser/preferences/sync.dtd:engine.tabs.accesskey' => 'browser/chrome/browser/preferences/sync.dtd:engine.tabs.label2', -]; + // Some keys map to a different string ID than the one identified by the + // algorithm + $known_mappings = [ + 'browser/chrome/browser/browser.properties:decoder.noCodecs.accesskey' => 'browser/chrome/browser/browser.properties:decoder.noCodecs.button', + 'browser/chrome/browser/preferences/sync.dtd:engine.tabs.accesskey' => 'browser/chrome/browser/preferences/sync.dtd:engine.tabs.label2', + ]; -$ak_results = []; -foreach ($ak_string_ids as $ak_string_id) { - // Exclude accesskey if it's in a FTL file and includes PLATFORM() - if (strpos($ak_string_id, '.ftl:') !== false && strpos($source[$ak_string_id], 'PLATFORM()') !== false) { - continue; - } + $ak_results = []; + foreach ($ak_string_ids as $ak_string_id) { + // Exclude accesskey if it's in a FTL file and includes PLATFORM() + if (strpos($ak_string_id, '.ftl:') !== false && strpos($source[$ak_string_id], 'PLATFORM()') !== false) { + continue; + } - if (isset($known_mappings[$ak_string_id])) { - $entity = $known_mappings[$ak_string_id]; - // Check if the label is translated - if (isset($target[$entity]) && $target[$entity] !== '') { - $current_ak = $target[$ak_string_id]; - if (($current_ak == '') || (mb_stripos($target[$entity], $current_ak) === false)) { - $ak_results[$ak_string_id] = $entity; + if (isset($known_mappings[$ak_string_id])) { + $entity = $known_mappings[$ak_string_id]; + // Check if the label is translated + if (isset($target[$entity]) && $target[$entity] !== '') { + $current_ak = $target[$ak_string_id]; + if (($current_ak == '') || (mb_stripos($target[$entity], $current_ak) === false)) { + $ak_results[] = [ + 'label_id' => $entity, + 'label_txt' => $target[$entity], + 'accesskey_id' => $ak_string_id, + 'accesskey_txt' => $current_ak, + ]; + } } - } - } else { - foreach ($ak_labels as $ak_label) { - /* - Replace 'accesskey' with one of the known IDs used for labels. - E.g.: - * foo.accesskey -> foo.label - * foo.accesskey -> foo.title - * foo.accesskey -> foo.message - * foo.accesskey -> foo (common in devtools) - */ - $entity = str_replace('.accesskey', $ak_label, $ak_string_id); - $current_ak = $target[$ak_string_id]; + } else { + foreach ($ak_labels as $ak_label) { + /* + Replace 'accesskey' with one of the known IDs used for labels. + E.g.: + * foo.accesskey -> foo.label + * foo.accesskey -> foo.title + * foo.accesskey -> foo.message + * foo.accesskey -> foo (common in devtools) + */ + $entity = str_replace('.accesskey', $ak_label, $ak_string_id); + $current_ak = $target[$ak_string_id]; - /* - Ignore: - * Strings not available or empty in target locale. - * Empty access keys in source locale. - */ - if (isset($target[$entity]) && $target[$entity] !== '' && $source[$ak_string_id] !== '') { /* - Store the string if the access key is empty or using a - character not available in the label. + Ignore: + * Strings not available or empty in target locale. + * Empty access keys in source locale. */ - if (($current_ak == '') || (mb_stripos($target[$entity], $current_ak) === false)) { - $ak_results[$ak_string_id] = $entity; + if (isset($target[$entity]) && $target[$entity] !== '' && $source[$ak_string_id] !== '') { + /* + Store the string if the access key is empty or using a + character not available in the label. + */ + if (($current_ak == '') || (mb_stripos($target[$entity], $current_ak) === false)) { + $ak_results[] = [ + 'label_id' => $entity, + 'label_txt' => $target[$entity], + 'accesskey_id' => $ak_string_id, + 'accesskey_txt' => $current_ak, + ]; + } } - } - /* - If we found an entity with the expected name in source strings, - we should stop cycling through $ak_labels. - */ - if (isset($source[$entity])) { - break; + /* + If we found an entity with the expected name in source strings, + we should stop cycling through $ak_labels. + */ + if (isset($source[$entity])) { + break; + } } } } + Cache::setKey($cache_id, $ak_results); + unset($source); + unset($target); } // Build components filter if (in_array($repo, $desktop_repos)) { - $components = Project::getComponents(array_flip($ak_results)); + $components = Project::getComponents(array_flip(array_column($ak_results, 'accesskey_id'))); $filter_block = ShowResults::buildComponentsFilter($components); } diff --git a/app/models/check_variables.php b/app/models/check_variables.php index 03c8c497..0899f8c5 100644 --- a/app/models/check_variables.php +++ b/app/models/check_variables.php @@ -1,6 +1,8 @@ $string_id, + 'source_string' => $source[$string_id], + 'target_string' => $target[$string_id], + ]; + } + Cache::setKey($cache_id, $var_errors); + unset($source); + unset($target); +} $error_count = count($var_errors); // Build components filter if (in_array($repo, $desktop_repos)) { - $components = Project::getComponents(array_flip($var_errors)); + $components = Project::getComponents(array_flip(array_column($var_errors, 'string_id'))); $filter_block = ShowResults::buildComponentsFilter($components); } diff --git a/app/models/commandkeys.php b/app/models/commandkeys.php index 6580ba38..e3a0ee60 100644 --- a/app/models/commandkeys.php +++ b/app/models/commandkeys.php @@ -1,6 +1,8 @@ $commandkey_id, + 'source_shortcut' => $source[$commandkey_id], + 'target_shortcut' => $target[$commandkey_id], + ]; + } } + Cache::setKey($cache_id, $commandkey_results); + unset($source); + unset($target); } // Build components filter -$components = Project::getComponents(array_flip($commandkey_results)); +$components = Project::getComponents(array_flip(array_column($commandkey_results, 'id'))); $filter_block = ShowResults::buildComponentsFilter($components); // RTL support diff --git a/app/views/accesskeys.php b/app/views/accesskeys.php index 9aedc078..94a88038 100644 --- a/app/views/accesskeys.php +++ b/app/views/accesskeys.php @@ -7,6 +7,13 @@ if (! empty($ak_results)) { $search_id = 'accesskeys'; $content = ''; + + if (count($ak_results) > 200) { + $error_messages[] = 'The number of errors (' . count($ak_results) + . ') is too large and has been truncated.'; + $ak_results = array_slice($ak_results, 0, 200); + } + if (! empty($error_messages)) { $content .= '

' . implode('
', $error_messages) . @@ -35,7 +42,12 @@ // Get the tool used to edit strings for the target locale $toolUsedByTargetLocale = Project::getLocaleTool($locale); - foreach ($ak_results as $ak_string => $ak_label) { + foreach ($ak_results as $ak_result) { + $ak_string = $ak_result['accesskey_id']; + $ak_label = $ak_result['label_id']; + $accesskey_txt = $ak_result['accesskey_txt']; + $label_txt = $ak_result['label_txt']; + // Link to entity $ak_link = "?sourcelocale={$reference_locale}" . "&locale={$locale}" . @@ -52,17 +64,17 @@ $path_label = VersionControl::hgPath($locale, $repo, $ak_label); $edit_link_ak = $toolUsedByTargetLocale != '' - ? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $ak_string, $target[$ak_string], $locale) + ? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $ak_string, $accesskey_txt, $locale) : ''; $edit_link_label = $toolUsedByTargetLocale != '' - ? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $ak_label, $target[$ak_label], $locale) + ? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $ak_label, $label_txt, $locale) : ''; - $ak_value = ! empty($target[$ak_string]) - ? Utils::secureText($target[$ak_string]) + $ak_value = ! empty($accesskey_txt) + ? Utils::secureText($accesskey_txt) : '(empty)'; - $label_value = ! empty($target[$ak_label]) - ? Utils::secureText($target[$ak_label]) + $label_value = ! empty($label_txt) + ? Utils::secureText($label_txt) : '(empty)'; $component = explode('/', $ak_string)[0]; diff --git a/app/views/check_variables.php b/app/views/check_variables.php index f04b0caa..80b509e6 100644 --- a/app/views/check_variables.php +++ b/app/views/check_variables.php @@ -28,22 +28,26 @@ // Get the tool used to edit strings for the target locale $toolUsedByTargetLocale = Project::getLocaleTool($locale); - foreach ($var_errors as $string_id) { + foreach ($var_errors as $var_error) { // Link to entity + $string_id = $var_error['string_id']; + $source_string = $var_error['source_string']; + $target_string = $var_error['target_string']; + $string_id_link = "?sourcelocale={$source_locale}" . "&locale={$locale}" . "&repo={$repo}" . "&search_type=entities&recherche={$string_id}" . '&entire_string=entire_string'; $bugzilla_link = Bugzilla::reportErrorLink( - $locale, $string_id, $source[$string_id], - $target[$string_id], $repo, $string_id_link + $locale, $string_id, $source_string, + $target_string, $repo, $string_id_link ); $path_source_locale = VersionControl::hgPath($source_locale, $repo, $string_id); $path_target_locale = VersionControl::hgPath($locale, $repo, $string_id); $edit_link = $toolUsedByTargetLocale != '' - ? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $string_id, $target[$string_id], $locale) + ? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $string_id, $target_string, $locale) : ''; $component = explode('/', $string_id)[0]; @@ -56,14 +60,14 @@ {$source_locale} -

" . Utils::secureText($source[$string_id]) . "
+
" . Utils::secureText($source_string) . "
$locale -
" . Utils::secureText($target[$string_id]) . "
+
" . Utils::secureText($target_string) . "