Rob’s Translator WordPress Plugin – English to 10 languages! Now IE Compliant

Great News!

My Robs Translator plugin is now working with Internet Explorer.

Largely due to a comment I received about how my Robs Translator plugin is obsolete due to internet explorer being the best thing in the world ever now that absolutely everyone uses Windows Vista with IE 7, I decided to finally sort out the problem.

There is slightly more work to do on the part of those installing the translator (though this is literally opening the php file in notepad and adding or removing one line).

The Robs Translator plug-in allows your blog viewers to translate your blog from English to one of 10 languages! Languages currently supported are:

  • German
  • French
  • Italian
  • Spanish
  • Korean
  • Chinese (Traditional)
  • Chinese (Simplified)
  • Potugese
  • Japanese
  • Russian

Download Robs Translator Version 1.2 here

Installing the Translator:

  1. Download Robs Translator v.1.2;
  2. Extract the zipped file, you should now have a folder entitled “Robs Translator”;
  3. Upload the entire folder to your “wp-content/plugins” folder;
  4. Open the plugins page of your WordPress admin panel and activate the Robs Translator plugin;

The Translator is installed! However, you need to tell your WordPress theme where to display the flags, and you also need to tell the translator what the base URL of your WordPress blog is (if it is not www.YOURSITE.com).

Inputting the Code to Display the Flags/Languages:

This is quite simple, and depends upon whether you want to display the flags in your header, or your sidebar. I’ve placed mine in the sidebar, though this is up to personal preference.

Placing Translate Flags / Languages in Sidebar:

Open your sidebar.php file (wp-content/themes/<YOUR-THEME-NAME>/sidebar.php) in a text editor (e.g. notepad) and input the following code, where you want your flags displayed (this is best near the top of the page!):

<?php translate(1); ?>

That’s all you need to do, the flags will display in that location (the 1 at the end tells the flags to display vertically, for horizontal display (which you wouldn’t want in a sidebar!), replace with a ’2′). However, you still need to tell the php file the exact location of your blog (if it is not www.YOURSITEROOT.com), so read the final instruction to find out how to do this.

Placing Translate Flags / Languages in Header:

Open your header.php file (wp-content/themes/<YOUR-THEME-NAME>/header.php) in a text editor (e.g. notepad) and input the following code, where you want your flags displayed (this is best near the top of the page!):

<?php translate(2); ?>

That’s it! However, you still need to tell the php file the exact location of your blog (if it is not www.YOURSITEROOT.com), so read the final instruction to find out how to do this.

Telling the plugin the location of your blog

This is important, and is the main difference of this latest version. Basically, Firefox browsers can handle HTTP_REFERERS requests (which mean that the translated page was the EXACT page where the button was pressed) however IE cannot. This means I have used another method to call the URL. Now, when a user clicks on the Translate button it will translate the base URL of your site. For example, for this site, it would translate www.24hourtrading.co.uk, not the blog. If your blog is located in a sub-domain directory, you’ll need to add a tiny bit to the robs-translator.php code too:

Making Robs Translator locate your blog if it is not the site root:

  1. Get the sub-domain location of your blog (e.g. if it is at URL www.YOURSITE.com/blog/, then it would be ‘/blog/’);
  2. Open the robs-translator.php file in a text editor
  3. Find the line which reads: $currenturl = ‘http://’ . $_SERVER["SERVER_NAME"] . $currenturl;
  4. Replace that line with the following line, being sure to replace the sub-domain location of your blog (if different from ‘/blog/’) : $currenturl = ‘http://’ . $_SERVER["SERVER_NAME"] . ‘/blog/’ . $currenturl;

That is it, the translation should now occur on your blog – as opposed to the root of your site. If your blog is a couple of domains up from your site root, then of course you’ll have to enter both.

Any problems, leave a comment. I hope this is considered an improvement, despite the slightly more convoluted way to install, as it is now cross-browser compliant!

About the Author

Rob Scott

Rob Scott is a 26 year old originating from Wensleydale, in the heart of the Yorkshire Dales National Park (UK). Rob founded 24 Hour Trading Ltd which currently owns and runs a series of websites. Rob writes extensively on a number of subjects here and in several other online publications, while, in his limited free time he develops his poetry. Subscribe to Rob Scott's RSS feed by clicking here. Rob has left Twitter and Facebook, after deciding there is no personal benefit to using either network.

28 Responses to “ Rob’s Translator WordPress Plugin – English to 10 languages! Now IE Compliant ”

  1. Thanks for the update, I have at least one friend who visits my site from work and they only have IE, so I guess it is a useful sep forward in some ways.

    Sorry if you got some twerp whinging about the lack of IE support, though why anyone would use IE unless they had to, they must be crazy. Even version 7 sucks, I just use the ie extension in Firefox if some site requires it because if I launch IE7 it usually crashes when I try to close it.

  2. Hi, thanks for updating your plugin. I seem to be having a slight problem. When you click a flag to translate Google says the wrong API is installed for the web site. I’ve updated the API but still get the same error. If you click through the error the translation occurs. Any ideas on how I can resolve this problem?

    Gary O

  3. Gary O,

    I’m not sure – it has worked when I’ve tested it on three machines.

    What browser are you using?

    Anyone else having the same trouble?

    All I can think briefly is that whatever problem there is may be either:

    a) on your local machine;
    b) it may have been a brief problem at Google’s end (e.g. a lot of traffic at the same time, translations momentarily down etc)

    Let me know how you get on, and if the problem persists, please give some more details and I’ll get my thinking cap out.

  4. google.comHi Rob,

    I’m browsing using IE7. The full error message is “The Google Maps API key used on this web site was registered for a different web site. You can generate a new key for this web site at http://www.google.com/apis/maps/.

    I am also using the In-Line Google Maps Plugin (http://avi.alkalay.net/2006/11/google-maps-plugin-for-wordpress.html).

    I have been to the google web site to get a new API key and have saved this in the In-Line Google Maps Plugin – is there somewhere esle I need to store the API? If you visit my blog – does this error occur for you?

    Regards

    Gary O

  5. Gary,

    I think that could be your problem – an incompatibility with the google maps plugin, as I’ve not encountered this before!

    However, when I visited your blog, after pressing ‘ok’ the translation did run…

    Not really sure how to work around this, as there is no API key required for the translator plugin.

    If it won’t mess up your Google Maps plugin, try de-activating it and running the translation – if it works ok, we can safely assume that is the problem. Then you can re-activate the maps plugin afterwards. If this IS the case, then the two cannot run together in their current format – you’ll need to remove one or the other, or just accept that the box will pop-up when translating.

    A bit of a pain, though it’s not the translation plugin which is sending the API key.

    Without having used the plugin you mention, I’m not sure what exactly could be done to stop this, though please let me know if any of the above works out the root of the problems…

  6. Hi Rob,

    I just installed the plugin and inserted the code into the PHP file. However, when I reloaded my blog this message showed up:

    Parse error: syntax error, unexpected ‘:’ in /home/bllindg/public_html/blog/wp-content/plugins/robs-translator/robs-translator.php on line 13

    What does this mean and how can this be fixed?

    Thanks in advance!

  7. It sounds as though there is an error in the syntax when you changed the line – this may be due to the fact that your blog is in a subdomain.

    Try changing the line in the robs-translator.php code to the following:

      $currenturl = ‘http://bllindgrls.officiallydumb.com/blog/’ . $currenturl;

    You can just copy and paste this in the place of the entire line. Does this solve the problem?

    If not, please can you copy the top 15 lines of the php code and place them into these comments, I’ll see what the problem is.

    Please note that this applies only to your blog!

  8. Actually, did you copy the ‘:’ before the code when you put it in? If so, remove it, line 13 of the php should read like this:

    $currenturl = ‘http://’ . $_SERVER[”SERVER_NAME”] . ‘/blog/’ . $currenturl;

    (without any ‘:’ sign, but with a trailing ‘;’ – my mistake, I missed it out when writing the instructions!!)

  9. Hi Rob, I’ll follow your suggestions. The Google Maps plugin is used on a number of my posts to map where we’ve been on our travels and is really an integral part of the posts.

    It looks as if I’ll have to put up with the little “hic cup”. In the mean time I’ll contact the Google Maps plugin writer and see if they’re prepared to review the plugin so that it is more compatible.

    Regards

    Gary O

  10. 24hourtrading.co.uk24hourtrading.co.ukgoogle.comYou were right about my blog being in a subdomain but I still get the same text after inputting what you suggested. Perhaps I’m doing something wrong.

    Here is a portion of the PHP code as you requested:

  11. 24hourtrading.co.uk24hourtrading.co.ukgoogle.comIt didn’t seem like the code showed up in my previous comment.

  12. 24hourtrading.co.uk24hourtrading.co.ukgoogle.comOk, maybe I should put quotations in front of the code since it’s not showing up?

  13. 24hourtrading.co.uk24hourtrading.co.ukgoogle.comHow about now?

    ?php

    /*
    Plugin Name: Robs Translator
    Plugin URI: http://www.24hourtrading.co.uk/blog/2007/05/01/robs-translator-wordpress-plugin-

    english-to-10-languages-now-ie-compliant/
    Description: Translate your blog and website to any language using Google translate –

    supports 11 languages! Latest bug fix – translator works with Internet Explorer
    Version: 1.2 (May 2nd, 2007)
    Author: Rob Scott
    Author URI: http://www.24hourtrading.co.uk/blog
    */

    $currenturl = ‘http://bllindgrls.officiallydumb.com/blog/’ . $currenturl;
    $currenturl = preg_replace(“@(.*?)url\=@ism”, “”, $currenturl);

    if($_GET['lang'] == “ger”) {
    header(“Location: http://www.google.com/translate?u=$currenturl&langpair=en%

    7Cde&hl=en&ie=UTF8″);

  14. There. Sorry for all this multi-commenting. I couldn’t get the PHP code to display. I left out a less than sign in front of the “?php” on the first line so it would show.

  15. Thanks for the update at my site, Rob! Though I must say, the new installation steps are kinda intimidating. LOL!

    I haven’t implemented it at my blogs but will do so one day when I am in the mood ;)

  16. Greetings,

    I am getting an error with this translator, seems to be a problem with WordPress 2.2 seeing it worked fine for me with WordPress 2.1.3…
    The WordPress 2.2 plugin protection feature kicks in when I try to activate the plugin… Below is the error:

    Plugin could not be activated because it triggered a fatal error.

  17. Hi,
    I am getting the same error as Martin on wordpress 2.2. Is there a possibility of seeing a new version of your plugin anytime soon?

    Thanks.

  18. Hi Rob,

    Thanks for great plugin. Yours is the first one that worked for me, after testing a few other free ones.

    There are a few points concerning Google Ajax Search that I use on my site; the plugin doesnt work with translated versions of my blog.

    I suppose I would need to get different API keys for every single language! :) Also my header logo gets disjointed unless I did away with it.

    But a big thanks anyway. Something is better than nothing.

    Regards,
    Darrin

  19. I’m not sure about WP 2.2 – I’ve yet to update…

    Been busy as a mad man lately.

    Will let you all know what the problems are, though I think it may be a compatility issue with new code in WP 2.2 using the same terminology as the translation plugin.

    Nothing ever runs smoothly.

    :)

  20. With regard the incompatibility with other plugins, I’m afraid that is not really possible to fix at my end!

    Some of the stuff will never translate using this method, it is only a half measure really.

    If you want accurate (Google’s are seldom) translations, I would suggest getting someone bilingual to translate your posts and having a totally identical site in another language.

    Obviously this is not workable for most people as they have neither the time or the budget to do this for all of the world’s major languages! Hence the half measure of the translation plug…

    I appreciate any questions or comments, but have been removing those who expect far too much from what is purely a way to translate at the click of a button rather than a meaningful translation tool (there really is no automated way of doing this – trust me, I’ve tried them all and the transaltions are often laughable!).

    The main concerns are largely grammatical – the online translations from Google, Babelfish et al are often illegibly bad. Korean is dreadful: with sentences translated literally word-for-word and becomming, as a result, grammatically incorrect to the point of being hardly recognisable or coherent…

    I’ll stop now, this is probably a post in itself ;)

  21. I agree with you most translators are very basic and we shouldnt expect the sun and moon along with them. But I got it working on my blog, others I tried, didnt work. That’s the point. :)

    However, I’ve decided to put a translator aside for the time being..(don’t really need one)

    ALL the translators currently are:

    1) Incoherent and too basic. If you can live with that, it doesnt matter.

    Till translators improve their capabilities. Which is the future, not now.

    Nothing to do with your translator, just that Google needs to hire better translators who know technical stuff, which takes time ;)

    2) There could be a glitch with Google concerning distinguishing the character case structure of translated URLs…but this is all just conjecture.

    Cheers.
    Darrin

  22. I am having the same problem with wORDPRESS 2.2 and Fatal error when trying to activate. Any help please?

  23. Your site is the best. I found your site n google. Thanks

  24. thank you for this plugin! i like this plugin because is not overloading the server so much like other similar plugins

  25. I keep getting this error when trying to activate.
    ————
    Plugin could not be activated because it triggered a fatal error.
    Parse error: parse error, unexpected ‘:’ in /home/content/m/r/k/mrking/html/bikram/wp-content/plugins/robs-translator/robs-translator.php on line 13
    ———————————-
    any ideas. I filled out the two areas. my http info and the directory. still no worky.

  26. my line 13 is:

    $currenturl = ‘http://www.artbymichaelking.com’ . $_SERVER[”SERVER_NAME”] . ‘/bikram/’ . $currenturl;

    the only “:” is in the http:// part. I take that out and I get some error about not being divisible by zero.

    any ideas?

  27. I am thi error with wp 2.3.1

    Fatal error: Cannot redeclare translate() (previously declared in /web/htdocs/www.mondine.it/home/wp-includes/l10n.php:20) in /web/htdocs/www.mondine.it/home/wp-content/plugins/robs-translator/robs-translator.php on line 38

  28. Hi,
    O’m having precisely the same issue on 2.3.1

Leave a Reply

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>