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
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.
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
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
- Go to https://console.developers.google.com and login
- Click “No organization” or select your preferred organization
3. Click “Create project”:
4. Enter a project name and click “Create”
5. Click “Enable APIs and services”
6. Search for the “Cloud Translation API” and enable it.
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
- Go to “Service accounts” section from the main menu: “IAM & Admin”
2. Click on “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
5. Now click “Create key” and select the JSON format. Then click “Done”.
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.
Replace [PATH] with the file path of the JSON file that contains your service account key, and [FILE_NAME] with the filename.
With command prompt:
Now that we are done with the boring stuff, we can start translating!
- Clone the repository from https://github.com/GreenTreeLabs/po-gtranslator
- Open up your command line and run the following command:
- Git clone https://github.com/GreenTreeLabs/po-gtranslator.git
- If you don’t have git installed you can download it here.
- Enter the directory po-translator:
- Install the dependencies:
- In case you don’t have the npm utility be sure to install Node.js from here.
- 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
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.
Subscribe To Our Newsletter
Don’t miss any updates of our new templates and extensions
and all the astonishing offers we bring for you.