Skip to content

Commit e80bd1d

Browse files
authored
(fix #905) New QA view: keyboard shortcuts (#906)
1 parent 5d421f2 commit e80bd1d

File tree

8 files changed

+221
-3
lines changed

8 files changed

+221
-3
lines changed

app/controllers/commandkeys.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Transvision;
3+
4+
// Get requested repo and locale
5+
require_once INC . 'l10n-init.php';
6+
7+
include MODELS . 'commandkeys.php';
8+
include VIEWS . 'commandkeys.php';

app/inc/dispatcher.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
$js_files[] = '/js/component_filter.js';
4242
$js_files[] = '/js/sorttable.js';
4343
break;
44+
case 'commandkeys':
45+
$controller = 'commandkeys';
46+
$experimental = true;
47+
$page_title = 'Keyboard Shortcuts';
48+
$page_descr = 'Check your keyboard shortcuts.';
49+
$js_files[] = '/js/component_filter.js';
50+
$js_files[] = '/js/sorttable.js';
51+
break;
4452
case Strings::StartsWith($url['path'], 'api'):
4553
$controller = 'api';
4654
$page_title = 'API response';

app/inc/urls.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
$urls = [
44
'/' => 'root',
55
'3locales' => '3locales',
6-
'accesskeys' => 'keys',
6+
'accesskeys' => 'accesskeys',
7+
'commandkeys' => 'commandkeys',
78
'api' => 'api',
89
'consistency' => 'consistency',
910
'credits' => 'credits',

app/models/commandkeys.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
namespace Transvision;
3+
4+
$error_messages = [];
5+
$reference_locale = Project::getReferenceLocale($repo);
6+
$supported_locales = Project::getRepositoryLocales($repo, [$reference_locale]);
7+
// If the requested locale is not available, fall back to the first
8+
if (! in_array($locale, $supported_locales)) {
9+
$locale = array_shift($supported_locales);
10+
}
11+
// Build the target locale switcher
12+
$target_locales_list = Utils::getHtmlSelectOptions($supported_locales, $locale);
13+
14+
/*
15+
Only use desktop repositories. If the requested repository is not
16+
available, fall back to the first key.
17+
*/
18+
$channels = array_intersect_key(
19+
Project::getSupportedRepositories(),
20+
array_flip($desktop_repos)
21+
);
22+
if (! isset($channels[$repo])) {
23+
$repo = current(array_keys($channels));
24+
$error_messages[] = "The selected repository is not supported. Falling back to <em>{$repo}</em>.";
25+
}
26+
$channel_selector = Utils::getHtmlSelectOptions($channels, $repo, true);
27+
28+
// Get strings
29+
$source = Utils::getRepoStrings($reference_locale, $repo);
30+
$target = Utils::getRepoStrings($locale, $repo);
31+
32+
// Get string IDs in target ending with '.key' or '.commandkey'
33+
$commandkey_ids = array_filter(
34+
array_keys($target),
35+
function ($entity) {
36+
return Strings::endsWith($entity, ['.key', '.commandkey']);
37+
}
38+
);
39+
40+
// Known false positives to ignore
41+
$ignored_ids = [
42+
'browser/chrome/browser/browser.properties:addonPostInstall.okay.key',
43+
'devtools/client/webconsole.properties:table.key',
44+
'extensions/irc/chrome/chatzilla.properties:msg.url.key',
45+
];
46+
$ignored_files = [
47+
'extensions/irc/chrome/chatzilla.properties',
48+
'toolkit/chrome/global/charsetMenu.properties',
49+
];
50+
51+
$commandkey_results = [];
52+
/*
53+
Get keyboard shortcuts different from English (ignoring case), and
54+
exclude known false positives.
55+
*/
56+
foreach ($commandkey_ids as $commandkey_id) {
57+
if (in_array($commandkey_id, $ignored_ids)) {
58+
continue;
59+
}
60+
61+
if (Strings::startsWith($commandkey_id, $ignored_files)) {
62+
continue;
63+
}
64+
65+
if (mb_strtoupper($target[$commandkey_id]) != mb_strtoupper($source[$commandkey_id])) {
66+
$commandkey_results[] = $commandkey_id;
67+
}
68+
}
69+
70+
// Add component filter
71+
// Build logic to filter components
72+
$components = Project::getComponents(array_flip($commandkey_results));
73+
$filter_block = '';
74+
foreach ($components as $value) {
75+
$filter_block .= " <a href='#{$value}' id='{$value}' class='filter'>{$value}</a>";
76+
}
77+
78+
// RTL support
79+
$text_direction = RTLSupport::getDirection($locale);

app/views/commandkeys.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
namespace Transvision;
3+
4+
// Include the common simple search form
5+
include __DIR__ . '/simplesearchform.php';
6+
7+
if (! empty($commandkey_results)) {
8+
$search_id = 'commandkeys';
9+
$content = '';
10+
if (! empty($error_messages)) {
11+
$content .= '<p class="error">' .
12+
implode('<br/>', $error_messages) .
13+
'</p>';
14+
}
15+
$content .= "<h2><span class=\"results_count_{$search_id}\">"
16+
. Utils::pluralize(count($commandkey_results), 'potential keyboard shortcuts error')
17+
. "</span> found</h2>\n";
18+
19+
if (isset($filter_block)) {
20+
$content .= "<div id='filters'>" .
21+
" <h4>Filter by folder:</h4>\n" .
22+
" <a href='#showall' id='showall' class='filter'>Show all results</a>\n" .
23+
$filter_block .
24+
"</div>\n";
25+
}
26+
27+
$content .= "
28+
<table class='collapsable results_table sortable {$search_id}'>
29+
<thead>
30+
<tr class='column_headers'>
31+
<th>Entity</th>
32+
<th>{$reference_locale}</th>
33+
<th>{$locale}</th>
34+
</tr>
35+
</thead>
36+
<tbody>\n";
37+
38+
// Get the tool used to edit strings for the target locale
39+
$toolUsedByTargetLocale = Project::getLocaleTool($locale);
40+
41+
foreach ($commandkey_results as $key) {
42+
$entity = ShowResults::formatEntity($key);
43+
$component = explode('/', $key)[0];
44+
45+
$entity_link = "?sourcelocale={$reference_locale}"
46+
. "&locale={$locale}"
47+
. "&repo={$repo}"
48+
. "&search_type=entities&recherche={$key}"
49+
. '&entire_string=entire_string';
50+
51+
$translated_shortcut = $target[$key];
52+
$source_shortcut = $source[$key];
53+
54+
$edit_link = $toolUsedByTargetLocale != ''
55+
? ShowResults::getEditLink($toolUsedByTargetLocale, $repo, $key, $translated_shortcut, $locale)
56+
: '';
57+
58+
$bugzilla_link = [Bugzilla::reportErrorLink(
59+
$locale, $key, $source_shortcut, $translated_shortcut, $repo, $entity_link
60+
)];
61+
62+
$reference_path = VersionControl::hgPath($reference_locale, $repo, $key);
63+
$locale_path = VersionControl::hgPath($locale, $repo, $key);
64+
65+
if (! $source_shortcut) {
66+
$source_shortcut = '<em class="error">(empty)</em>';
67+
}
68+
if ($translated_shortcut == '@@missing@@') {
69+
$translated_shortcut = '<em class="error">Missing string</em>';
70+
} elseif ($translated_shortcut == '') {
71+
$translated_shortcut = '<em class="error">(empty)</em>';
72+
}
73+
74+
// Replace / and : in the key name and use it as an anchor name
75+
$anchor_name = str_replace(['/', ':'], '_', $key);
76+
77+
$content .= "
78+
<tr class='{$component} {$search_id}'>
79+
<td>
80+
<span class='celltitle'>Entity</span>
81+
<a class='resultpermalink tag' id='{$anchor_name}' href='#{$anchor_name}' title='Permalink to this string'>#</a>
82+
<a class='l10n tag' href='/string/?entity={$key}&amp;repo={$repo}' title='List all translations for this entity'>all locales</a>
83+
<span class='link_to_entity'>
84+
<a href=\"/{$entity_link}\">{$entity}</a>
85+
</span>
86+
</td>
87+
<td dir='ltr' lang='{$reference_locale}'>
88+
<span class='celltitle'>{$reference_locale}</span>
89+
<div class='string'>
90+
{$source_shortcut}
91+
</div>
92+
<div dir='ltr' class='result_meta_link'>
93+
<a class='source_link' href='{$reference_path}'>
94+
&lt;source&gt;
95+
</a>
96+
</div>
97+
</td>
98+
<td dir='{$text_direction}' lang='{$locale}'>
99+
<span class='celltitle'>{$locale}</span>
100+
<div class='string'>{$translated_shortcut}</div>
101+
<div dir='ltr' class='result_meta_link'>
102+
<a class='source_link' href='{$locale_path}'>
103+
&lt;source&gt;
104+
</a>
105+
{$edit_link}
106+
&nbsp;
107+
<a class='bug_link' target='_blank' href='{$bugzilla_link[0]}'>
108+
&lt;report a bug&gt;
109+
</a>
110+
</div>
111+
</td>
112+
</tr>";
113+
}
114+
$content .= "</tbody>\n</table>\n";
115+
} else {
116+
$content = '<h2>Congratulations, no errors found.</h2>';
117+
}
118+
119+
print $content;

app/views/templates/base.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
<div class="linkscolumn" id="qa_column">
4444
<h3>QA Views</h3>
4545
<ul>
46-
{$li_link('keys', 'Check your access keys', 'Access Keys')}
46+
{$li_link('accesskeys', 'Check your access keys', 'Access Keys')}
47+
{$li_link('commandkeys', 'Check your keyboard shortcuts', 'Keyboard Shortcuts')}
4748
{$li_link('checkvariables', 'Check what variable differences there are from English', 'Check Variables')}
4849
{$li_link('empty_strings', 'Display empty strings in English or locale', 'Empty Strings')}
4950
{$li_link('unchangedstrings', 'Display all strings identical to English', 'Unchanged Strings')}

tests/functional/pages.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
include 'includes/init.php';
44

55
$paths = [
6+
['accesskeys/', 200, 'Access Keys', 'Congratulations, no errors found.'],
7+
['commandkeys/', 200, 'Keyboard Shortcuts', 'Repository'],
68
['consistency/?locale=fr&repo=gecko_strings', 200, 'English String', 'Available Translations'],
79
['consistency/?locale=fr&repo=gecko_strings', 200, 'Translation Consistency', 'Analyze translation consistency across repositories.'],
810
['credits/', 200, 'Transvision 1.0 was created', 'Transvision is a community project under the MozFR umbrella'],

web/style/transvision.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ input[type="checkbox"]:disabled + label {
10431043
}
10441044

10451045
/* Access keys view */
1046-
#keys .error {
1046+
#accesskeys .error {
10471047
margin: 0 auto;
10481048
text-align: center;
10491049
width: 75%;

0 commit comments

Comments
 (0)