diff --git a/CHANGELOG.md b/CHANGELOG.md index fc376308..9a8d6373 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to - ✨Add link public/authenticated/restricted access with read/editor roles #234 - ✨(frontend) add copy link button #235 - 🛂(frontend) access public docs without being logged #235 +- 🌐(frontend) add localization to editor #268 ## Changed diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx index 3d228a77..3c9d473b 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx @@ -1,4 +1,4 @@ -import { BlockNoteEditor as BlockNoteEditorCore } from '@blocknote/core'; +import { BlockNoteEditor as BlockNoteEditorCore, locales } from '@blocknote/core'; import '@blocknote/core/fonts/inter.css'; import { BlockNoteView } from '@blocknote/mantine'; import '@blocknote/mantine/style.css'; @@ -18,6 +18,8 @@ import { randomColor } from '../utils'; import { BlockNoteToolbar } from './BlockNoteToolbar'; +import { useTranslation } from 'react-i18next'; + const cssEditor = ` &, & > .bn-container, & .ProseMirror { height:100% @@ -93,6 +95,14 @@ export const BlockNoteContent = ({ }, [createDocAttachment, doc.id], ); + + const { t, i18n } = useTranslation(); + const lang = i18n.language; + + // Invalidate the stored editor when the language changes + useEffect(() => { + setStore(storeId, { editor: null }); + }, [setStore, storeId, lang]); const editor = useMemo(() => { if (storedEditor) { @@ -108,7 +118,8 @@ export const BlockNoteContent = ({ color: randomColor(), }, }, - uploadFile, + dictionary: locales[lang as keyof typeof locales], + uploadFile }); }, [provider, storedEditor, uploadFile, userData?.email]); diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx index 785f84c2..8297c6bf 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolbar.tsx @@ -15,6 +15,7 @@ import { } from '@blocknote/react'; import { forEach, isArray } from 'lodash'; import React, { useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; export const BlockNoteToolbar = () => { return ( @@ -93,6 +94,7 @@ export function MarkdownButton() { const editor = useBlockNoteEditor(); const Components = useComponentsContext(); const selectedBlocks = useSelectedBlocks(editor); + const { t } = useTranslation(); const handleConvertMarkdown = () => { const blocks = editor.getSelection()?.blocks; @@ -126,7 +128,7 @@ export function MarkdownButton() { return ( M diff --git a/src/frontend/apps/impress/src/i18n/translations.json b/src/frontend/apps/impress/src/i18n/translations.json index f656ac1c..39b530a6 100644 --- a/src/frontend/apps/impress/src/i18n/translations.json +++ b/src/frontend/apps/impress/src/i18n/translations.json @@ -125,7 +125,7 @@ "Validate the modification": "Valider les modifications", "Version restored successfully": "Version restaurée avec succès", "We didn't find a mail matching, try to be more accurate": "Nous n'avons pas trouvé de correspondance par mail, essayez d'être plus précis", - "We simply comply with the law, which states that certain audience measurement tools, properly configured to respect privacy, are exempt from prior authorization.": "Nous nous conformons simplement à la loi, qui stipule que certains outils de mesure d’audience, correctement configurés pour respecter la vie privée, sont exemptés de toute autorisation préalable.", + "We simply comply with the law, which states that certain audience measurement tools, properly configured to respect privacy, are exempt from prior authorization.": "Nous nous conformons simplement à la loi, qui stipule que certains outils de mesure d'audience, correctement configurés pour respecter la vie privée, sont exemptés de toute autorisation préalable.", "We try to respond within 2 working days.": "Nous essayons de répondre dans les 2 jours ouvrables.", "You are the sole owner of this group, make another member the group owner before you can change your own role or be removed from your document.": "Vous êtes le seul propriétaire de ce groupe, faites d'un autre membre le propriétaire du groupe, avant de pouvoir modifier votre propre rôle ou vous supprimer du document.", "You can oppose the tracking of your browsing on this website.": "Vous pouvez vous opposer au suivi de votre navigation sur ce site.", @@ -140,7 +140,8 @@ "accessibility-dinum-services": "DINUM s'engage à rendre accessibles ses services numériques, conformément à l'article 47 de la loi n° 2005-102 du 11 février 2005.", "accessibility-form-defenseurdesdroits": "Écrire un message au<1>Défenseur des droits", "accessibility-not-audit": "docs.numerique.gouv.fr n'est pas en conformité avec le RGAA 4.1. Le site n'a pas encore été audité.", - "you have reported to the website manager a lack of accessibility that prevents you from accessing content or one of the services of the portal and you have not received a satisfactory response.": "vous avez signalé au responsable du site internet un défaut d'accessibilité qui vous empêche d'accéder à un contenu ou à un des services du portail et vous n'avez pas obtenu de réponse satisfaisante." + "you have reported to the website manager a lack of accessibility that prevents you from accessing content or one of the services of the portal and you have not received a satisfactory response.": "vous avez signalé au responsable du site internet un défaut d'accessibilité qui vous empêche d'accéder à un contenu ou à un des services du portail et vous n'avez pas obtenu de réponse satisfaisante.", + "Convert Markdown": "Convertir Markdown" } } }