
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
react-google-translate
Advanced tools
Useful hook for Google Translate API.
See demo
npm install --save react-google-translate @google-cloud/translate
Generate your credentials and project id in Google Cloud Platform. Read through the documentation for setting a service account.
After you acquired your credentials and project id, add it to your environment variables.
GCP_PRIVATE_KEY=[private_key]
GCP_CLIENT_EMAIL=[client_email]
GCP_PROJECT_ID=[project_id]
In your index.js,
import { setConfig } from 'react-google-translate'
setConfig({
clientEmail: process.env.REACT_APP_GCP_CLIENT_EMAIL ?? '',
privateKey: process.env.REACT_APP_GCP_PRIVATE_KEY ?? '',
projectId: process.env.REACT_APP_GCP_PROJECT_ID ?? ''
})
import React, { useState, useEffect } from 'react'
import { useLazyTranslate } from 'react-google-translate'
const Example = () => {
const [text] = useState('test');
const [language] = useState('zh-CN');
const [translate, { data, loading }] = useLazyTranslate({
language
})
useEffect(() => {
if (text) {
translate(text, language);
}
}, [translate, text])
render() {
return (
<div>{loading ? 'Loading...' : data}</div>
)
}
}
language
: string | string[]Set the default language for the translation.
skip
: booleanSkips the request if true.
translate
: funcCalls the api to translate the given text and language.
loading
: booleanIndicates that loading state.
data
: string | string[]Translated text received from the hook.
called
: booleanIndicates that hook has been triggered.
MIT © geminstall23
FAQs
Useful hook for Google Translate API.
The npm package react-google-translate receives a total of 42 weekly downloads. As such, react-google-translate popularity was classified as not popular.
We found that react-google-translate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.