Current location: Hot Scripts Forums » General Web Coding » JavaScript » JavaScript to send URL to Google Translation


JavaScript to send URL to Google Translation

Reply
  #1 (permalink)  
Old 09-10-09, 11:05 PM
Stume Stume is offline
New Member
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
JavaScript to send URL to Google Translation

The code below, simplified from others on the Web to handle a single language pair, sends the current web page to Google for translation - and it works. However what I'm trying to do is to modify it so that it sends the URL of another page to Google instead (always the same different page - no user interaction required).

Unfortunately, while I can write a little php, I've really not much idea about what's going on here, and, after over an hour of puzzling, am not much closer to understanding what to change. If anyone is able to assist I'd be very greatful. The code so far is:

HTML Code:
<form action="http://www.google.com/translate" >
<script language="JavaScript">
<!--
document.write ("<input name=u value="+location.href+" type=hidden>")
// -->
</script>
<input name="hl" value="en" type="hidden">
<input name="ie" value="UTF8" type="hidden">
<input name="langpair" value="" type="hidden">
<input name="langpair" value="en|fr" title="French" onclick="this.form.langpair.value=this.value" height="20" type="image" width="30">
</form>

I should, perhaps, explain that I was originally using an ordinary html link to sending a URL to Google with the language pair for translation - very simple and effective. Unfortunately Google seem to have blocked this, and the above JavaScript method seems to be the best alternative - if only it can be persuaded to do what I need...

I hope that explains things?

Last edited by wirehopper; 09-11-09 at 07:13 AM. Reason: HTML tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-11-09, 07:15 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Code:
<!--
document.write ('<input name=u value="http://domain.com/page_to_translate.html" type=hidden>')
// -->
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-21-09, 07:02 PM
Stume Stume is offline
New Member
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Wirehopper.

That looks like it should work, but in practice it brings up page
Code:
http://translate.google.com/?hl=en&langpair=en|fr#
- i.e. the page for translation isn't being passed to Google.

For the avoidance of doubt, I now have the code

Code:
<form action="http://www.google.com/translate" > <script language="JavaScript"> <!-- document.write ('<input name=u
 value=""http://www.microsoft.com/ type=hidden>') // --> </script> <input name="hl" value="en" type="hidden"> <input name="ie"
 value="UTF8" type="hidden"> <input name="langpair" value="" type="hidden"> <input name="langpair" value="en|fr" title="French"
 onclick="this.form.langpair.value=this.value" height="20" type="image" width="30"> </form>
Any further ideas would be very welcome...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-21-09, 07:33 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
__________________
This post was created with 100% recycled electrons.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-21-09, 08:18 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Sorry - missed the plus signs.

Code:
<!--
document.write ('<input name=u value="+http://domain.com/page_to_translate.html+" type=hidden>')
// -->
Also - check out the link from ruteckycs - the time you save may be well worth it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-22-09, 01:19 AM
dhvanik dhvanik is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Not working with form post

Hi all,

I am using Google translator. Its works very fine with main pages. But when i am trying to post the translated page it gives me in original English.

And even when i used ajax in my pages the page comes in English only.

I am not getting any solution for this please help me out with this.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 09-22-09, 07:09 AM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
My script will translate all linked pages, check out my home page, I use it there:

Rutecky Computer Services
__________________
This post was created with 100% recycled electrons.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 09-22-09, 07:28 AM
dhvanik dhvanik is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
That is also not working

Hi ,

Thanks for reply . But it is not working. Just do as i say in your site and you will get what is my problem.

In your site first change the laguage , than go to E-store demo. You will get it in changed laguage but now if you click on search the result page will be in english. Just check it.

Check it and if I am wrong make me correct.

Thanks any ways and if you have any other solution tell me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 09-22-09, 07:41 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Please post the code for the search call.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 09-22-09, 06:42 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
The translation will not work on the estore script search results because the entire page is generated by pulling data from a database. Its not a problem with my script, its that Google simply can not translate it because its pulled from a DB. if you note all the static pages translate fine as these are not pulled from a DB.

If you need a script that will translate dynamic pages 100% of the time then any Google based solution is not your answer.
__________________
This post was created with 100% recycled electrons.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
google translation, javascript, url


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get Indexed in Google Quickly rorycanyon General Advertisements 3 03-21-07 10:11 AM
Need help in send some value through a URL for send SMS sujata_ghosh PHP 0 09-11-06 07:20 AM
Auto Insert URL Tracking Via JavaScript... w2n JavaScript 24 04-14-06 08:59 AM


All times are GMT -5. The time now is 01:30 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.