feat: add translations and reset functionality for new features

This commit is contained in:
kangfenmao 2024-12-02 22:29:18 +08:00
parent 7dacd58821
commit cd3c053f81
5 changed files with 34 additions and 7 deletions

View File

@ -456,7 +456,9 @@
"zoom_reset": "Reset Zoom", "zoom_reset": "Reset Zoom",
"show_app": "Show App", "show_app": "Show App",
"reset_defaults": "Reset Defaults", "reset_defaults": "Reset Defaults",
"press_shortcut": "Press Shortcut" "reset_defaults_confirm": "Are you sure you want to reset all shortcuts?",
"press_shortcut": "Press Shortcut",
"alt_warning": "Mac does not support the Alt key"
}, },
"theme.auto": "Auto", "theme.auto": "Auto",
"theme.dark": "Dark", "theme.dark": "Dark",

View File

@ -456,7 +456,9 @@
"zoom_reset": "Сбросить масштаб", "zoom_reset": "Сбросить масштаб",
"show_app": "Показать приложение", "show_app": "Показать приложение",
"reset_defaults": "Сбросить настройки по умолчанию", "reset_defaults": "Сбросить настройки по умолчанию",
"press_shortcut": "Нажмите сочетание клавиш" "reset_defaults_confirm": "Вы уверены, что хотите сбросить все горячие клавиши?",
"press_shortcut": "Нажмите сочетание клавиш",
"alt_warning": "Mac не поддерживает Alt"
}, },
"theme.auto": "Автоматически", "theme.auto": "Автоматически",
"theme.dark": "Темная", "theme.dark": "Темная",

View File

@ -444,7 +444,9 @@
"zoom_reset": "重置缩放", "zoom_reset": "重置缩放",
"show_app": "显示应用", "show_app": "显示应用",
"reset_defaults": "重置默认快捷键", "reset_defaults": "重置默认快捷键",
"press_shortcut": "按下快捷键" "reset_defaults_confirm": "确定要重置所有快捷键吗?",
"press_shortcut": "按下快捷键",
"alt_warning": "Mac 系统不支持 Alt 键"
}, },
"theme.auto": "跟随系统", "theme.auto": "跟随系统",
"theme.dark": "深色主题", "theme.dark": "深色主题",

View File

@ -444,7 +444,9 @@
"zoom_reset": "重置縮放", "zoom_reset": "重置縮放",
"show_app": "顯示應用", "show_app": "顯示應用",
"reset_defaults": "重置預設快捷鍵", "reset_defaults": "重置預設快捷鍵",
"press_shortcut": "按下快捷鍵" "reset_defaults_confirm": "確定要重置所有快捷鍵嗎?",
"press_shortcut": "按下快捷鍵",
"alt_warning": "Mac 系統不支持 Alt 鍵"
}, },
"theme.auto": "自動", "theme.auto": "自動",
"theme.dark": "深色主題", "theme.dark": "深色主題",

View File

@ -1,4 +1,5 @@
import { UndoOutlined } from '@ant-design/icons' import { UndoOutlined } from '@ant-design/icons'
import { HStack } from '@renderer/components/Layout'
import { isMac } from '@renderer/config/constant' import { isMac } from '@renderer/config/constant'
import { useTheme } from '@renderer/context/ThemeProvider' import { useTheme } from '@renderer/context/ThemeProvider'
import { useAppDispatch, useAppSelector } from '@renderer/store' import { useAppDispatch, useAppSelector } from '@renderer/store'
@ -62,6 +63,15 @@ const ShortcutSettings: FC = () => {
const isValidShortcut = (keys: string[]): boolean => { const isValidShortcut = (keys: string[]): boolean => {
const hasModifier = keys.some((key) => ['Control', 'Ctrl', 'Command', 'Alt', 'Shift'].includes(key)) const hasModifier = keys.some((key) => ['Control', 'Ctrl', 'Command', 'Alt', 'Shift'].includes(key))
const hasNonModifier = keys.some((key) => !['Control', 'Ctrl', 'Command', 'Alt', 'Shift'].includes(key)) const hasNonModifier = keys.some((key) => !['Control', 'Ctrl', 'Command', 'Alt', 'Shift'].includes(key))
if (isMac && keys.includes('Alt')) {
window.message.warning({
content: t('settings.shortcuts.alt_warning'),
key: 'shortcut-alt-warning'
})
return false
}
return hasModifier && hasNonModifier && keys.length >= 2 return hasModifier && hasNonModifier && keys.length >= 2
} }
@ -104,6 +114,7 @@ const ShortcutSettings: FC = () => {
if (e.shiftKey) keys.push('Shift') if (e.shiftKey) keys.push('Shift')
const key = e.key const key = e.key
if (!['Control', 'Alt', 'Shift', 'Meta'].includes(key)) { if (!['Control', 'Alt', 'Shift', 'Meta'].includes(key)) {
keys.push(key.toUpperCase()) keys.push(key.toUpperCase())
} }
@ -125,6 +136,14 @@ const ShortcutSettings: FC = () => {
setEditingKey(null) setEditingKey(null)
} }
const handleResetAllShortcuts = () => {
window.modal.confirm({
title: t('settings.shortcuts.reset_defaults_confirm'),
centered: true,
onOk: () => dispatch(resetShortcuts())
})
}
const columns: ColumnsType<ShortcutItem> = [ const columns: ColumnsType<ShortcutItem> = [
{ {
title: t('settings.shortcuts.action'), title: t('settings.shortcuts.action'),
@ -203,9 +222,9 @@ const ShortcutSettings: FC = () => {
showHeader={false} showHeader={false}
/> />
<SettingDivider style={{ marginBottom: 0 }} /> <SettingDivider style={{ marginBottom: 0 }} />
<div style={{ display: 'flex', justifyContent: 'flex-end', padding: '16px 0' }}> <HStack justifyContent="flex-end" padding="16px 0">
<Button onClick={() => dispatch(resetShortcuts())}>{t('settings.shortcuts.reset_defaults')}</Button> <Button onClick={handleResetAllShortcuts}>{t('settings.shortcuts.reset_defaults')}</Button>
</div> </HStack>
</SettingGroup> </SettingGroup>
</SettingContainer> </SettingContainer>
) )