Make Your Site Easily Translatable With a Little JavaScript
Despite the advances of the Internet, apparently some news still travels slowly. I closed down my Gmail Invite Spooler page months ago, but I’m still getting hundreds of unique visitors to that page along with about a dozen email requests for Gmail each day. Almost all of the emails and traffic are from foreign countries, so I devised a simple javascript that will allow folks to more easily translate the page into their own language.
You can use this very same javascript. It should work on any site just by including the following:
Here’s what it will look like:
February 26th, 2006 at 12:58 pm
A very simple helpful solution, thank you!
March 9th, 2006 at 4:25 pm
Works well. Thanks.
April 2nd, 2006 at 10:38 pm
can i use the above code to translate any page on the internet ..?
how to use it.?
thanks
April 4th, 2006 at 7:44 pm
Hello pankaj.
The main purpose of this script is actually just to enable those who visit your site to translate the current page they’re viewing. Means whichever Web page you’ve placed that script, they’ll be able to view the page in either one of the 8 languages from the drop-down list.
Take this blog’s page as an example. Choose from the drop-down list above of which to what language you want to see this page. Say it’s Spanish. Once you click on ‘Espa˜nol’ there, you’ll see a copy of this page written in Spanish.
Once you there, click on a link that says, “Language Tools”. You suppose to be redirected to the official Google Language Tools. From there, you may then translate any URL/Web site all over the net.
BUT, you can alter this VARIABLE:
myurl = window.encodeURIComponent(document.location.href);
… which is the one that’ll retrieve the current URL of this page (and any other page so long as the script is called from there).
Simply replace the ‘document.location.href’ (without quotes) there to the URL of the page/site you want to translate. Say it’s http://Yahoo.Com/, so enter it like this: “http://www.Yahoo.Com/” (with quotes).
However, doing this is a bit tiresome. You want to translate this site, you change the VARIABLE to its URL. You wish to translate that page, you replace it again. Then you save the script. Next, you call it from your page. And so forth, and so on…
So, the best thing is, go to Google Language Tools and input just the URL, and there you go!
Thanks.
April 17th, 2006 at 5:10 pm
fdfdf
April 27th, 2006 at 10:54 am
Hey nice tool - I’ll probably use it someday.
Did you notice that the dropdown has a bunch of strange code in it as well? Apart from just the languages, I mean.
May 8th, 2006 at 9:05 am
Hello Quyen.
Just wondering. What does that “fdfdf” there is all about? Don’t tell me that you disagree with my previous post… ;P
And Hi Nathan.
I thought you was talking about the Google Language Tools, didn’t you? It’s really just another great service from Google. Thus, you should really try it out.
I’ve tested the translate site script. There’s nothing wrong. Maybe there are some PHP parsing errors on this page. Or probably corrupted by this auto-generated JavaScript file -» http://isnoop.net/blog/wp-content/plugins/lightbox/prototype.js. Don’t know what it is for :)
Have a good day/evening/night.
May 8th, 2006 at 6:49 pm
quiero una invitacion
May 11th, 2006 at 10:17 am
Hello fran.
¿Invitación para qué? ¿A dónde? ¿Y qué significas de todos modos…? Por favor contestación en inglés.
Thanks.
May 16th, 2006 at 4:39 pm
I’ve been having some more foreign visitors so I was looking for a code like this. Very awesome, thanks a lot for this!
May 18th, 2006 at 2:01 am
we put the script in the head, we see jumpmenu for the languages but it does not translate what do we have to do? simon and pi-qui
May 21st, 2006 at 9:02 am
It adds extra funny menu options in Konqueror
May 26th, 2006 at 2:15 pm
dog obedience
after all the dog training blog is running, go check it out! :)
July 5th, 2006 at 6:58 am
Okay. It’s been quite a long time since I visited this page for the first time :) In fact, I just wanna say that it is NOT JavaScript which does the actual translation processes. It’s Google Machine Translation (MT) that does all those things - JavaScript simply send you page to the Google MT and the rests will be handled by the MT. I really hope that it helps someone!
By the way, did you see this morning FIFA World Cup Germany 2006 Semi-Final match between Germany (the host), and Italy? I got very shocked to know Italy won the game with 2 goals. And it was done in the last 2 Minutes of the 30 Minutes Extra Time after the actual 90 Minutes Time play!
I hope France will win the next semi-final (tomorrow morning) and then accompany Italy to the Final match on July 10 2006 (Monday morning)… and then WIN??
Have a nice surfing!
July 10th, 2006 at 2:57 pm
Hi Sally,
Thanks for sharing this wonderful tool iwth us.
Is it possible to not show the google page, or to show it on the botton of my page?
I tryied this: bottom.location.href=url; and didn’t work.
Best regards,
Fábio
July 11th, 2006 at 1:38 am
Hi there, Fábio.
You’re most welcome :)
It’s an unfortunate that I couldn’t really get your point(s), but if you’re trying to break Google
FRAMESfrom the translation results Web page, then there’s a simple solution for that one, but bothersome on the other side…Just put the following JavaScript script into
<HEAD></HEAD>tags of all of your pages:<script type="Text/JavaScript">
<!-- Hide
if (window != top) top.location.replace (location.href);
// End-->
</script>
OR…
If you actually want to show the results page right from your very own Web site, then first, you can put it in a frame, just as Google does. Or else, you’ll probably need to use some sort of Server Side Scripting Languages such as CGI/Perl or PHP.
In fact, there’s a cool PHP script which enables your visitors to on-the-fly translate your site to their choice of language. They’ll never know that the translation is actually done by Google and that the page is somehow ‘fetched’ from the Google results page. However, it requires support for cURL library, and a PHP-enabled Web server, of course ;)
If you’re interested, here’s the URL:
http://Forums.DigitalPoint.com/showthread.php?t=42057
Yups, that’s a Forum site. Read it on until the end because it’s worth reading. The link to Download the script is available exactly at the above page (the 1st thread).
Best of luck to you!
July 11th, 2006 at 6:17 am
Hi there Pábio.
I’ve posted “something” here on this evening (GMT +8), but it seems that it’s rejected :) I’ve no idea why. I didn’t say anything harm except replying to your query.
If it never show up, that’s it. Please consult someone’s else help. I just don’t want to waste my time posting over and over again, but then you see nothing ;) Or e-Mail Comp.Misc[AT]GMail.com :)
July 11th, 2006 at 6:19 am
WooppS!
Your comment is awaiting moderation. :D
August 15th, 2006 at 4:02 pm
hello. This tool is fantastic, is there anyway to skin it to fit in with a sites design?
August 16th, 2006 at 9:47 pm
You can certainly use stylesheets to do what you’d like to it.
The dropdown box has an ID of ‘trans’ so you can address it as such:
<style>
select#trans {color:red; border: 1px solid red; background: yellow}
</style>
Check it out:
August 21st, 2006 at 6:10 pm
Hello Ian.
That’s cool ;) Finally, you posted something ;p and just wondering what’s happened to the translate site script before…
October 8th, 2006 at 11:40 am
Autor, Respect!
October 8th, 2006 at 7:52 pm
I forgot to mention that the JavaScript script at http://isnoop.net/js/translate.js is already against frames. If someone puts your Web page into his or her Web site using a frame like iframe, maybe, the page that will be translated is YOUR page, and not his or hers ;) On the other hand, if you put any of your page inside a frame, take note that only the frame’s content will be translated, not the page calling the frame!
P.S.: Have you added lang["ar"] = “Arabic” to the script? Go to the Official Google Research Blog: Statistical machine translation live, and you’ll learn it better… :D [Try it out. Arabic to English translation!]
October 10th, 2006 at 11:50 am
!!! It is class to itself
January 22nd, 2007 at 7:19 pm
Hi sally,
I am using Google webmaster tool and there I am getting errors like:
http://www.iconocast.com/News_Files/A0SB7/function.fopen 404 (Not found) [?] Jan 20, 2007
I believe my translation software needs curl. Can you help?
Corey
January 23rd, 2007 at 11:21 am
Corey,
There aren’t any references to fopen in the translation script. Google’s webmaster tools do show you every link they have listed as a 404 whether or not you actually link to it on your site. Google could know about it because some other site has a malformed URL.
Your best bet is to check your old access logs and find out what the referring URL was.
January 23rd, 2007 at 12:13 pm
Hi! Why I can’t fill my info in profile? Can somebody help me?
My login is Kisakookoo!
January 24th, 2007 at 12:34 am
Hi there Corey.
You said…
“I believe my translation software needs curl.”
If you’re using a PHP script from Digital Point forum at http://Forums.DigitalPoint.com/showthread.php?t=42057, yes you indeed need the cURL. Unfortunately, installing cURL in Apache is beyond my knowledge. For more details about that, take a look at http://cURL.haxx.se/ Installation, and usage guide of the script is available right at the forum itself - last time, it’s 450 posts already, so be patient…
But, if it’s not that script, but IS a PHP script from somewhere else, then you may, and may not need cURL. Since you gave “http://www.iconocast.com/News_Files/A0SB7/function.fopen”, and there’s a ‘fopen’ therein, your current (PHP) script might be using fOpen() function rather than cURL.
It seems like fOpen() isn’t supported on your Web site, but it’s almost impossible it’s not (for the basic functionalities such as opening, reading, and writing to/from a file) because fOpen() is nothing harm but a global function in PHP that should always come along with every release/version of ‘the’ PHP interpreter. In the other words, it’s kind of a mandatory thing, and not optional like cURL which you may/may not install on your Web site.
So… I’m sorry to ask, but are you very sure that your Web site is a PHP-enabled one, and that you’re allowed to run PHP scripts on your Web site?
Maybe… you can post one part where it calls the fOpen() in your translation script?
Thanks.
March 22nd, 2007 at 1:35 pm
[...] - Make your site easily translatable with a little javascript [...]
March 29th, 2007 at 1:12 am
Hey, just visiting.
The s*pam protection still missed this comment…
http://isnoop.net/blog/2006/02/24/make-your-site-easily-translatable-with-a-little-javascript/#comment-38147
Well, I thought so. ;-)
March 30th, 2007 at 2:18 pm
What in the name of Jerry Brightonhammer was that all about?
I dont’ know but it doesn’t make sense to me.
April 6th, 2007 at 1:18 pm
wow good!
wow good! - wow good! - lol amazing!
May 29th, 2007 at 7:06 am
Hello, What a beautiful and awesome site. I adore what you’ve done with your setup and graphics. Thanks you so much.
October 1st, 2007 at 8:08 pm
online marketing melbourne
online marketing melbourne
July 1st, 2008 at 2:13 pm
I have put it on Heath-herring.com (MMA UFC FIGHTER) and his fans from all over the world are appreciating this simple YET POWERFUL java plugin.
Thanks