I was trying to add the google translate element to my angular site.
The html is pretty simple but I am lost as to how or where to add it to an angular site.
I tried a bit with a custom component template but just doesn't seem to work.
<div id="google_translate_element"></div>
<script type="text/javascript"
src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit">
</script>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement(
{pageLanguage: 'en'},
'google_translate_element'
);
}
</script>
I was able to create some test code on https://stackblitz.com ,
I attached my stackblitz angular project for anyone to access.
This worked using the script in the index.html and div and styling in an angular component. So I think I could create a custom angular component or just put it all in the index.html.
Here is what I did to test it out in angular on stackblitz In Index.html
<html>
<head>
<title>My app</title>
</head>
<body>
<my-app>Loading...</my-app>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en' }, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<p>You can translate the content of this page by selecting a language in the select box.</p>
</body>
</html>
I mean If I'm on a any route except landing page and I click on the dropdown to change the language its just refreshing the page and redirecting me to landing page