Auto Translate WordPress Content

Recently, I had a chance in working an auto translation language project for WordPress stores; my job was to make the WordPress auto translate the texts on the stores base on customer’s language. That mean the user from each country will see the different language.

You might think right away about WPML plugin or something like that, but the important part is, that plugin only work when you have the translation for each post/page. Otherwise, it will not operate in this case.

After digging around for days, I had the solution that meets my expects:

  • FREE
  • Use as less plugin as possible
  • No advanced coding required

What do you need to prepare?

Beside WPML – a paid plugin that you can create a prolific language WordPress site, but the free option that would work? It should be qTranslate-X.

Auto Translate WordPress Content
qTranslate-X URL Config

More information about qTranslate-X, you can read at this post of the author: https://wordpress.org/plugins/qtranslate-x/

Why do I use qTranslate-X?

  1. qTranslate-X just work as the same as WPML work, and the most important thing is qTranslate-X support the language mapping, it’s something like the pair of country – language (people from Netherland use German as the primary language).
  2. qTranslate-X support pretty permalink for each language that means you will have a URL like this: https://www.wpwiseguys.com/es for Espanol language.
  3. qTranslate-X have the cookies/function that can be used to get the current language.

Why I use Bing Translator instead Google Translator Toolbar

Auto Translate WordPress Content  To me, my works make me have to use translator tool usually, and after about three and a half year using Google Translate and Bing Translate; I found that Bing Translator is much better at translation and more accuracy than Google Translate.

The other thing is you can’t remove the Google translator toolbar when you translate, You can refer to this following image for better understanding.

 

While using Bing Translator, I can make my website look more professional without any watermark or popup of the original text.

Auto Translate WordPress Content
Remove original text and tooltips, highlight after auto translate

How does this auto translate method work?

Auto Translate WordPress Content
Auto Translate WordPress Content in action

Behind the tutorial is the logic to make it work as best as possible. You can imagine a site with 1600 unique visitor a day from around the world, a lot of languages can be used to translate, and I have no intend to tell them we do not have the translation of their language.

I will check the current language by using qTranslate-X’s function; it will return me the current language code of my customer. Then I will translate the language of the site from English to customer’s language.

For more detail about how qTranslate-X detect language, it will use browser’s language of the user and set that user to the corresponding language.

At first, I think it’s not good as I want to translate base on GEOIP, but I debate myself that if a user does not know English, they will set browser’s language to their mother language so they will need the translation, else, they already known English so just keep the site in English.

Before decided to use this logic, I tried to use the other options, but somehow, the simple logic makes the problem much easier.

Most interesting part: The source code

Due to the source code already had the comments on each section, so I just paste it here then you can read the comment for explanations. Mainly, I will get the current language code of that user/customer and assign to a variable. After that, I will do the auto translation with Bing.

You can read more about Bing translate widget here for more information: https://msdn.microsoft.com/en-us/library/dn341983.aspx

Because I do not want to show the panels of Bing translator as it’s not professional, so I will remove Bing’s Translator panel as well as the popup of the original text.

Also, you can do the trigger auto translate when the page is loaded, but it’s not necessary as we already had the param of auto translate on the script. So you’re no need to worry about it anymore.

Conclusion

There’s no method would have just benefit, it has the limitation too, like you will see a flash after the translation or some text will be translated too while do do not want at all, it’s annoying. We have to accept it!

If you have a better idea so you can contribute by comments, I will update and show your credit on my post.

You can look for more about my snippet which might be useful for your WordPress site; it’s here: WordPress Snippet

 

2 thoughts on “Auto Translate WordPress Content”

  1. It would be nice if we could auto translate posts in the backend editor of WordPress then save and publish the already translated text to the site, that way it would not flash. I tried doing it several times but always failed lol. Let me know what you think, I have wanted that option for years.

    1. You could do that, the idea is using this git https://github.com/Stichoza/google-translate-php combine with this article https://www.wpwiseguys.com/3162-wpml-snippet-duplicate-postpage-publish/, the idea is we will run the translation request with text from the original post and receive translated content.

      After received, we will update the post with translated content, all done!

      But it will have some problem you might consider:

      – Each post can have more than 1 translated language, maybe 4-5 language, and you have to create 4-5 posts, 1000 post x 5 language = 5000 posts = heavy DB
      – The translation is free, it might block you out from translate so you can’t expect much and don’t know when you will be blocked.

      It’s up to you buddy

Leave a Reply