Google translate using a link click
Asked Answered
U

2

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!

Unreligious answered 12/10, 2017 at 14:12 Comment(7)
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.Derwent
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?Unreligious
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.Derwent
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.Erwin
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,Unreligious
hey, this answer may help you to translate specific div inside the page - #1900692Varden
Duplicate of : #12244318Execrative
E
5

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

Eudemonism answered 23/10, 2017 at 18:59 Comment(1)
That was it. Thanks!Unreligious
R
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>
Rutledge answered 26/10, 2017 at 2:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.