ui: Simplify hotkey deprecation notices.

To reduce code duplication when creating hotkey deprecation notices,
create the `get_hotkey_deprecation_notice` function. Also, create a
`ui` testing file with a test for the new function.

Fix #10004.
This commit is contained in:
Marco Burstein 2018-07-20 17:19:14 -07:00 committed by Tim Abbott
parent 888434e6cd
commit bb09bea0b6
2 changed files with 18 additions and 2 deletions

View File

@ -0,0 +1,8 @@
var ui = zrequire('ui');
set_global('i18n', global.stub_i18n);
run_test('get_hotkey_deprecation_notice', () => {
var expected = 'translated: We\'ve replaced the "*" hotkey with "Ctrl + s" to make this common shortcut easier to trigger.';
var actual = ui.get_hotkey_deprecation_notice('*', 'Ctrl + s');
assert.equal(expected, actual);
});

View File

@ -123,13 +123,21 @@ exports.show_failed_message_success = function (message_id) {
});
};
exports.get_hotkey_deprecation_notice = function (originalHotkey, replacementHotkey) {
return i18n.t(
'We\'ve replaced the "__originalHotkey__" hotkey with "__replacementHotkey__" '
+ 'to make this common shortcut easier to trigger.',
{ originalHotkey: originalHotkey, replacementHotkey: replacementHotkey }
);
};
var shown_deprecation_notices = [];
exports.maybe_show_deprecation_notice = function (key) {
var message;
if (key === 'C') {
message = i18n.t('We\'ve replaced the "C" hotkey with "x" to make this common shortcut easier to trigger.');
message = exports.get_hotkey_deprecation_notice('C', 'x');
} else if (key === '*') {
message = i18n.t('We\'ve replaced the "*" hotkey with "Ctrl + s" to make this common shortcut easier to trigger.');
message = exports.get_hotkey_deprecation_notice('*', 'Ctrl + s');
} else {
blueslip.error("Unexpected deprecation notice for hotkey:", key);
return;