Translate WordPress plugin

How to Translate WordPress Plugins and Themes Automatically As a Developer

As you know WordPress is the most popular CMS (Content Management System) and people all over the world are using it. According to a study it powers over 33% of the websites.

By default, WordPress speaks English. But there is no guarantee that all of that 33% of WordPress users use English. They may take their native or other languages as their website language. After all, you can’t control them which language they should choose.

So, as a WordPress plugin or theme developer, you must offer multilingual products to outreach as many users as possible.

Translating WordPress plugin manually is quite an impossible and time-consuming task. So, here we are to show you a path to translate WordPress plugins and themes in an automated way. Keep reading.

Why You Need to Translate WordPress Plugins and Themes

Translate WordPress plugin

As a developer, it’s important to make available your products in different languages. WordPress websites are accessed from all across the world by people who speak languages other than English. In fact, according to a recent survey, 55 percent of users preferably shop online in their native language.

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 by creating high-quality translations of all user-facing text.

Providing translation ready WordPress products, you will also be benefited in many ways like,

Bigger Audience: Not all users understand English. And, there are many people who prefer to get plugins in their native languages. So, when you offer the same plugin with and without translation ready. You will hardly find anyone who goes for without translation ready plugin.

Better SEO: Not everyone searches on Google using English. So, if you offer translation ready products, you will get a better search result. And, your users will get better SEO result as well.

Psychological Advantage: Translating your plugin or theme has some positive psychological implications for your customer. Multilingual plugins reflect that the developer invested time on more than just technical issues. Customers will recognize this value and hopefully therefore see the quality of your product in a different way.

How to Translate WordPress Plugins and Themes Automatically

How to translate WordPress plugins and themes

First thing first. 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.

Step 01: Create a Project

  1. Go to https://console.developers.google.com and login
  2. Click “No organization” or select your preferred organization
How to Translate WordPress Plugins and Themes Automatically As a Developer 1

3. Click “Create project”:

How to Translate WordPress Plugins and Themes Automatically As a Developer 2

4. Enter a project name and click “Create”

How to Translate WordPress Plugins and Themes Automatically As a Developer 3

5. Click “Enable APIs and services”

How to Translate WordPress Plugins and Themes Automatically As a Developer 4

6. Search for the “Cloud Translation API” and enable it.

How to Translate WordPress Plugins and Themes Automatically As a Developer 5

In case it demands your billing account. Do it for getting a free trial.

Now we have a project.

Step 02: Create a Service Account

  1. Go to “Service accounts” section from the main menu: “IAM & Admin”
How to Translate WordPress Plugins and Themes Automatically As a Developer 6

2.  Click on “Create service account”

How to Translate WordPress Plugins and Themes Automatically As a Developer 7

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

How to Translate WordPress Plugins and Themes Automatically As a Developer 8

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

How to Translate WordPress Plugins and Themes Automatically As a Developer 9

5. Now click “Create key” and select the JSON format. Then click “Done”.

How to Translate WordPress Plugins and Themes Automatically As a Developer 10

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.

Step 03: Final Step

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.

Congratulations! You have just completed all of the steps to translate WordPress plugins and themes.

Translate Your WordPress Plugins and Sell It Globally

Open source software license management

You don’t need to be global. Instead, make your WordPress products global by offering translation ready plugins and themes and sell them around the world. As a WordPress developer, you must ensure translation files before making your WordPress products selling checklist.

If you face any complication while trying to translate WordPress plugins and themes following our tutorial guide, let us know through the comment box below. We are ready to serve you.

About

Shams is a technology enthusiastic person who loves to write WordPress related content. In his free time, he loves to watch movies and sports. He has a keen interest in traveling all around the world.