-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pontoon links to QA views, improve accesskeys view (#884)
* Add edit link to variables view * Add edit link to Empty strings * Improve accesskeys view
- Loading branch information
Showing
11 changed files
with
281 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Transvision; | ||
|
||
// Get requested repo and locale | ||
require_once INC . 'l10n-init.php'; | ||
|
||
include MODELS . 'accesskeys.php'; | ||
include VIEWS . 'accesskeys.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
namespace Transvision; | ||
|
||
$error_messages = []; | ||
$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); | ||
} | ||
// Build the target locale switcher | ||
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale); | ||
|
||
/* | ||
Only use desktop repositories. If the requested repository is not | ||
available, fall back to the first key. | ||
*/ | ||
$channels = array_intersect_key( | ||
Project::getSupportedRepositories(), | ||
array_flip($desktop_repos) | ||
); | ||
if (! isset($channels[$repo])) { | ||
$repo = current(array_keys($channels)); | ||
$error_messages[] = "The selected repository is not supported. Falling back to <em>{$repo}</em>."; | ||
} | ||
$channel_selector = Utils::getHtmlSelectOptions($channels, $repo, true); | ||
|
||
// Get strings | ||
$source = Utils::getRepoStrings($reference_locale, $repo); | ||
$target = Utils::getRepoStrings($locale, $repo); | ||
|
||
// Get strings with 'accesskey' in the string ID | ||
$ak_string_ids = array_filter( | ||
array_keys($target), | ||
function ($entity) { | ||
return strpos($entity, '.accesskey') !== false; | ||
} | ||
); | ||
|
||
// Possible labels associated to an access key | ||
$ak_labels = ['.label', '.title', '.message', '']; | ||
|
||
// Known false positives | ||
$ignored_ids = [ | ||
'suite/chrome/mailnews/messenger.dtd:searchButton.title', | ||
]; | ||
|
||
$ak_results = []; | ||
foreach ($ak_string_ids as $ak_string_id) { | ||
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]) && ! empty($target[$entity]) && ! empty($source[$ak_string_id]) ) { | ||
// Ignore known false positives | ||
if (in_array($entity, $ignored_ids)) { | ||
continue; | ||
} | ||
/* | ||
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[$ak_string_id] = $entity; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Add component filter | ||
if (in_array($repo, $desktop_repos)) { | ||
// Build logic to filter components | ||
$components = Project::getComponents(array_flip($ak_results)); | ||
$filter_block = ''; | ||
foreach ($components as $value) { | ||
$filter_block .= " <a href='#{$value}' id='{$value}' class='filter'>{$value}</a>"; | ||
} | ||
} | ||
|
||
// RTL support | ||
$direction = RTLSupport::getDirection($locale); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,109 @@ | ||
<?php | ||
namespace Transvision; | ||
|
||
require_once INC . 'l10n-init.php'; | ||
|
||
$strings[$repo] = Utils::getRepoStrings($locale, $repo); | ||
$strings_english[$repo] = Utils::getRepoStrings('en-US', $repo); | ||
|
||
$channel_selector = Utils::getHtmlSelectOptions( | ||
array_intersect_key( | ||
$repos_nice_names, | ||
array_flip($desktop_repos) | ||
), | ||
$repo, | ||
true | ||
); | ||
|
||
// Get the locale list | ||
$loc_list = Project::getRepositoryLocales($repo); | ||
|
||
// Build the target locale switcher | ||
$target_locales_list = Utils::getHtmlSelectOptions($loc_list, $locale); | ||
|
||
$akeys = array_filter( | ||
array_keys($strings[$repo]), | ||
function ($entity) { | ||
return substr($entity, -9) == 'accesskey'; | ||
// Include the common simple search form | ||
include __DIR__ . '/simplesearchform.php'; | ||
|
||
if (! empty($ak_results)) { | ||
$search_id = 'accesskeys'; | ||
$content = ''; | ||
if (! empty($error_messages)) { | ||
$content .= '<p class="error">' . | ||
implode('<br/>', $error_messages) . | ||
'</p>'; | ||
} | ||
); | ||
|
||
$ak_labels = ['.label', '.title', '.title2']; | ||
$ak_results = []; | ||
|
||
foreach ($akeys as $akey) { | ||
$entity = substr($akey, 0, -10); | ||
$akey_value = $strings[$repo][$akey]; | ||
|
||
foreach ($ak_labels as $ak_label) { | ||
if (isset($strings[$repo][$entity . $ak_label]) | ||
&& !empty($strings[$repo][$entity . $ak_label]) | ||
&& isset($strings_english[$repo][$akey]) | ||
&& !empty($strings_english[$repo][$akey]) | ||
) { | ||
if ($akey_value == '') { | ||
$ak_results[$akey] = $entity . $ak_label; | ||
} elseif (mb_stripos($strings[$repo][$entity . $ak_label], $akey_value) === false) { | ||
$ak_results[$akey] = $entity . $ak_label; | ||
} else { | ||
break; | ||
} | ||
} | ||
$content .= "<h2><span class=\"results_count_{$search_id}\">" | ||
. Utils::pluralize(count($ak_results), 'potential access key error') | ||
. "</span> found</h2>\n"; | ||
|
||
if (isset($filter_block)) { | ||
$content .= "<div id='filters'>" . | ||
" <h4>Filter by folder:</h4>\n" . | ||
" <a href='#showall' id='showall' class='filter'>Show all results</a>\n" . | ||
$filter_block . | ||
"</div>\n"; | ||
} | ||
|
||
$content .= " | ||
<table class='collapsable results_table sortable {$search_id}'> | ||
<thead> | ||
<tr class='column_headers'> | ||
<th>Entity</th> | ||
<th>Label</th> | ||
<th>Access key</th> | ||
<th>Access key entity</th> | ||
</tr> | ||
</thead> | ||
<tbody>\n"; | ||
|
||
// Get the tool used to edit strings for the target locale | ||
$toolUsedByTargetLocale = Project::getLocaleTool($locale); | ||
|
||
foreach ($ak_results as $ak_string => $ak_label) { | ||
// Link to entity | ||
$ak_link = "?sourcelocale={$reference_locale}" . | ||
"&locale={$locale}" . | ||
"&repo={$repo}" . | ||
"&search_type=entities&recherche={$ak_string}" . | ||
'&entire_string=entire_string'; | ||
$label_link = "?sourcelocale={$reference_locale}" . | ||
"&locale={$locale}" . | ||
"&repo={$repo}" . | ||
"&search_type=entities&recherche={$ak_label}" . | ||
'&entire_string=entire_string'; | ||
|
||
$path_ak = VersionControl::hgPath($locale, $repo, $ak_string); | ||
$path_label = VersionControl::hgPath($locale, $repo, $ak_label); | ||
|
||
$edit_link_ak = $toolUsedByTargetLocale != '' | ||
? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $ak_string, $target[$ak_string], $locale) | ||
: ''; | ||
$edit_link_label = $toolUsedByTargetLocale != '' | ||
? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $ak_label, $target[$ak_label], $locale) | ||
: ''; | ||
|
||
$ak_value = ! empty($target[$ak_string]) | ||
? Utils::secureText($target[$ak_string]) | ||
: '<em class="error">(empty)</em>'; | ||
$label_value = ! empty($target[$ak_label]) | ||
? Utils::secureText($target[$ak_label]) | ||
: '<em class="error">(empty)</em>'; | ||
|
||
$component = explode('/', $ak_string)[0]; | ||
$content .= "<tr class='{$component} {$search_id}'> | ||
<td> | ||
<span class='celltitle'>Entity</span> | ||
<span class='link_to_entity'> | ||
<a href=\"/{$label_link}\">" . ShowResults::formatEntity($ak_label) . "</a> | ||
</span> | ||
</td> | ||
<td dir='{$direction}'> | ||
<span class='celltitle'>Label</span> | ||
<div class='string'>{$label_value}</div> | ||
<div dir='ltr' class='result_meta_link'> | ||
<a class='source_link' href='{$path_label}'><source></a> | ||
{$edit_link_label} | ||
</div> | ||
</td> | ||
<td dir='{$direction}'> | ||
<span class='celltitle'>Access key</span> | ||
<div class='string'>{$ak_value}</div> | ||
<div dir='ltr' class='result_meta_link'> | ||
<a class='source_link' href='{$path_ak}'><source></a> | ||
{$edit_link_ak} | ||
</div> | ||
</td> | ||
<td> | ||
<span class='celltitle'>Access key entity</span> | ||
<span class='link_to_entity'> | ||
<a href=\"/{$ak_link}\">" . ShowResults::formatEntity($ak_string) . "</a> | ||
</span> | ||
</td> | ||
</tr>\n"; | ||
} | ||
$content .= "</tbody>\n</table>\n"; | ||
} else { | ||
$content = '<h2>Congratulations, no errors found.</h2>'; | ||
} | ||
// Include the common simple search form | ||
include __DIR__ . '/simplesearchform.php'; | ||
|
||
echo '<h2>' . count($ak_results) . ' potential accesskey errors</h2>'; | ||
Utils::printSimpleTable( | ||
$ak_results, | ||
$strings[$repo], | ||
['Label entity', 'Label value', 'Access key', 'Access key entity'], | ||
'collapsable sortable' | ||
); | ||
print $content; |
Oops, something went wrong.