add translation for shortcuts.js

This commit is contained in:
Nriver 2024-08-14 17:12:33 +08:00
parent 68733cf0c2
commit 78e908c761
3 changed files with 47 additions and 20 deletions

View File

@ -2,6 +2,7 @@ import server from "../../../services/server.js";
import utils from "../../../services/utils.js"; import utils from "../../../services/utils.js";
import dialogService from "../../../services/dialog.js"; import dialogService from "../../../services/dialog.js";
import OptionsWidget from "./options_widget.js"; import OptionsWidget from "./options_widget.js";
import { t } from "../../../services/i18n.js";
const TPL = ` const TPL = `
<div class="options-section shortcuts-options-section"> <div class="options-section shortcuts-options-section">
@ -25,25 +26,25 @@ const TPL = `
} }
</style> </style>
<h4>Keyboard Shortcuts</h4> <h4>${t('shortcuts.keyboard_shortcuts')}</h4>
<p> <p>
Multiple shortcuts for the same action can be separated by comma. ${t('shortcuts.multiple_shortcuts')}
See <a href="https://www.electronjs.org/docs/latest/api/accelerator">Electron documentation</a> for available modifiers and key codes. ${t('shortcuts.electron_documentation')}
</p> </p>
<div class="form-group"> <div class="form-group">
<input type="text" class="keyboard-shortcut-filter form-control" placeholder="Type text to filter shortcuts..."> <input type="text" class="keyboard-shortcut-filter form-control" placeholder="${t('shortcuts.type_text_to_filter')}">
</div> </div>
<div class="shortcuts-table-container"> <div class="shortcuts-table-container">
<table class="keyboard-shortcut-table" cellpadding="10"> <table class="keyboard-shortcut-table" cellpadding="10">
<thead> <thead>
<tr> <tr>
<th>Action name</th> <th>${t('shortcuts.action_name')}</th>
<th>Shortcuts</th> <th>${t('shortcuts.shortcuts')}</th>
<th>Default shortcuts</th> <th>${t('shortcuts.default_shortcuts')}</th>
<th>Description</th> <th>${t('shortcuts.description')}</th>
</tr> </tr>
</thead> </thead>
<tbody></tbody> <tbody></tbody>
@ -51,9 +52,9 @@ const TPL = `
</div> </div>
<div class="shortcuts-options-buttons"> <div class="shortcuts-options-buttons">
<button class="options-keyboard-shortcuts-reload-app btn btn-primary">Reload app to apply changes</button> <button class="options-keyboard-shortcuts-reload-app btn btn-primary">${t('shortcuts.reload_app')}</button>
<button class="options-keyboard-shortcuts-set-all-to-default btn">Set all shortcuts to the default</button> <button class="options-keyboard-shortcuts-set-all-to-default btn">${t('shortcuts.set_all_to_default')}</button>
</div> </div>
</div>`; </div>`;
@ -83,10 +84,10 @@ export default class KeyboardShortcutsOptions extends OptionsWidget {
else { else {
$tr.append($("<td>").text(action.actionName)) $tr.append($("<td>").text(action.actionName))
.append($("<td>").append( .append($("<td>").append(
$(`<input type="text" class="form-control">`) $(`<input type="text" class="form-control">`)
.val(action.effectiveShortcuts.join(", ")) .val(action.effectiveShortcuts.join(", "))
.attr('data-keyboard-action-name', action.actionName) .attr('data-keyboard-action-name', action.actionName)
.attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", ")) .attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", "))
) )
) )
.append($("<td>").text(action.defaultShortcuts.join(", "))) .append($("<td>").text(action.defaultShortcuts.join(", ")))
@ -101,10 +102,10 @@ export default class KeyboardShortcutsOptions extends OptionsWidget {
const $input = this.$widget.find(e.target); const $input = this.$widget.find(e.target);
const actionName = $input.attr('data-keyboard-action-name'); const actionName = $input.attr('data-keyboard-action-name');
const shortcuts = $input.val() const shortcuts = $input.val()
.replace('+,', "+Comma") .replace('+,', "+Comma")
.split(",") .split(",")
.map(shortcut => shortcut.replace("+Comma", "+,")) .map(shortcut => shortcut.replace("+Comma", "+,"))
.filter(shortcut => !!shortcut); .filter(shortcut => !!shortcut);
const optionName = `keyboardShortcuts${actionName.substr(0, 1).toUpperCase()}${actionName.substr(1)}`; const optionName = `keyboardShortcuts${actionName.substr(0, 1).toUpperCase()}${actionName.substr(1)}`;
@ -112,7 +113,7 @@ export default class KeyboardShortcutsOptions extends OptionsWidget {
}); });
this.$widget.find(".options-keyboard-shortcuts-set-all-to-default").on('click', async () => { this.$widget.find(".options-keyboard-shortcuts-set-all-to-default").on('click', async () => {
if (!await dialogService.confirm("Do you really want to reset all keyboard shortcuts to the default?")) { if (!await dialogService.confirm(t('shortcuts.confirm_reset'))) {
return; return;
} }
@ -152,7 +153,7 @@ export default class KeyboardShortcutsOptions extends OptionsWidget {
return; return;
} }
this.$widget.find(el).toggle(!!( // !! to avoid toggle overloads with different behavior this.$widget.find(el).toggle(!!(
action.actionName.toLowerCase().includes(filter) action.actionName.toLowerCase().includes(filter)
|| action.defaultShortcuts.some(shortcut => shortcut.toLowerCase().includes(filter)) || action.defaultShortcuts.some(shortcut => shortcut.toLowerCase().includes(filter))
|| action.effectiveShortcuts.some(shortcut => shortcut.toLowerCase().includes(filter)) || action.effectiveShortcuts.some(shortcut => shortcut.toLowerCase().includes(filter))

View File

@ -1181,5 +1181,18 @@
"set_password": "设置密码", "set_password": "设置密码",
"password_mismatch": "新密码不一致。", "password_mismatch": "新密码不一致。",
"password_changed_success": "密码已更改。按 OK 后 Trilium 将重新加载。" "password_changed_success": "密码已更改。按 OK 后 Trilium 将重新加载。"
},
"shortcuts": {
"keyboard_shortcuts": "快捷键",
"multiple_shortcuts": "同一操作的多个快捷键可以用逗号分隔。",
"electron_documentation": "请参阅 <a href=\"https://www.electronjs.org/docs/latest/api/accelerator\">Electron文档</a>,了解可用的修饰符和键码。",
"type_text_to_filter": "输入文字以过滤快捷键...",
"action_name": "操作名称",
"shortcuts": "快捷键",
"default_shortcuts": "默认快捷键",
"description": "描述",
"reload_app": "重新加载应用以应用更改",
"set_all_to_default": "将所有快捷键重置为默认值",
"confirm_reset": "您确定要将所有键盘快捷键重置为默认值吗?"
} }
} }

View File

@ -1182,5 +1182,18 @@
"set_password": "Set Password", "set_password": "Set Password",
"password_mismatch": "New passwords are not the same.", "password_mismatch": "New passwords are not the same.",
"password_changed_success": "Password has been changed. Trilium will be reloaded after you press OK." "password_changed_success": "Password has been changed. Trilium will be reloaded after you press OK."
},
"shortcuts": {
"keyboard_shortcuts": "Keyboard Shortcuts",
"multiple_shortcuts": "Multiple shortcuts for the same action can be separated by comma.",
"electron_documentation": "See <a href=\"https://www.electronjs.org/docs/latest/api/accelerator\">Electron documentation</a> for available modifiers and key codes.",
"type_text_to_filter": "Type text to filter shortcuts...",
"action_name": "Action name",
"shortcuts": "Shortcuts",
"default_shortcuts": "Default shortcuts",
"description": "Description",
"reload_app": "Reload app to apply changes",
"set_all_to_default": "Set all shortcuts to the default",
"confirm_reset": "Do you really want to reset all keyboard shortcuts to the default?"
} }
} }