I am trying to put a Google Translate Widget on the header of a create-react-app website. But the frustrating part is the widget is sometimes loading, sometimes not. It just doesn't display at all (more often in mobile) and after refreshing the page it shows up. Here is the code:
Script:
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'tr'}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
Element:
<div
className="col-lg-1 col-md-1 col-1 my-auto"
id="language-container"
>
<img
src="...svg"
id="language-icon"
className="my-auto me-2"
/>
<span id="google_translate_element"></span>
</div>
So, I couldn't find any solution yet. If you think you might have one, please share it. Thanks.