react-native-translator
react-native-translator copied to clipboard
TypeError: Cannot read property 'type' of undefined
got error for this function const onTranslate = async () => {
const _result = await translate('en', 'fr', value);
setResult(_result);
};
WARN Possible Unhandled Promise Rejection (id: 12):
TypeError: Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
I'm using normal react native jsx, also the real-time conversion is crashing the app.
Same issue. on both Android and iOS, RN 0.70.6
better use the google translation API directly its working here the example code. `` const [translatedText, setTranslatedText] = useState(''); const handleTranslate = async () => { const text = 'how are you doing today 77'; const targetLanguage = 'hi'; const translatedText = await translateText(text, targetLanguage); setTranslatedText(translatedText); };
const translateText = async (text, targetLanguage) => {
const apiKey = 'AIzaSyCVL6U956LvuHCeMEaXKVvWssRY7DJmvZU';
const url = https://translation.googleapis.com/language/translate/v2?key=${apiKey}
;
const data = {
q: text,
target: targetLanguage,
};
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
const json = await response.json();
return json.data.translations[0].translatedText;
};
<Text>Original text: Hello, world!</Text>
<Button title="Translate" onPress={handleTranslate} />
<Text>Translated text: {translatedText}</Text>
``
the call the function onPress={handleTranslate} inside a button
@AhammedMishal1 @MariusCatanoiu how about this?
onTranslate = async () => {
const _result = await translate('en', 'fr', value, { type: 'google' });
setResult(_result);
};
@AhammedMishal1 @MariusCatanoiu how about this?
onTranslate = async () => { const _result = await translate('en', 'fr', value, { type: 'google' }); setResult(_result); };
did need google API for this to work ?
@AhammedMishal1 @MariusCatanoiu how about this?
onTranslate = async () => {
const _result = await translate('en', 'fr', value, { type: 'google' });
setResult(_result);
};
did need google API for this to work ?
No. It's working by crawling.
@AhammedMishal1 @MariusCatanoiu how about this?
onTranslate = async () => {
const _result = await translate('en', 'fr', value, { type: 'google' });
setResult(_result);
};
did need google API for this to work ?
No. It's working by crawling.
As a provider of the npm library, it's important to consider the possibility of the web page you're scraping for translations changing its tags in the future. In such cases, will the library still function correctly, or will the code need to be updated to accommodate the changes in the web page's structure?