refactor: change locale key (#3838)

This commit is contained in:
Garfield Lee
2023-09-06 15:20:44 +08:00
committed by GitHub
parent b3d902e33f
commit 925c18300f
49 changed files with 2622 additions and 2324 deletions
+207 -142
View File
@@ -1,5 +1,67 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { useMemo } from 'react';
import { useCallback, useMemo } from 'react';
type KeyboardShortcutsI18NKeys =
| 'cancel'
| 'quickSearch'
| 'newPage'
| 'appendDailyNote'
| 'expandOrCollapseSidebar'
| 'goBack'
| 'goForward'
| 'selectAll'
| 'undo'
| 'redo'
| 'zoomIn'
| 'zoomOut'
| 'zoomTo100'
| 'zoomToFit'
| 'select'
| 'text'
| 'shape'
| 'image'
| 'straightConnector'
| 'elbowedConnector'
| 'curveConnector'
| 'pen'
| 'hand'
| 'note'
| 'group'
| 'unGroup'
| 'switch'
| 'bold'
| 'italic'
| 'underline'
| 'strikethrough'
| 'inlineCode'
| 'codeBlock'
| 'link'
| 'bodyText'
| 'increaseIndent'
| 'reduceIndent'
| 'groupDatabase'
| 'moveUp'
| 'moveDown'
| 'divider';
// TODO(550): remove this hook after 'useAFFiNEI18N' support scoped i18n
const useKeyboardShortcutsI18N = () => {
const t = useAFFiNEI18N();
return useCallback(
(key: KeyboardShortcutsI18NKeys) =>
t[`com.affine.keyboardShortcuts.${key}`](),
[t]
);
};
// TODO(550): remove this hook after 'useAFFiNEI18N' support scoped i18n
const useHeadingKeyboardShortcutsI18N = () => {
const t = useAFFiNEI18N();
return useCallback(
(number: string) => t['com.affine.keyboardShortcuts.heading']({ number }),
[t]
);
};
interface ShortcutMap {
[x: string]: string[];
@@ -10,205 +72,209 @@ export interface ShortcutsInfo {
}
export const useWinGeneralKeyboardShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Cancel']()]: ['ESC'],
[t['Quick Search']()]: ['Ctrl', 'K'],
[t['New Page']()]: ['Ctrl', 'N'],
[t('cancel')]: ['ESC'],
[t('quickSearch')]: ['Ctrl', 'K'],
[t('newPage')]: ['Ctrl', 'N'],
// not implement yet
// [t['Append to Daily Note']()]: 'Ctrl + Alt + A',
[t['Expand/Collapse Sidebar']()]: ['Ctrl', '/'],
// [t('appendDailyNote')]: 'Ctrl + Alt + A',
[t('expandOrCollapseSidebar')]: ['Ctrl', '/'],
// not implement yet
// [t['Go Back']()]: 'Ctrl + [',
// [t['Go Forward']()]: 'Ctrl + ]',
// [t('goBack')]: 'Ctrl + [',
// [t('goForward')]: 'Ctrl + ]',
}),
[t]
);
};
export const useMacGeneralKeyboardShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Cancel']()]: ['ESC'],
[t['Quick Search']()]: ['⌘', 'K'],
[t['New Page']()]: ['⌘', 'N'],
[t('cancel')]: ['ESC'],
[t('quickSearch')]: ['⌘', 'K'],
[t('newPage')]: ['⌘', 'N'],
// not implement yet
// [t['Append to Daily Note']()]: '⌘ + ⌥ + A',
[t['Expand/Collapse Sidebar']()]: ['⌘', '/'],
// [t('appendDailyNote')]: '⌘ + ⌥ + A',
[t('expandOrCollapseSidebar')]: ['⌘', '/'],
// not implement yet
// [t['Go Back']()]: '⌘ + [',
// [t['Go Forward']()]: '⌘ + ]',
// [t('goBack')]: '⌘ + [',
// [t('goForward')]: '⌘ + ]',
}),
[t]
);
};
export const useMacEdgelessKeyboardShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Select All']()]: ['⌘', 'A'],
[t['Undo']()]: ['⌘', 'Z'],
[t['Redo']()]: ['⌘', '⇧', 'Z'],
[t['Zoom in']()]: ['⌘', '+'],
[t['Zoom out']()]: ['⌘', '-'],
[t['Zoom to 100%']()]: ['⌘', '0'],
[t['Zoom to fit']()]: ['⌘', '1'],
[t['Select']()]: ['V'],
[t['Text']()]: ['T'],
[t['Shape']()]: ['S'],
[t['Image']()]: ['I'],
[t['Straight Connector']()]: ['L'],
[t['Elbowed Connector']()]: ['X'],
[t('selectAll')]: ['⌘', 'A'],
[t('undo')]: ['⌘', 'Z'],
[t('redo')]: ['⌘', '⇧', 'Z'],
[t('zoomIn')]: ['⌘', '+'],
[t('zoomOut')]: ['⌘', '-'],
[t('zoomTo100')]: ['⌘', '0'],
[t('zoomToFit')]: ['⌘', '1'],
[t('select')]: ['V'],
[t('text')]: ['T'],
[t('shape')]: ['S'],
[t('image')]: ['I'],
[t('straightConnector')]: ['L'],
[t('elbowedConnector')]: ['X'],
// not implement yet
// [t['Curve Connector']()]: 'C',
[t['Pen']()]: ['P'],
[t['Hand']()]: ['H'],
[t['Note']()]: ['N'],
// [t('curveConnector')]: 'C',
[t('pen')]: ['P'],
[t('hand')]: ['H'],
[t('note')]: ['N'],
// not implement yet
// [t['Group']()]: '⌘ + G',
// [t['Ungroup']()]: '⌘ + ⇧ + G',
// [t('group')]: '⌘ + G',
// [t('unGroup')]: '⌘ + ⇧ + G',
}),
[t]
);
};
export const useWinEdgelessKeyboardShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Select All']()]: ['Ctrl', 'A'],
[t['Undo']()]: ['Ctrl', 'Z'],
[t['Redo']()]: ['Ctrl', 'Y/Ctrl', 'Shift', 'Z'],
[t['Zoom in']()]: ['Ctrl', '+'],
[t['Zoom out']()]: ['Ctrl', '-'],
[t['Zoom to 100%']()]: ['Ctrl', '0'],
[t['Zoom to fit']()]: ['Ctrl', '1'],
[t['Select']()]: ['V'],
[t['Text']()]: ['T'],
[t['Shape']()]: ['S'],
[t['Image']()]: ['I'],
[t['Straight Connector']()]: ['L'],
[t['Elbowed Connector']()]: ['X'],
[t('selectAll')]: ['Ctrl', 'A'],
[t('undo')]: ['Ctrl', 'Z'],
[t('redo')]: ['Ctrl', 'Y/Ctrl', 'Shift', 'Z'],
[t('zoomIn')]: ['Ctrl', '+'],
[t('zoomOut')]: ['Ctrl', '-'],
[t('zoomTo100')]: ['Ctrl', '0'],
[t('zoomToFit')]: ['Ctrl', '1'],
[t('select')]: ['V'],
[t('text')]: ['T'],
[t('shape')]: ['S'],
[t('image')]: ['I'],
[t('straightConnector')]: ['L'],
[t('elbowedConnector')]: ['X'],
// not implement yet
// [t['Curve Connector']()]: 'C',
[t['Pen']()]: ['P'],
[t['Hand']()]: ['H'],
[t['Note']()]: ['N'],
[t['Switch']()]: ['Alt ', ''],
// [t('curveConnector')]: 'C',
[t('pen')]: ['P'],
[t('hand')]: ['H'],
[t('note')]: ['N'],
[t('switch')]: ['Alt ', ''],
// not implement yet
// [t['Group']()]: 'Ctrl + G',
// [t['Ungroup']()]: 'Ctrl + Shift + G',
// [t('group')]: 'Ctrl + G',
// [t('unGroup')]: 'Ctrl + Shift + G',
}),
[t]
);
};
export const useMacPageKeyboardShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
const tH = useHeadingKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Undo']()]: ['⌘', 'Z'],
[t['Redo']()]: ['⌘', '⇧', 'Z'],
[t['Bold']()]: ['⌘', 'B'],
[t['Italic']()]: ['⌘', 'I'],
[t['Underline']()]: ['⌘', 'U'],
[t['Strikethrough']()]: ['⌘', '⇧', 'S'],
[t['Inline code']()]: ['⌘', 'E'],
[t['Code block']()]: ['⌘', '⌥', 'C'],
[t['Link']()]: ['⌘', 'K'],
[t['Quick search']()]: ['⌘', 'K'],
[t['Body text']()]: ['⌘', '⌥', '0'],
[t['Heading']({ number: '1' })]: ['⌘', '⌥', '1'],
[t['Heading']({ number: '2' })]: ['⌘', '⌥', '2'],
[t['Heading']({ number: '3' })]: ['⌘', '⌥', '3'],
[t['Heading']({ number: '4' })]: ['⌘', '⌥', '4'],
[t['Heading']({ number: '5' })]: ['⌘', '⌥', '5'],
[t['Heading']({ number: '6' })]: ['⌘', '⌥', '6'],
[t['Increase indent']()]: ['Tab'],
[t['Reduce indent']()]: ['⇧', 'Tab'],
[t['Group as Database']()]: ['⌘', 'G'],
[t['Switch']()]: ['⌥', 'S'],
[t('undo')]: ['⌘', 'Z'],
[t('redo')]: ['⌘', '⇧', 'Z'],
[t('bold')]: ['⌘', 'B'],
[t('italic')]: ['⌘', 'I'],
[t('underline')]: ['⌘', 'U'],
[t('strikethrough')]: ['⌘', '⇧', 'S'],
[t('inlineCode')]: ['⌘', 'E'],
[t('codeBlock')]: ['⌘', '⌥', 'C'],
[t('link')]: ['⌘', 'K'],
[t('quickSearch')]: ['⌘', 'K'],
[t('bodyText')]: ['⌘', '⌥', '0'],
[tH('1')]: ['⌘', '⌥', '1'],
[tH('2')]: ['⌘', '⌥', '2'],
[tH('3')]: ['⌘', '⌥', '3'],
[tH('4')]: ['⌘', '⌥', '4'],
[tH('5')]: ['⌘', '⌥', '5'],
[tH('6')]: ['⌘', '⌥', '6'],
[t('increaseIndent')]: ['Tab'],
[t('reduceIndent')]: ['⇧', 'Tab'],
[t('groupDatabase')]: ['⌘', 'G'],
[t('switch')]: ['⌥', 'S'],
// not implement yet
// [t['Move Up']()]: '⌘ + ⌥ + ↑',
// [t['Move Down']()]: '⌘ + ⌥ + ↓',
// [t('moveUp')]: '⌘ + ⌥ + ↑',
// [t('moveDown')]: '⌘ + ⌥ + ↓',
}),
[t]
[t, tH]
);
};
export const useMacMarkdownShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
const tH = useHeadingKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Bold']()]: ['**Text**'],
[t['Italic']()]: ['*Text*'],
[t['Underline']()]: ['~Text~'],
[t['Strikethrough']()]: ['~~Text~~'],
[t['Divider']()]: ['***'],
[t['Inline code']()]: ['`Text` '],
[t['Code block']()]: ['``` Space'],
[t['Heading']({ number: '1' })]: ['# Text'],
[t['Heading']({ number: '2' })]: ['## Text'],
[t['Heading']({ number: '3' })]: ['### Text'],
[t['Heading']({ number: '4' })]: ['#### Text'],
[t['Heading']({ number: '5' })]: ['##### Text'],
[t['Heading']({ number: '6' })]: ['###### Text'],
[t('bold')]: ['**Text**'],
[t('italic')]: ['*Text*'],
[t('underline')]: ['~Text~'],
[t('strikethrough')]: ['~~Text~~'],
[t('divider')]: ['***'],
[t('inlineCode')]: ['`Text` '],
[t('codeBlock')]: ['``` Space'],
[tH('1')]: ['# Text'],
[tH('2')]: ['## Text'],
[tH('3')]: ['### Text'],
[tH('4')]: ['#### Text'],
[tH('5')]: ['##### Text'],
[tH('6')]: ['###### Text'],
}),
[t]
[t, tH]
);
};
export const useWinPageKeyboardShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
const tH = useHeadingKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Undo']()]: ['Ctrl', 'Z'],
[t['Redo']()]: ['Ctrl', 'Y'],
[t['Bold']()]: ['Ctrl', 'B'],
[t['Italic']()]: ['Ctrl', 'I'],
[t['Underline']()]: ['Ctrl', 'U'],
[t['Strikethrough']()]: ['Ctrl', 'Shift', 'S'],
[t['Inline code']()]: [' Ctrl', 'E'],
[t['Code block']()]: ['Ctrl', 'Alt', 'C'],
[t['Link']()]: ['Ctr', 'K'],
[t['Quick search']()]: ['Ctrl', 'K'],
[t['Body text']()]: ['Ctrl', 'Shift', '0'],
[t['Heading']({ number: '1' })]: ['Ctrl', 'Shift', '1'],
[t['Heading']({ number: '2' })]: ['Ctrl', 'Shift', '2'],
[t['Heading']({ number: '3' })]: ['Ctrl', 'Shift', '3'],
[t['Heading']({ number: '4' })]: ['Ctrl', 'Shift', '4'],
[t['Heading']({ number: '5' })]: ['Ctrl', 'Shift', '5'],
[t['Heading']({ number: '6' })]: ['Ctrl', 'Shift', '6'],
[t['Increase indent']()]: ['Tab'],
[t['Reduce indent']()]: ['Shift+Tab'],
[t['Group as Database']()]: ['Ctrl + G'],
[t('undo')]: ['Ctrl', 'Z'],
[t('redo')]: ['Ctrl', 'Y'],
[t('bold')]: ['Ctrl', 'B'],
[t('italic')]: ['Ctrl', 'I'],
[t('underline')]: ['Ctrl', 'U'],
[t('strikethrough')]: ['Ctrl', 'Shift', 'S'],
[t('inlineCode')]: [' Ctrl', 'E'],
[t('codeBlock')]: ['Ctrl', 'Alt', 'C'],
[t('link')]: ['Ctr', 'K'],
[t('quickSearch')]: ['Ctrl', 'K'],
[t('bodyText')]: ['Ctrl', 'Shift', '0'],
[tH('1')]: ['Ctrl', 'Shift', '1'],
[tH('2')]: ['Ctrl', 'Shift', '2'],
[tH('3')]: ['Ctrl', 'Shift', '3'],
[tH('4')]: ['Ctrl', 'Shift', '4'],
[tH('5')]: ['Ctrl', 'Shift', '5'],
[tH('6')]: ['Ctrl', 'Shift', '6'],
[t('increaseIndent')]: ['Tab'],
[t('reduceIndent')]: ['Shift+Tab'],
[t('groupDatabase')]: ['Ctrl + G'],
['Switch']: ['Alt + S'],
// not implement yet
// [t['Move Up']()]: 'Ctrl + Alt + ↑',
// [t['Move Down']()]: 'Ctrl + Alt + ↓',
// [t('moveUp')]: 'Ctrl + Alt + ↑',
// [t('moveDown')]: 'Ctrl + Alt + ↓',
}),
[t]
[t, tH]
);
};
export const useWinMarkdownShortcuts = (): ShortcutMap => {
const t = useAFFiNEI18N();
const t = useKeyboardShortcutsI18N();
const tH = useHeadingKeyboardShortcutsI18N();
return useMemo(
() => ({
[t['Bold']()]: ['**Text** '],
[t['Italic']()]: ['*Text* '],
[t['Underline']()]: ['~Text~ '],
[t['Strikethrough']()]: ['~~Text~~ '],
[t['Divider']()]: ['***'],
[t['Inline code']()]: ['`Text` '],
[t['Code block']()]: ['``` Text'],
[t['Heading']({ number: '1' })]: ['# Text'],
[t['Heading']({ number: '2' })]: ['## Text'],
[t['Heading']({ number: '3' })]: ['### Text'],
[t['Heading']({ number: '4' })]: ['#### Text'],
[t['Heading']({ number: '5' })]: ['##### Text'],
[t['Heading']({ number: '6' })]: ['###### Text'],
[t('bold')]: ['**Text** '],
[t('italic')]: ['*Text* '],
[t('underline')]: ['~Text~ '],
[t('strikethrough')]: ['~~Text~~ '],
[t('divider')]: ['***'],
[t('inlineCode')]: ['`Text` '],
[t('codeBlock')]: ['``` Text'],
[tH('1')]: ['# Text'],
[tH('2')]: ['## Text'],
[tH('3')]: ['### Text'],
[tH('4')]: ['#### Text'],
[tH('5')]: ['##### Text'],
[tH('6')]: ['###### Text'],
}),
[t]
[t, tH]
);
};
@@ -219,7 +285,7 @@ export const useMarkdownShortcuts = (): ShortcutsInfo => {
const winMarkdownShortcuts = useWinMarkdownShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return {
title: t['Markdown Syntax'](),
title: t['com.affine.shortcutsTitle.markdownSyntax'](),
shortcuts: isMac ? macMarkdownShortcuts : winMarkdownShortcuts,
};
};
@@ -231,7 +297,7 @@ export const usePageShortcuts = (): ShortcutsInfo => {
const winPageShortcuts = useWinPageKeyboardShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return {
title: t['Page'](),
title: t['com.affine.shortcutsTitle.page'](),
shortcuts: isMac ? macPageShortcuts : winPageShortcuts,
};
};
@@ -243,7 +309,7 @@ export const useEdgelessShortcuts = (): ShortcutsInfo => {
const winEdgelessShortcuts = useWinEdgelessKeyboardShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return {
title: t['Edgeless'](),
title: t['com.affine.shortcutsTitle.edgeless'](),
shortcuts: isMac ? macEdgelessShortcuts : winEdgelessShortcuts,
};
};
@@ -254,9 +320,8 @@ export const useGeneralShortcuts = (): ShortcutsInfo => {
const macGeneralShortcuts = useMacGeneralKeyboardShortcuts();
const winGeneralShortcuts = useWinGeneralKeyboardShortcuts();
const isMac = environment.isBrowser && environment.isMacOs;
return {
title: t['General'](),
title: t['com.affine.shortcutsTitle.general'](),
shortcuts: isMac ? macGeneralShortcuts : winGeneralShortcuts,
};
};