How to Translate WordPress Plugins and Themes with Google Translate API

en flag
es flag

You may know that over 835 million websites use WordPress today. But how can you ensure your plugin or theme can be used as widely as possible within the ecosystem?

Surprisingly enough, less than half of all WordPress sites have their locale set to English. If you don’t have translations set up already, that means more than 50% of your potential customers probably can’t work with your product in the language they best understand.

WordPress.org Locale Stats

One of the best ways to open up your product to the world is to create high-quality translations of all user-facing text.

The problem is that translation takes a lot of time — the more text you have throughout your product, the more strings to translate. Translation also requires proficiency in different languages, knowledge of how to manage MO and PO files, and overall, a whole lot of effort.

My name is Diego Imbriani, and I’ve been a plugin developer since 2011. I used to sell my plugins through my company GreenTreeLabs (all sold out now!).My products are currently active on ~70,000 websites worldwide.

Thankfully, I found a way to alleviate the whole translation process and simplify translating plugins and themes. Below, I’ll walk you through the process step-by-step, showing you how you can use the script I created to automatically translate your WordPress plugins or themes.

Why You Should Translate Your WordPress Plugin

I recently wanted to add an Italian translation to one of my plugins: Final Tiles Gallery for WordPress, so I opened the plugin’s PO file, which contains all translatable strings, and I started translating my plugin line by line.

Italian PO file of Final Tiles Gallery
An extract from the Italian PO file of Final Tiles Gallery

The Final Tiles Gallery PO file has about 350 entries, and translating them all would require about 2 hours. Honestly, I didn’t find this job very appealing. As I was digging through the translations, I wondered if there was a way to automatically translate my PO file…

I decided to experiment a little with the Google Translate API and managed to code a script to accomplish my idea.

I must admit I’d never thought about translating my plugins before. I’m Italian, but I’ve always used programs and operating systems in English. It would feel “weird” to use any kind of user interface that’s not in English. But, maybe that’s just me. 🙂 There are many countries and nations that aren’t as proficient in English.

WordPress is used by millions of people of different backgrounds, languages, and cultures. We simply can’t ignore the need to translate our plugins and themes to make them accessible to as many users as possible.

I sell my plugins using Freemius, which has a nifty dashboard with extremely useful analytics and stats. A few days ago, I had a look at the “Top 10 Languages” table that you find in their Developer Dashboard. Although I know many sites with Final Tiles Gallery are not in English, I was surprised to find that out of a sample of about 40,000 installations, only around 40% of websites are in English!

Here’s the overview:

Total Installs by Country

As you can see, French, German, and Russian users make up a large percentage of the total — 32,5%.

Benefits of Translating a Plugin or Theme

For WordPress plugin or theme businesses, translating our products is also a marketing opportunity for many reasons:

Larger audience

Not all WordPress users are willing to install a plugin that doesn’t have a translation in their language. That could be for many reasons, but mainly because they may not understand English.

In other cases, users might understand English, but simply feel more comfortable using their own language. So, given the choice between two similar plugins, those customers would pick the one in their language, even if the other plugin offered better quality.

People may prefer languages other than English due to cultural reasons, too. As an example, for historical reasons, especially the older generation of French people don’t like to use English. Moreover, less than 30% of French people say they actually speak the language with confidence, according to some recent surveys.

So, if your product isn’t translated into French, you may immediately lose over 60% of the French WordPress market share. If there’s a French alternative to your product, you probably lose them all, or at least the vast majority. Similar analyses are relevant to many Asian countries, like Japan, that are not yet “Americanized”.

WordPress.org SEO

Vova Feldman, Freemius CEO, has written a bit about the benefits of translation for SEO on the WordPress.org repository. I can’t emphasize these benefits enough.

The fact is the search algorithm on the repo is highly sensitive to the use of different languages in your readme.txt. Focusing your translation efforts on your product strings and your readme.txt can compound your marketing reach on the repo. While most users are searching in English, it’s clear, based on the locale stats from WordPress.org mentioned above, that many users don’t search in English. Therefore, they have limited access to many of the plugins and themes available to those who understand English.

The algorithm shows different results based on the locale of a given WordPress installation. Translating your product overcomes this barrier to getting exposure to users you’d normally never be able to reach.

Vova put it very well when he said, “Bottom line – translations are now more important than ever!” – and it’s still true more than a year on.

Reputation

Translating your plugin or theme has positive psychological implications for your customers. A plugin or theme that offers translations in your customers’ own language can be perceived as a higher-quality product. It means the developer invested time into more than just the technical aspects of the plugin and the customers may recognize this value.

Contributors

Adding translations to your plugin or theme can create a knock-on effect of voluntary translators on the WordPress.org repository if you offer a free plugin or theme. Even a plugin that’s only translated into a few languages is perceived as being much more popular than a plugin with no translations at all, so volunteers may be more inclined to contribute.

Translations stats for the Gutenberg plugin
List of some translations stats for the Gutenberg plugin

So, now that you understand the benefits of translating your product, the next question is: How many languages should you support?

Choosing Supported Languages

There’s no limit to how many languages you can support. But, you should consider a few things before diving into translating your plugin or theme into all of them.

The problem is this: if you translate every language using Google Translate, there will inevitably be incorrect translations. This may result in negative user feedback pointing out the mistakes.

To resolve this problem, I suggest starting with the most popular languages. This type of data can be obtained from three places:

  • Freemius Developer Dashboard
  • WordPress.org stats page (which shows the most popular WordPress locales)
  • Google Analytics stats for your product’s website

Grab a free copy of our Cheat Sheet for
Selling Plugins and Themes

A growth roadmap with concise, actionable tips for every milestone of WordPress product development.

blue book with the title “Cheat Sheet for Selling Themes and Plugins by Freemius” written on it
Name
email

Wherever the numbers point, you can choose the languages that have the largest audiences. If you offer a few translations to those audiences first, you can ask some of your customers or colleagues to review the translations before you release them publicly. This way, you won’t be overwhelmed with customer feedback reporting minor translation issues.

Fiverr has numerous professionals who can help review your translations. You can further minimize your support load by adding a notification in your plugin or theme’s WP Admin settings to inform users to suggest translation updates on the WordPress.org repository instead of submitting a support ticket.

Following this step-by-step process for each language is a logical way to achieve high-quality translations and prevent your support queue from overflowing with tons of small tickets.

Using the Google Translate API to Translate Your Plugin/Theme

Google Cloud provides an API so that you can use Translate as a service.

Google Translate API Pricing

Version 3 of the API is free for up to 500,000 characters per month, and $20 per million characters if you exceed the quota. You can read the pricing details here:

Google Translate (Cloud Translation) API Pricing (May 2024)
Google Translate (Cloud Translation) API Pricing (May 2024)

A Quick Side Note – Internationalized

All plugins must be internationalized before being localized. A great place to start is the WordPress.org guide I18n for WordPress Developers that explains the steps. Once you’ve created your .pot/.po files, you can proceed on the scripting process below.

Let’s Script!

Before we can run the script we need to create a new project in Google Cloud console. If you need help with this task, check this guide or follow these steps:

  1. Go to https://console.developers.google.com and login.
  2. Click “No organization” or select your preferred organization (we assume you don’t have one):

Google Cloud Select Organization

3. Click “New project”:

Google Cloud New Project

4. Enter a project name and click “Create”:

New Google Cloud Project

5. Now you should be redirected to the Console dashboard. Click “Enable APIs and services”:

Google Cloud Console Dashboard

6. Search for the “Cloud Translation API”:

Google Cloud API Library

7. Click “Enable”:

Enable Cloud Translation API

Now that we have a project, we need to set up a service account to authorize our requests to Google APIs. You can follow steps 1 and 2 on this guide from the Google Cloud platform otherwise follow these steps:

  1. Go to “Service accounts” section from the main menu: “IAM & Admin”:

Google Cloud IAM & Admin

2. Click on “Create service account”:

Google Cloud Create Service Account

3. Enter a name and a description for the service account and click “Create”:

4. Click “Continue” to skip role selection as we don’t need it:

Google Cloud Service Account Creation

5. Now click “Create key” and then click “Create”, make sure you selected the JSON format:

Google Cloud Service Account Creation Key Enable

6. After you create the key, the browser will download it automatically. Remember the folder where you’re going to save the file as we’ll need it later.

Now it’s all ready to go but before running the script be sure you have set the GOOGLE_APPLICATION_CREDENTIALS environment variable as described in the guide:

Example: Linux or macOS

Replace [PATH] with the file path of the JSON file that contains your service account key.

export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

For example:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

Example: Windows:

Replace [PATH] with the file path of the JSON file that contains your service account key, and [FILE_NAME] with the filename.

With PowerShell:

$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

For example:

$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\[FILE_NAME].json"

With command prompt:

set GOOGLE_APPLICATION_CREDENTIALS=[PATH]

Now that we are done with the boring stuff, we can start translating!

  1. Clone the repository from https://github.com/GreenTreeLabs/po-gtranslator
    1. Open up your command line and run the following command:
    2. Git clone https://github.com/GreenTreeLabs/po-gtranslator.git
    3. If you don’t have git installed you can download it here.
  2. Enter the directory po-translator:

cd po-gtranslator

  1. Install the dependencies:

npm install

  1. In case you don’t have the npm utility be sure to install Node.js from here.
  2. Run the script with all the needed parameters:

node po-gtranslator.js --project_id=final-tiles-gallery --po_source=it.po --po_dest=it_IT.po --mo=it.mo --lang=it

Let’s have a look at each parameter:

--project_id: ID of your Google project, you can get it from the Google Cloud Console

--po_source: path of the empty PO file that you want to translate

--po_dest: path of the PO file with the translations

--mo: path of the MO file

--lang: code of the language you want to translate to

Note that the source PO file will be kept untranslated and it can be used to generate as many languages as you need. The PO file you need to add to your plugin or theme is the one you pass as –po_dest, which is unique for each language.

Auto Translation in Action!
po-gtranslator.js in action!

Thanks for scripting with me!

It’s been a fun learning experience for me to figure this process out.

If you’re thinking about other steps to make your plugin appealing to broader audiences worldwide, consider multi-currency support and pricing.

Check out our guide to learn why offering multiple currencies is important and how Freemius can help with implementation.

Diego Imbriani

Published by

Bringing 25 years of development expertise, Diego owns Source Code SRL, a Software Development Agency, fueled by a fervor for software and continuous exploration of code and innovative ideas.

Erick Danzer

“The kind of insight and analytics that Freemius can offer about plugin users is unheard of.”

Erick Danzer - Owner at NextGEN Gallery Try Freemius Today

Hand-picked related articles

Comments

24 Comments