From 3fd7cdf883fd2698cdf7491104da4b5689edfe1a Mon Sep 17 00:00:00 2001 From: Wang Zhuochun Date: Tue, 8 Oct 2013 16:30:08 +0800 Subject: [PATCH] display better shortcut conflict message --- extension/locale/en-US/vimfx.properties | 1 + extension/locale/zh-CN/vimfx.properties | 1 + extension/packages/help.coffee | 5 +++-- extension/packages/l10n.coffee | 12 +++++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/extension/locale/en-US/vimfx.properties b/extension/locale/en-US/vimfx.properties index 8f58531..6314b04 100644 --- a/extension/locale/en-US/vimfx.properties +++ b/extension/locale/en-US/vimfx.properties @@ -78,3 +78,4 @@ help_add_shortcut=Click to add new shortcut for this command help_add_shortcut_title=Enter new Shortcut help_add_shortcut_text=Please enter new shortcut for this command. Make sure to separate keys in multi key shortcuts with commas. Spaces are not allowed. Bad example: 'a c-F', proper example: 'a,c-F' help_add_shortcut_text_already_exists=This shortcut is already used +help_add_shortcut_text_already_used_by=This shortcut '%1s' is already used in '%2s' diff --git a/extension/locale/zh-CN/vimfx.properties b/extension/locale/zh-CN/vimfx.properties index 2d23cbd..6feab78 100644 --- a/extension/locale/zh-CN/vimfx.properties +++ b/extension/locale/zh-CN/vimfx.properties @@ -78,3 +78,4 @@ help_add_shortcut=为这个命令添加一个新的快捷键 help_add_shortcut_title=输入新的快捷键 help_add_shortcut_text=请为这个命令输入一个新的快捷键。请确保使用逗号分隔多键快捷键。 不允许包含空格。错误示例:'a c-F',正确示例:'a,c-F' help_add_shortcut_text_already_exists=这个快捷键已被使用 +help_add_shortcut_text_already_used_by=这个快捷键('%1s')已被'%2s'使用 diff --git a/extension/packages/help.coffee b/extension/packages/help.coffee index 0a47cd8..1ed19aa 100644 --- a/extension/packages/help.coffee +++ b/extension/packages/help.coffee @@ -73,8 +73,9 @@ installHandlers = (document, commands) -> value = { value: null } check = { value: null } if promptService.prompt(document.defaultView, title, text, value, null, check) - if commands.filter((c) => c.keys().indexOf(value.value) != -1).length > 0 - textError = _('help_add_shortcut_text_already_exists') + conflict_cmd = commands.filter((c) => c.keys().indexOf(value.value) != -1) + if conflict_cmd.length > 0 + textError = _('help_add_shortcut_text_already_used_by', null, value.value, conflict_cmd[0].help()) promptService.alert(document.defaultView, title, textError) else cmd.keys(cmd.keys().concat(value.value)) diff --git a/extension/packages/l10n.coffee b/extension/packages/l10n.coffee index 646965f..4b4f823 100644 --- a/extension/packages/l10n.coffee +++ b/extension/packages/l10n.coffee @@ -31,7 +31,7 @@ l10n = do -> addonsDefaultBundle = Services.strings.createBundle(filePath(DEFAULT_LOCALE)) # The underscore function - l10n_underscore = (aKey, aLocale) -> + l10n_underscore = (aKey, aLocale, aHolders...) -> localeBundle = null localeBasicBundle = null @@ -49,6 +49,16 @@ l10n = do -> or (defaultBasicBundle && (getStr(defaultBasicBundle, aKey) or (defaultBasicBundle = null))) \ or getStr(addonsDefaultBundle, aKey) + # If placeholder exists, substitute %s in string + # e.g. + # _("helloString", username) + # Supports `%1s`, `%2s`, ... pattern in order to change arguments order + # in translation. + if aHolders.length > 0 + offset = 0 + aVal = aVal.replace /%(\d*)(s|d)/g, (v, n) => + aHolders[if n != "" then (n - 1) else offset++] + return aVal unload(Services.strings.flushBundles) -- 2.39.3