Skip to content

Commit df5cea5

Browse files
committed
feat: add translations to button components and their dialogs
1 parent 995254c commit df5cea5

6 files changed

Lines changed: 44 additions & 21 deletions

File tree

apps/playground/src/components/Header/CloneButton/CloneButton.tsx

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

33
import { Dialog, Form, Tooltip } from '@douglasneuroinformatics/libui/components';
4-
import { useNotificationsStore } from '@douglasneuroinformatics/libui/hooks';
4+
import { useNotificationsStore, useTranslation } from '@douglasneuroinformatics/libui/hooks';
55
import { CopyPlusIcon } from 'lucide-react';
66
import { z } from 'zod/v4';
77

@@ -16,6 +16,7 @@ export const CloneButton = () => {
1616
const addInstrument = useAppStore((store) => store.addInstrument);
1717
const setSelectedInstrument = useAppStore((store) => store.setSelectedInstrument);
1818
const editorFilesRef = useFilesRef();
19+
const { t } = useTranslation();
1920

2021
const handleSubmit = ({ label }: { label: string }) => {
2122
const files = editorFilesRef.current;
@@ -42,36 +43,39 @@ export const CloneButton = () => {
4243
</Dialog.Trigger>
4344
<Dialog.Content className="sm:max-w-[475px]">
4445
<Dialog.Header>
45-
<Dialog.Title>Create New Instrument</Dialog.Title>
46+
<Dialog.Title>{t({ en: 'Create New Instrument', fr: 'Créer un nouvel instrument' })}</Dialog.Title>
4647
<Dialog.Description>
47-
This will save the current playground state in local storage as a new instrument.
48+
{t({
49+
en: 'This will save the current playground state in local storage as a new instrument.',
50+
fr: "Ceci enregistrera l'état actuel du terrain de jeu dans le stockage local en tant que nouvel instrument."
51+
})}
4852
</Dialog.Description>
4953
</Dialog.Header>
5054
<Form
5155
className="[&_button]:max-w-32"
5256
content={{
5357
label: {
5458
kind: 'string',
55-
label: 'Label',
59+
label: t({ en: 'Label', fr: 'Nom' }),
5660
variant: 'input'
5761
}
5862
}}
59-
submitBtnLabel="Save"
63+
submitBtnLabel={t({ en: 'Save', fr: 'Enregistrer' })}
6064
validationSchema={z.object({
6165
label: z
6266
.string()
6367
.min(1)
6468
.refine(
6569
(arg) => !instruments.find((instrument) => instrument.label === arg),
66-
'An instrument with this label already exists'
70+
t({ en: 'An instrument with this label already exists', fr: 'Un instrument avec ce nom existe déjà' })
6771
)
6872
})}
6973
onSubmit={(data) => void handleSubmit(data)}
7074
/>
7175
</Dialog.Content>
7276
</Dialog>
7377
<Tooltip.Content side="bottom">
74-
<p>Create New Instrument</p>
78+
<p>{t({ en: 'Create New Instrument', fr: 'Créer un nouvel instrument' })}</p>
7579
</Tooltip.Content>
7680
</Tooltip>
7781
);

apps/playground/src/components/Header/DownloadButton/DownloadButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useDownload } from '@douglasneuroinformatics/libui/hooks';
1+
import { useDownload, useTranslation } from '@douglasneuroinformatics/libui/hooks';
22
import JSZip from 'jszip';
33
import { DownloadIcon } from 'lucide-react';
44

@@ -24,10 +24,12 @@ export const DownloadButton = () => {
2424
await download(`${baseName}.zip`, file, { blobType: 'application/zip' });
2525
};
2626

27+
const { t } = useTranslation();
28+
2729
return (
2830
<ActionButton
2931
icon={<DownloadIcon />}
30-
tooltip="Download Archive"
32+
tooltip={t({ en: 'Download Archive', fr: "Télécharger l'archive" })}
3133
onClick={() => {
3234
void downloadFiles();
3335
}}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useTranslation } from '@douglasneuroinformatics/libui/hooks';
12
import { RefreshCwIcon } from 'lucide-react';
23

34
import { useAppStore } from '@/store';
@@ -6,5 +7,6 @@ import { ActionButton } from '../ActionButton';
67

78
export const RefreshButton = () => {
89
const onClick = useAppStore((store) => store.viewer.forceRefresh);
9-
return <ActionButton icon={<RefreshCwIcon />} tooltip="Refresh" onClick={onClick} />;
10+
const { t } = useTranslation();
11+
return <ActionButton icon={<RefreshCwIcon />} tooltip={t({ en: 'Refresh', fr: 'Actualiser' })} onClick={onClick} />;
1012
};

apps/playground/src/components/Header/SaveButton/SaveButton.tsx

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

3-
import { useInterval } from '@douglasneuroinformatics/libui/hooks';
3+
import { useInterval, useTranslation } from '@douglasneuroinformatics/libui/hooks';
44
import { isEqual } from 'lodash-es';
55
import { SaveIcon } from 'lucide-react';
66

@@ -21,11 +21,13 @@ export const SaveButton = () => {
2121
}
2222
}, 1000);
2323

24+
const { t } = useTranslation();
25+
2426
return (
2527
<ActionButton
2628
disabled={disabled}
2729
icon={<SaveIcon />}
28-
tooltip="Save"
30+
tooltip={t({ en: 'Save', fr: 'Enregistrer' })}
2931
onClick={() => {
3032
updateSelectedInstrument({ files: editorFiles.current });
3133
}}

apps/playground/src/components/Header/ShareButton/ShareButton.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
22

33
import { formatByteSize } from '@douglasneuroinformatics/libjs';
44
import { Heading, Input, Popover, Tooltip } from '@douglasneuroinformatics/libui/components';
5+
import { useTranslation } from '@douglasneuroinformatics/libui/hooks';
56
import { CopyButton } from '@opendatacapture/react-core';
67
import { Share2Icon } from 'lucide-react';
78

@@ -15,6 +16,7 @@ export const ShareButton = () => {
1516
const [shareURL, setShareURL] = useState(encodeShareURL({ files: editorFilesRef.current, label }));
1617
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
1718
const [isTooltipOpen, setIsTooltipOpen] = useState(false);
19+
const { t } = useTranslation();
1820

1921
// The user cannot modify the editor without closing the popover
2022
useEffect(() => {
@@ -40,10 +42,13 @@ export const ShareButton = () => {
4042
</Popover.Trigger>
4143
<Popover.Content align="end" className="w-[520px] p-4">
4244
<div className="flex flex-col space-y-2 text-center sm:text-left">
43-
<Heading variant="h5">Share Instrument</Heading>
45+
<Heading variant="h5">{t({ en: 'Share Instrument', fr: "Partager l'instrument" })}</Heading>
4446
<p className="text-muted-foreground text-sm">
45-
Anyone with this link can open a snapshot of the current code in your playground. The total size of the
46-
URL-encoded source files for this instrument is {formatByteSize(shareURL.size)}.
47+
{t({
48+
en: 'Anyone with this link can open a snapshot of the current code in your playground. The total size of the URL-encoded source files for this instrument is ',
49+
fr: "Toute personne disposant de ce lien peut ouvrir un aperçu du code actuel dans votre terrain de jeu. La taille totale des fichiers sources encodés dans l'URL pour cet instrument est de "
50+
})}
51+
{formatByteSize(shareURL.size)}.
4752
</p>
4853
</div>
4954
<div className="flex gap-2 pt-4">
@@ -53,7 +58,7 @@ export const ShareButton = () => {
5358
</Popover.Content>
5459
</Popover>
5560
<Tooltip.Content side="bottom">
56-
<p>Share</p>
61+
<p>{t({ en: 'Share', fr: 'Partager' })}</p>
5762
</Tooltip.Content>
5863
</Tooltip>
5964
);

apps/playground/src/components/Header/UploadButton/UploadButton.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from 'react';
22

33
import { isPlainObject } from '@douglasneuroinformatics/libjs';
4-
import { useNotificationsStore } from '@douglasneuroinformatics/libui/hooks';
4+
import { useNotificationsStore, useTranslation } from '@douglasneuroinformatics/libui/hooks';
55
import JSZip from 'jszip';
66
import { UploadIcon } from 'lucide-react';
77

@@ -18,6 +18,7 @@ export const UploadButton = () => {
1818
const addInstrument = useAppStore((store) => store.addInstrument);
1919
const setSelectedInstrument = useAppStore((store) => store.setSelectedInstrument);
2020
const instruments = useAppStore((store) => store.instruments);
21+
const { t } = useTranslation();
2122

2223
const handleSubmit = async (files: File[]) => {
2324
try {
@@ -53,8 +54,11 @@ export const UploadButton = () => {
5354
} catch (err) {
5455
console.error(err);
5556
addNotification({
56-
message: 'Please refer to browser console for details',
57-
title: 'Upload Failed',
57+
message: t({
58+
en: 'Please refer to browser console for details',
59+
fr: 'Veuillez consulter la console du navigateur pour plus de détails'
60+
}),
61+
title: t({ en: 'Upload Failed', fr: 'Échec du téléversement' }),
5862
type: 'error'
5963
});
6064
} finally {
@@ -64,12 +68,16 @@ export const UploadButton = () => {
6468

6569
return (
6670
<React.Fragment>
67-
<ActionButton icon={<UploadIcon />} tooltip="Upload Archive" onClick={() => setIsDialogOpen(true)} />
71+
<ActionButton
72+
icon={<UploadIcon />}
73+
tooltip={t({ en: 'Upload Archive', fr: 'Téléverser une archive' })}
74+
onClick={() => setIsDialogOpen(true)}
75+
/>
6876
<FileUploadDialog
6977
accept={{ 'application/zip': ['.zip'] }}
7078
isOpen={isDialogOpen}
7179
setIsOpen={setIsDialogOpen}
72-
title="Upload Archive"
80+
title={t({ en: 'Upload Archive', fr: 'Téléverser une archive' })}
7381
onSubmit={handleSubmit}
7482
onValidate={() => {
7583
return { result: 'success' };

0 commit comments

Comments
 (0)