From b8cc727641bcd26830000771f52f5a3626309b7f Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Mon, 9 Oct 2023 17:03:06 +0300
Subject: [PATCH] base and annoations tool translations

---
 editors/demo/src/Editors.js                   | 25 +++--------------
 editors/demo/src/locale/en.js                 | 27 +++++++++++++++++++
 editors/demo/src/locale/es.js                 | 27 +++++++++++++++++++
 .../SaveService/components/SaveButton.js      |  9 ++++++-
 .../BaseService/components/UndoRedoButton.js  |  9 ++++++-
 5 files changed, 74 insertions(+), 23 deletions(-)
 create mode 100644 editors/demo/src/locale/en.js
 create mode 100644 editors/demo/src/locale/es.js

diff --git a/editors/demo/src/Editors.js b/editors/demo/src/Editors.js
index 0d9db9fc0..b95aae885 100644
--- a/editors/demo/src/Editors.js
+++ b/editors/demo/src/Editors.js
@@ -7,33 +7,16 @@ import Editoria from './Editoria/Editoria';
 import HHMI from './HHMI/HHMI';
 import NCBI from './NCBI/NCBI';
 import OEN from './OEN/OEN';
+import en from './locale/en';
+import es from './locale/es';
 
 import 'wax-prosemirror-core/dist/index.css';
 import 'wax-prosemirror-services/dist/index.css';
 import 'wax-questions-service/dist/index.css';
 import 'wax-table-service/dist/index.css';
 i18next.use(initReactI18next).init({
-  resources: {
-    en: {
-      translation: {
-        Wax: {
-          Annotations: {
-            'Toggle code': 'Toggle code translation',
-          },
-        },
-      },
-    },
-    es: {
-      translation: {
-        Wax: {
-          Annotations: {
-            'Toggle code': 'Toggle code translation Spanish',
-          },
-        },
-      },
-    },
-  },
-  lng: 'en',
+  resources: { es },
+  lng: 'es',
   interpolation: {
     escapeValue: false,
   },
diff --git a/editors/demo/src/locale/en.js b/editors/demo/src/locale/en.js
new file mode 100644
index 000000000..d40848d98
--- /dev/null
+++ b/editors/demo/src/locale/en.js
@@ -0,0 +1,27 @@
+const en = {
+  translation: {
+    Wax: {
+      Base: {
+        Undo: 'Undo',
+        Redo: 'Redo',
+        'Save changes': 'Save changes',
+      },
+      Annotations: {
+        'Toggle code': 'Toggle code',
+        'Toggle emphasis': 'Toggle emphasis',
+        'Toggle Small Caps': 'Toggle Small Caps',
+        'Toggle strikethrough': 'Toggle strikethrough',
+        'Toggle strong': 'Toggle strong',
+        'Toggle subscript': 'Toggle subscript',
+        'Toggle superscript': 'Toggle superscript',
+        'Toggle underline': 'Toggle underline',
+        'Add or remove link': 'Add or remove link',
+      },
+      Display: {},
+      Text: {},
+      CustomTags: {},
+    },
+  },
+};
+
+export default en;
diff --git a/editors/demo/src/locale/es.js b/editors/demo/src/locale/es.js
new file mode 100644
index 000000000..eef6c9eb5
--- /dev/null
+++ b/editors/demo/src/locale/es.js
@@ -0,0 +1,27 @@
+const es = {
+  translation: {
+    Wax: {
+      Base: {
+        Undo: 'Deshacer',
+        Redo: 'Rehacer',
+        'Save changes': 'Guardar cambios',
+      },
+      Annotations: {
+        'Toggle code': 'Código de alternancia',
+        'Toggle emphasis': 'Alternar énfasis',
+        'Toggle Small Caps': 'Alternar versalitas',
+        'Toggle strikethrough': 'Alternar tachado',
+        'Toggle strong': 'Alternar fuerte',
+        'Toggle subscript': 'Alternar subíndice',
+        'Toggle superscript': 'Alternar superíndice',
+        'Toggle underline': 'Alternar subrayado',
+        'Add or remove link': 'Agregar o eliminar enlace',
+      },
+      Display: {},
+      Text: {},
+      CustomTags: {},
+    },
+  },
+};
+
+export default es;
diff --git a/wax-prosemirror-services/src/BaseService/SaveService/components/SaveButton.js b/wax-prosemirror-services/src/BaseService/SaveService/components/SaveButton.js
index 4a982d58c..aab685be5 100644
--- a/wax-prosemirror-services/src/BaseService/SaveService/components/SaveButton.js
+++ b/wax-prosemirror-services/src/BaseService/SaveService/components/SaveButton.js
@@ -1,8 +1,11 @@
 /* eslint react/prop-types: 0 */
 import React, { useContext, useMemo, useEffect, useState } from 'react';
+import { isEmpty } from 'lodash';
+import { useTranslation } from 'react-i18next';
 import { WaxContext, MenuButton } from 'wax-prosemirror-core';
 
 const SaveButton = ({ view = {}, item }) => {
+  const { t, i18n } = useTranslation();
   const { icon, label, select, title } = item;
 
   const {
@@ -55,7 +58,11 @@ const SaveButton = ({ view = {}, item }) => {
         iconName={iconTodisplay}
         label={label}
         onMouseDown={handleMouseDown}
-        title={title}
+        title={
+          !isEmpty(i18n) && i18n.exists(`Wax.Base.${title}`)
+            ? t(`Wax.Base.${title}`)
+            : title
+        }
       />
     ),
     [isSaving, isDisabled],
diff --git a/wax-prosemirror-services/src/BaseService/components/UndoRedoButton.js b/wax-prosemirror-services/src/BaseService/components/UndoRedoButton.js
index 0d2565ec8..2ee63f76f 100644
--- a/wax-prosemirror-services/src/BaseService/components/UndoRedoButton.js
+++ b/wax-prosemirror-services/src/BaseService/components/UndoRedoButton.js
@@ -1,8 +1,11 @@
 /* eslint react/prop-types: 0 */
 import React, { useContext, useMemo } from 'react';
+import { isEmpty } from 'lodash';
+import { useTranslation } from 'react-i18next';
 import { WaxContext, MenuButton } from 'wax-prosemirror-core';
 
 const UndoRedoButton = ({ view = {}, item }) => {
+  const { t, i18n } = useTranslation();
   const { active, icon, label, run, select, title } = item;
 
   const {
@@ -38,7 +41,11 @@ const UndoRedoButton = ({ view = {}, item }) => {
         iconName={icon}
         label={label}
         onMouseDown={e => handleMouseDown(e, main.state, main.dispatch)}
-        title={title}
+        title={
+          !isEmpty(i18n) && i18n.exists(`Wax.Base.${title}`)
+            ? t(`Wax.Base.${title}`)
+            : title
+        }
       />
     ),
     [isActive, isDisabled],
-- 
GitLab