Created
March 11, 2023 06:59
-
-
Save marzuk-zarir/7bb1c88979c073835c4884334a96aa69 to your computer and use it in GitHub Desktop.
Translate text to another language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from 'react' | |
| import translate from 'translate' | |
| import ChildComponent from './ChildComponent' | |
| translate.engine = 'deepl' | |
| translate.key = process.env.DEEPL_KEY | |
| export default function TranslateText({ text }) { | |
| const [translatedText, setTranslatedText] = useState() | |
| useEffect(() => { | |
| setTranslatedText(async () => { | |
| return await translate(text, 'es') | |
| }) | |
| }, []) | |
| return ( | |
| <div> | |
| <p>{translatedText}</p> | |
| <ChildComponent text={translatedText} /> | |
| </div> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment