Skip to content

Instantly share code, notes, and snippets.

@marzuk-zarir
Created March 11, 2023 06:59
Show Gist options
  • Select an option

  • Save marzuk-zarir/7bb1c88979c073835c4884334a96aa69 to your computer and use it in GitHub Desktop.

Select an option

Save marzuk-zarir/7bb1c88979c073835c4884334a96aa69 to your computer and use it in GitHub Desktop.
Translate text to another language
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