diff --git a/.eslintignore b/.eslintignore index 0246b2d27..ae4fbcc60 100644 --- a/.eslintignore +++ b/.eslintignore @@ -284,6 +284,7 @@ packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v5/utils/useScrollUtils. packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/useEditorCommands.js +packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/localisation.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/useKeymap.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/useRefocusOnVisiblePaneChange.js packages/app-desktop/gui/NoteEditor/NoteBody/PlainEditor/PlainEditor.js diff --git a/.gitignore b/.gitignore index d727f8ce4..36b0e0f8d 100644 --- a/.gitignore +++ b/.gitignore @@ -261,6 +261,7 @@ packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v5/utils/useScrollUtils. packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/useEditorCommands.js +packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/localisation.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/useKeymap.js packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/useRefocusOnVisiblePaneChange.js packages/app-desktop/gui/NoteEditor/NoteBody/PlainEditor/PlainEditor.js diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx index c8d196830..246413217 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx @@ -14,6 +14,7 @@ import useKeymap from './utils/useKeymap'; import useEditorSearch from '../utils/useEditorSearchExtension'; import CommandService from '@joplin/lib/services/CommandService'; import { SearchMarkers } from '../../../utils/useSearchMarkers'; +import localisation from './utils/localisation'; interface Props extends EditorProps { style: React.CSSProperties; @@ -98,6 +99,7 @@ const Editor = (props: Props, ref: ForwardedRef) => { const editorProps: EditorProps = { ...props, + localisations: localisation(), onEvent: event => onEventRef.current(event), onLogMessage: message => onLogMessageRef.current(message), }; diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/localisation.ts b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/localisation.ts new file mode 100644 index 000000000..a17cf3571 --- /dev/null +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/utils/localisation.ts @@ -0,0 +1,28 @@ +import { _ } from '@joplin/lib/locale'; + +// See https://codemirror.net/examples/translate/ +export default () => ({ + // @codemirror/view + 'Control character': _('Control character'), + + // @codemirror/commands + 'Selection deleted': _('Selection deleted'), + + // @codemirror/search + 'Go to line': _('Go to line'), + 'go': _('go'), + 'Find': _('Find'), + 'Replace': _('Replace'), + 'next': _('next'), + 'previous': _('previous'), + 'all': _('all'), + 'match case': _('match case'), + 'by word': _('by word'), + 'replace': _('replace'), + 'replace all': _('replace all'), + 'close': _('close'), + 'current match': _('current match'), + 'replaced $ matches': _('replaced $ matches'), + 'replaced match on line $': _('replaced match on line $'), + 'on line': _('on line'), +}); diff --git a/packages/editor/CodeMirror/createEditor.ts b/packages/editor/CodeMirror/createEditor.ts index cd03786a2..727978867 100644 --- a/packages/editor/CodeMirror/createEditor.ts +++ b/packages/editor/CodeMirror/createEditor.ts @@ -255,6 +255,8 @@ const createEditor = ( decoratorExtension, biDirectionalTextExtension, + props.localisations ? EditorState.phrases.of(props.localisations) : [], + // Adds additional CSS classes to tokens (the default CSS classes are // auto-generated and thus unstable). syntaxHighlighting(classHighlighter), diff --git a/packages/editor/types.ts b/packages/editor/types.ts index 2c468b08b..00d820fd9 100644 --- a/packages/editor/types.ts +++ b/packages/editor/types.ts @@ -173,9 +173,15 @@ export type OnEventCallback = (event: EditorEvent)=> void; export type PasteFileCallback = (data: File)=> Promise; type OnScrollPastBeginningCallback = ()=> void; +interface Localisations { + [editorString: string]: string; +} + export interface EditorProps { settings: EditorSettings; initialText: string; + // Used mostly for internal editor library strings + localisations?: Localisations; // If null, paste and drag-and-drop will not work for resources unless handled elsewhere. onPasteFile: PasteFileCallback|null;