12

I recently saw a website that used Google Translate in their page, but instead of using the widget, they listed the available languages via links. Click a link and it translates the page.

Has anyone ever done this? I tried to parse through the page to figure out how it was done but I don't see much different than when I use the widget. Here's some of my code:

<h3>Translate</h3>
<ul class="google-translate-six">
    <li><a href="?/#googtrans(en|es)" title="View this site in Spanish.">Español</a></li>
    <li><a href="?/#googtrans(en|zh-CN)" title="View this site in Chinese.">中文</a></li>
    <li><a href="?/#googtrans(en|it)" title="View this site in Italian.">Italiano</a></li>
    <li><a href="?/#googtrans(en|pl)" title="View this site in Polish.">Polskie</a></li>
    <li><a href="?/#googtrans(en|ht)" title="View this site in Haitian Creole.">Kreyòl Ayisyen</a></li>
    <li><a href="?/#googtrans(en|pt)" title="View this site in Portuguese.">Português</a></li>
    <li><a href="?/#googtrans(en|en)" title="View this site in English.">English</a></li>
</ul>

<script type="text/javascript">
    function googleTranslateElementInit() {
    new google.translate.TranslateElement({
    pageLanguage: 'en',
    autoDisplay: false,
    gaTrack: true,
    gaId: 'wewe',
    layout: google.translate.TranslateElement.InlineLayout.SIMPLE
    }, 'google_translate_element');
  }
</script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Thanks! The site I'm referring to is: https://www.baltimorecountymd.gov/index.html. The Translate section is at the bottom right portion of the page.

Thanks everyone!

tahdhaze09
  • 2,220
  • 1
  • 21
  • 36
  • Your example site doesn't work for me, only get "This site can’t be reached. www.baltimorecountymd.gov took too long to respond." // If you just want to add a link that sends your URL and the necessary language parameters to Google Translate, that's not that hard to figure out though - just go to the GT website, input something like `http://example.com/` and a target language there ... and then look at the resulting URL, which parameter represents what is pretty obvious. – CBroe Oct 19 '17 at 13:19
  • How do i configure the script that needs to be embedded? The formulation of the link is obvious, but what do I need to grab fro m]Google as far as the embedded script? Is there something different for links than the widget? – tahdhaze09 Oct 19 '17 at 13:21
  • What script, I was just referring to a simple link that opens the Google Translate page, passing what to translate via parameters. If you are looking for something different, then please show a working example (as I said, can't get anything from the one you referred to, doesn't load) or properly describe what specific features you are looking for. – CBroe Oct 19 '17 at 14:00
  • Just found a site for adding this function in you page. But I am encountering a 500 error when try to click the button. Here's the [site](https://translate.google.com/manager/website/?hl=yi). – Gabriel Cheung Oct 19 '17 at 15:40
  • Thanks @GabrielCheung. Yeah I had to scrape the scripts from that from another site I had. Since you need scripts from Google to make the translation work; I was just curious if there is there a configuration that provides extra function to make using a link work any different (you can use the Translate functionality, minus the widget, for example, like an API). Or, is there anything I need to write myself that provides it. I may just use the table version of the widget for now, – tahdhaze09 Oct 20 '17 at 13:59
  • hey, this answer may help you to translate specific div inside the page - https://stackoverflow.com/questions/1900192/google-api-translate-only-a-div-into-page – Nofar Eliasi Oct 23 '17 at 10:10
  • Duplicate of : https://stackoverflow.com/questions/12243818/adding-google-translate-to-a-web-site – GramThanos Oct 23 '17 at 10:37

2 Answers2

5

I believe this page is what you're looking for.

Jiroscopes
  • 545
  • 9
  • 25
0

This should work for you

<a href="https://imgur.com/JwbDy4R"><img src="https://i.imgur.com/JwbDy4R.png" title="source: imgur.com" /></a>

<a href="https://imgur.com/84lyZBW"><img src="https://i.imgur.com/84lyZBW.png" title="source: imgur.com" /></a>

<a href="https://imgur.com/4e2Gd0m"><img src="https://i.imgur.com/4e2Gd0m.png" title="source: imgur.com" /></a>

<a href="https://imgur.com/6Bqalja"><img src="https://i.imgur.com/6Bqalja.png" title="source: imgur.com" /></a>
cyborgnick
  • 11
  • 4