Sponsored by:

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:

35 Responses to “Make Your Site Easily Translatable With a Little JavaScript”

  1. Matt Sweeney Says:

    A very simple helpful solution, thank you!

  2. Rob Says:

    Works well. Thanks.

  3. pankaj Says:

    can i use the above code to translate any page on the internet ..?
    how to use it.?
    thanks

  4. Sally Says:

    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.

  5. quyen` Says:

    fdfdf

  6. nathan Says:

    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.

  7. Sally Says:

    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.

  8. fran Says:

    quiero una invitacion

  9. Sally Says:

    Hello fran.

    ¿Invitación para qué? ¿A dónde? ¿Y qué significas de todos modos…? Por favor contestación en inglés.

    Thanks.

  10. TheGune Says:

    I’ve been having some more foreign visitors so I was looking for a code like this. Very awesome, thanks a lot for this!

  11. pi-qui Says:

    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

  12. mazin Says:

    It adds extra funny menu options in Konqueror

  13. dog training Says:

    dog obedience

    after all the dog training blog is running, go check it out! :)

  14. Sally Says:

    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!

  15. Fábio Says:

    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

  16. Sally Says:

    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 FRAMES from 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!

  17. Sally Says:

    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 :)

  18. Sally Says:

    WooppS!

    Your comment is awaiting moderation. :D

  19. dtgreenwood Says:

    hello. This tool is fantastic, is there anyway to skin it to fit in with a sites design?

  20. Ian Says:

    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:

  21. Sally Says:

    Hello Ian.

    That’s cool ;) Finally, you posted something ;p and just wondering what’s happened to the translate site script before…

  22. Andry Says:

    Autor, Respect!

  23. Sally Says:

    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!]

  24. Name Alexey Says:

    !!! It is class to itself

  25. Corey Says:

    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

  26. Ian Says:

    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.

  27. Kisakookoo Says:

    Hi! Why I can’t fill my info in profile? Can somebody help me?
    My login is Kisakookoo!

  28. Sally Says:

    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.

  29. GLEAMLAND | Zainal Amri aka Gleam | Surabaya and Bali Graphic Designer » Archive » Web Translation Scripts Says:

    [...] - Make your site easily translatable with a little javascript [...]

  30. Sally Says:

    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. ;-)

  31. JerryBrightonhammer Says:

    What in the name of Jerry Brightonhammer was that all about?
    I dont’ know but it doesn’t make sense to me.

  32. zaebali Says:

    wow good!

    wow good! - wow good! - lol amazing!

  33. fort worth Says:

    Hello, What a beautiful and awesome site. I adore what you’ve done with your setup and graphics. Thanks you so much.

  34. online marketing melbourne Says:

    online marketing melbourne

    online marketing melbourne

  35. STEVE Says:

    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

Leave a Reply