Google Translation Tip
While looking at my backlinks today, I noticed a site in French had linked to my post about making photo galleries. He mentioned that the Google Translate wasn’t great. I took a look, and while I don’t know how good the text translation was, I did notice that Google strangely tried to translate the code as well, thus screwing it all up.
A quick search revealed that all one had to do was to add the “notranslate” class to any wrapping object to prevent its contents from being translated.
Now, I use the Syntax Highligher Evolved plugin to display code on my site (although I use an older version because I like the look and functionality of it better than the latest version). So I edited the plugin and found where it inserts the PRE tag, and added the notranslate class to it. And voila, now my code doesn’t get translated anymore.
Just a helpful tip for anybody who posts code on their sites.
from a french.
Thanks for sharing this, Otto.
I would share a tip for adding the class “notranslate” to some elements via jQuery.
Let’s say we want to add this class to these “not-to-be-translated” elements: code, pre and any element with “.code” class.
1. Add these lines to your functions.php file:
2. Create a new file and paste this:
3. Save this file with the name “google_no_translate.js” and put it in a subdirectory “js” of your theme directory.
Obviously, if you’re using a custom plugin for all your custom functions, you’ll modify that file instead of the functions.php file. This will preserve all your custom features, even if you’ll change your existing theme.
I’m not a jQuery expert, so I wonder if those three lines with ‘addClass’ could be written in one line only.
Otto, I can assure you that it works well! 🙂
FYI, I didn’t receive any email from your subcription manager. I checked my spam box and has no email from your domain.
Actually Philippe Durand, the author of the post in question, said that the automatic translation by Google was NOT bad. 😉 He also mentions your blog as indispensable for people interested in WordPress …
Thanks Otto for the original article, and for this tip on automatic translation.
As Willem mentioned (merci !), I thought Google was doing OK on that translation job — except for code, but that is fixed now.
Also I’ll add this to my plugin. Thanks for the tip!
Good job, Alex! Now the code wrapped in SHE shortcodes isn’t translated anymore by Google. Thanks! 😉