Skip to content

Instantly share code, notes, and snippets.

@carolineschnapp
Created February 1, 2011 19:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save carolineschnapp/806456 to your computer and use it in GitHub Desktop.
Save carolineschnapp/806456 to your computer and use it in GitHub Desktop.
Google Translate Embed Code
<div id="google_translate_element"></div>
<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
@ysbhakti
Copy link

It's very easy to make some words bold and other words italic with Markdown. You can even link to Google!

@Cewein
Copy link

Cewein commented Mar 12, 2019

Sadly it does not work anymore, google stopped there widget service

@temsool
Copy link

temsool commented Dec 16, 2019

Sadly it does not work anymore, google stopped there widget service

nope, still works, tried and confirmed right now

@shersial
Copy link

Yes working

@augustdumatubun
Copy link

Got the following message in Firefox Web Console.
Blocked loading mixed active content “http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit”
Loading failed for the <script> with source “http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit”.

@Numerabilis
Copy link

I was looking for translate iframe webpages from my website. Any ideas?
It´s an english manual of programming: https://www.linguagemclipper.com.br/manual-harbour
I need to translate to portuguese.

@vikasChobey
Copy link

My Web Page

Hello everybody!

Translate this page:

<script> function googleTranslateElementInit() { new google.translate.TranslateElement( {pageLanguage: 'en'}, 'google_translate_element' ); } </script> <script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

@kevinyc-dri
Copy link

does this work for instapage?
Do I put it in JS or CSS/HTML?

@MickDawdy
Copy link

Works for me today. Thank you for putting this up :)

@rajninegi786
Copy link

rajninegi786 commented Jan 21, 2021

Just Add this Script and setup your language and your google translate html code is ready.

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>

@NomadAndInLove
Copy link

Is there a way to change this so that the script adds rel attributes to the following link that's added to my site?

<a class="goog-logo-link" href="https://translate.google.com" target="_blank" rel="noopener noreferrer"><img src="https://www.gstatic.com/images/branding/googlelogo/1x/googlelogo_color_42x16dp.png" width="37px" height="14px" style="padding-right: 3px" alt="Google Translate">Translate</a>

@theindianappguy
Copy link

how can we provide the default language for the page so if people coming to website have different default language google can translate

@theindianappguy
Copy link

worked in localhost not on the live site

@shersial
Copy link

The LANG tag (i.e. the lang="" attribute) is designed to signal screen readers pronunciation engines to switch to another language. For this reason and other, tagging Web text as being in a particular language is required in WCAG 2.0.

Declaring a U.S. English Page (Penn State)

...

@MickDawdy
Copy link

While this translate code did work for me, sometimes but not always, back in January 2021, I had to delete it from all of my code as it had become more and more unreliable with the passing of time. All browsers provide access to the extension for translating words. phrases, and whole web pages. Check out this link for Chrome for example...
https://chrome.google.com/webstore/detail/google-translate/aapbdbdomjkkjkaonfhkkikfgjllcleb?hl=en

@ndsda
Copy link

ndsda commented Jul 25, 2023

It does not work for me any more. It worked on my website since 2015 until this week. Has Google stopped supporting it?

Update: It started working again the next day - so just temporary downtime from Google.

@MickDawdy
Copy link

MickDawdy commented Jul 26, 2023 via email

@dabugen
Copy link

dabugen commented Sep 28, 2023

Using:

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>

...works just fine for me as of today (setup on a new website).

@ndsda
Copy link

ndsda commented Sep 28, 2023

Yes, it now works for me too. I meant to write back to say it started working the following day. So there must have simply been a tempory issue in July.

@fyndeal
Copy link

fyndeal commented Mar 22, 2024

It is working for me (I build sites on a 3rd party platform) but the default menu language is coming up in the geographical local language (in this case Thai).
I tried a Google "expert" who insisted that the menu language is decided by your Chrome language settings, but he was full of crap. I have no Thai settings in my browser, or on my laptop at all. It's not even an alternative language choice in Windows or Office for me.
I insist that it's being decided by location but he disagreed.
To check, I set the following code in my website:

<script type="text/javascript">// </script> <script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>

.. and it comes up as Thai (as I am in Thailand).
When I was last working in Zambia, it came up in English
To verify, I connected via a VPN to a server in London and, lo and behold, the menu language changed to English! I simultaneously checked the exact same website on my phone (not connected via VPN) and it's still in Thai.
Anyone know how to lock the menu language to English (or another language, come to that)?
Thanks peeps.

sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment