Skip to content

Commit

Permalink
Adjust rte to async translate function
Browse files Browse the repository at this point in the history
  • Loading branch information
VP-DS committed Dec 5, 2023
1 parent c14f915 commit 216df08
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useTranslationConfig } from "@comet/admin";
import { useTranslationConfig } from "@Comet/admin";
import TranslateIcon from "@mui/icons-material/Translate";
import Tooltip from "@mui/material/Tooltip";
import { convertToRaw } from "draft-js";
Expand All @@ -13,17 +13,18 @@ import { translateAndTransformXmlToState } from "./xml/translateAndTransformToSt
function ToolbarButton({ editorState, setEditorState }: IControlProps): React.ReactElement {
const { translate } = useTranslationConfig();

function handleClick(event: React.MouseEvent) {
async function handleClick(event: React.MouseEvent) {
event.preventDefault();

const contentState = editorState.getCurrentContent();

const xml = transformStateToXml(contentState);

if (translate) {
const translation = xml.map((item) => ({ original: item, replaceWith: translate(item) }));
const translationPromises = xml.map(async (item) => ({ original: item, replaceWith: await translate(item) }));
const translations = await Promise.all(translationPromises);

const translatedState = translateAndTransformXmlToState(contentState, convertToRaw(contentState), translation);
const translatedState = translateAndTransformXmlToState(contentState, convertToRaw(contentState), translations);

setEditorState(translatedState);
}
Expand Down

0 comments on commit 216df08

Please sign in to comment.