Skip to content

Commit 995254c

Browse files
committed
feat: add tranlations to edito components
1 parent c7b08c4 commit 995254c

3 files changed

Lines changed: 36 additions & 13 deletions

File tree

apps/playground/src/components/Editor/Editor.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useRef, useState } from 'react';
22

33
import { extractInputFileExtension } from '@opendatacapture/instrument-bundler';
4+
import { useTranslation } from '@douglasneuroinformatics/libui/hooks';
45
import { Columns3Icon, FilePlusIcon, FileUpIcon } from 'lucide-react';
56
import { motion } from 'motion/react';
67
import { useShallow } from 'zustand/react/shallow';
@@ -29,6 +30,7 @@ export const Editor = () => {
2930

3031
const [isFileUploadDialogOpen, setIsFileUploadDialogOpen] = useState(false);
3132
const [isDeleteFileDialogOpen, setIsDeleteFileDialogOpen] = useState(false);
33+
const { t } = useTranslation();
3234

3335
const addFile = useAppStore((store) => store.addFile);
3436
const addFiles = useAppStore((store) => store.addFiles);
@@ -77,18 +79,22 @@ export const Editor = () => {
7779
return (
7880
<div className="flex h-full w-full flex-col border border-r-0 bg-slate-50 dark:bg-slate-800">
7981
<div className="flex w-full border-b">
80-
<EditorButton icon={<Columns3Icon />} tip="View Files" onClick={() => setIsSidebarOpen(!isSidebarOpen)} />
82+
<EditorButton
83+
icon={<Columns3Icon />}
84+
tip={t({ en: 'View Files', fr: 'Voir les fichiers' })}
85+
onClick={() => setIsSidebarOpen(!isSidebarOpen)}
86+
/>
8187
<EditorButton
8288
icon={<FilePlusIcon />}
83-
tip="Add File"
89+
tip={t({ en: 'Add File', fr: 'Ajouter un fichier' })}
8490
onClick={() => {
8591
setIsSidebarOpen(true);
8692
setIsAddingFile(true);
8793
}}
8894
/>
8995
<EditorButton
9096
icon={<FileUpIcon />}
91-
tip="Upload Files"
97+
tip={t({ en: 'Upload Files', fr: 'Téléverser des fichiers' })}
9298
onClick={() => {
9399
setIsFileUploadDialogOpen(true);
94100
}}
@@ -135,7 +141,9 @@ export const Editor = () => {
135141
{openFilenames.length ? (
136142
<EditorPane ref={editorPaneRef} onEditorMount={() => setIsEditorMounted(true)} />
137143
) : (
138-
<EditorPanePlaceholder>No File Selected</EditorPanePlaceholder>
144+
<EditorPanePlaceholder>
145+
{t({ en: 'No File Selected', fr: 'Aucun fichier sélectionné' })}
146+
</EditorPanePlaceholder>
139147
)}
140148
</div>
141149
<DeleteFileDialog
@@ -157,7 +165,7 @@ export const Editor = () => {
157165
}}
158166
isOpen={isFileUploadDialogOpen}
159167
setIsOpen={setIsFileUploadDialogOpen}
160-
title="Upload Files"
168+
title={t({ en: 'Upload Files', fr: 'Téléverser des fichiers' })}
161169
onSubmit={async (files) => {
162170
const editorFiles = await loadEditorFilesFromNative(files);
163171
addFiles(editorFiles);
@@ -166,7 +174,10 @@ export const Editor = () => {
166174
onValidate={(files: File[]) => {
167175
for (const file of files) {
168176
if (filenames.includes(file.name)) {
169-
return { message: `File already exists: ${file.name}`, result: 'error' };
177+
return {
178+
message: t({ en: `File already exists: ${file.name}`, fr: `Le fichier existe déjà : ${file.name}` }),
179+
result: 'error'
180+
};
170181
}
171182
}
172183
return { result: 'success' };

apps/playground/src/components/Editor/EditorFileButton.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useRef, useState } from 'react';
22

3-
import { useOnClickOutside } from '@douglasneuroinformatics/libui/hooks';
3+
import { useOnClickOutside, useTranslation } from '@douglasneuroinformatics/libui/hooks';
44
import { cn } from '@douglasneuroinformatics/libui/utils';
55
import { PencilIcon, TrashIcon } from 'lucide-react';
66

@@ -23,6 +23,7 @@ export const EditorFileButton = ({ filename, isActive, onDelete }: EditorFileBut
2323
const [displayFilename, setDisplayFilename] = useState(filename);
2424
const [isRenaming, setIsRenaming] = useState(false);
2525
const renameFile = useAppStore((store) => store.renameFile);
26+
const { t } = useTranslation();
2627

2728
const rename = () => {
2829
renameFile(filename, displayFilename);
@@ -79,15 +80,15 @@ export const EditorFileButton = ({ filename, isActive, onDelete }: EditorFileBut
7980
}}
8081
>
8182
<TrashIcon />
82-
<span className="ml-2 text-sm">Delete</span>
83+
<span className="ml-2 text-sm">{t({ en: 'Delete', fr: 'Supprimer' })}</span>
8384
</ContextMenu.Item>
8485
<ContextMenu.Item
8586
onSelect={() => {
8687
setIsRenaming(true);
8788
}}
8889
>
8990
<PencilIcon />
90-
<span className="ml-2 text-sm">Rename</span>
91+
<span className="ml-2 text-sm">{t({ en: 'Rename', fr: 'Renommer' })}</span>
9192
</ContextMenu.Item>
9293
</ContextMenu.Content>
9394
</ContextMenu>

apps/playground/src/components/Editor/EditorPane.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
22

3-
import { useTheme } from '@douglasneuroinformatics/libui/hooks';
3+
import { useTheme, useTranslation } from '@douglasneuroinformatics/libui/hooks';
44
import MonacoEditor from '@monaco-editor/react';
55

66
import { useFilesRef } from '@/hooks/useFilesRef';
@@ -29,6 +29,7 @@ export const EditorPane = React.forwardRef<EditorPaneRef, EditorPaneProps>(funct
2929

3030
const [theme] = useTheme();
3131
const [isMounted, setIsMounted] = useState(false);
32+
const { t } = useTranslation();
3233
const { libs } = useRuntime('v1');
3334

3435
const editorRef = useRef<MonacoEditorType | null>(null);
@@ -112,12 +113,18 @@ export const EditorPane = React.forwardRef<EditorPaneRef, EditorPaneProps>(funct
112113
};
113114

114115
if (!defaultFile) {
115-
return <EditorPanePlaceholder>No File Selected</EditorPanePlaceholder>;
116+
return (
117+
<EditorPanePlaceholder>{t({ en: 'No File Selected', fr: 'Aucun fichier sélectionné' })}</EditorPanePlaceholder>
118+
);
116119
}
117120

118121
const fileType = inferFileType(defaultFile.name);
119122
if (!fileType) {
120-
return <EditorPanePlaceholder>{`Error: Invalid file type "${fileType}"`}</EditorPanePlaceholder>;
123+
return (
124+
<EditorPanePlaceholder>
125+
{t({ en: `Error: Invalid file type "${fileType}"`, fr: `Erreur : Type de fichier invalide "${fileType}"` })}
126+
</EditorPanePlaceholder>
127+
);
121128
} else if (fileType === 'asset') {
122129
if (isBase64EncodedFileType(defaultFile.name)) {
123130
return (
@@ -130,7 +137,11 @@ export const EditorPane = React.forwardRef<EditorPaneRef, EditorPaneProps>(funct
130137
</div>
131138
);
132139
}
133-
return <EditorPanePlaceholder>Cannot Display Binary Asset</EditorPanePlaceholder>;
140+
return (
141+
<EditorPanePlaceholder>
142+
{t({ en: 'Cannot Display Binary Asset', fr: "Impossible d'afficher l'actif binaire" })}
143+
</EditorPanePlaceholder>
144+
);
134145
}
135146

136147
return (

0 commit comments

Comments
 (0)