Translate WordPress Themes and Plugins with AI

Get fast, accurate, and affordable translations for WordPress themes and plugins. PTC by WPML delivers human quality at machine speed. PTC powers WPML’s AI translation, translating tens of millions of words every month, between almost every language pair at over 99.5% accuracy.

Translating Your Themes and Plugins With PTC

Private Translation Cloud (PTC) is an AI translation system, optimized for the resource files of software. It includes full support for the resource files that your themes and plugins need. PTC will read your .po/.pot files and produce translations as .po, .mo, JED and l10n.php – for both PHP and React.

Here is how to translate your themes and plugins with PTC:

  1. Sign up for a free 30-day trial account. A trial account lets you get translations from PTC to any language that you choose.
  2. Choose the target languages. PTC translates software from English to popular languages.
  3. Describe your project and target audience. In your description, mention that you’re translating a WordPress theme or plugin and what your theme/plugin does. This will allow PTC to translate with the correct terminology and tone for your product.
  4. Upload the .po/.pot files that contain the texts to translate.
  5. Receive the completed translations. Translation will take a few minutes. You can download the completed translations as .po, .mo, JED or l10n.php.

Congratulations! In just a few minutes, you’ve added human-quality translations to your themes and plugins.

Remember to place the completed translations in your project’s /languages/ folder. If you’re hosting your theme or plugin on wordpress.org, you’ll also need to include a tiny code snippet which tells WordPress to use your translations and not fetch them from the WordPress Communitee Translation project.

Translating the README.TXT, Automated Emails and Other Texts

Your readme.txt contains important information users see, such as the plugin or theme’s description. Since this file is not a resource file like your .pot files, PTC does not detect or translate it automatically.

To translate the readme.txt with PTC:

  1. In your PTC dashboard, go to Translations → Paste to translate.
  2. Paste the parts of your readme.txt you want to translate.
  3. Choose your target languages and click Translate.
  4. Download the translated text and include it inside your theme or plugin package.

If your plugin or theme is hosted on WordPress.org, the Details tab shows the readme.txt content in the user’s language. To make these translations appear on WordPress.org:

  1. Go to your project on translate.wordpress.org.
  2. Add the translations provided by PTC.
  3. Wait for a WordPress translation editor (PTE) to review and approve them.

You can also invite trusted team members to become translation editors to help with approvals.

Automating The Translation Process

You don’t need to upload .po files and download the translations every time there’s a change in your themes and plugins. To automate the translation process, use PTC’s Git integration or API.

Integrate PTC Into Your Git Repository

Connect your GitHubGitLab, or Bitbucket repository to PTC. Specify which branches to monitor. When a change is detected in .po or .pot files in any of those branches, PTC will automatically translate the updated content and send the translations back via a merge request.

To use Git integration, PTC requires read and write access to your repository. This allows it to retrieve the resource file and push translated files. You can grant access using OAuth or a personal access token.

Integrate PTC Into Your CI Process

If you prefer not to give PTC access to your repository, you can still automate translation by connecting your CI workflow to the PTC API. Your CI process can notify PTC when a new version of .po or .pot files is available. PTC will then process the translation and notify your CI when the translated files are ready to download.

Need Help Adding GetText Calls to Your Code and Generating .POT Files?

Instead of explaining the theory behind WordPress internationalization (i18n) and localization (l10n), we’ll show you the necessary steps using a demo plugin that we’ve created especially for training purposes. We’ll cover:

  • How to make a WordPress plugin translation-ready
  • How to translate the text strings and integrate these translations into your plugin

Each step of this tutorial is demonstrated with code changes. Check the demo plugin’s repository to review them via Git commits.

The Goal for Our Demo Plugin: Making it Multilingual

Our demo plugin, OTGS Foo Banner, displays a banner with a customizable message on the front-end. Our goal is to make all strings translatable and add Spanish translations. This way, users who switch WordPress to Spanish can use the plugin in their language.

Steps to WordPress Plugin Internationalization (i18n) and Localization (l10n)

1. Initialize Composer and Install WP-CLI as a Dev Dependency

If you’re not using Composer in your projects yet, initialize it by running composer init. Then, follow the command-line wizard.

Commit Reference: See commit f096381 in GitHub

To run WP-CLI commands, install WP-CLI via Composer by running:

composer require --dev wp-cli/wp-cli-bundle

Commit Reference: See commit 718606e in GitHub

2. Wrap All Texts in GetText Calls

Adding GetText Calls to PHP Code

In PHP, wrap all the hard-coded strings in gettext WordPress localization functions like __() and _e(). Specify a text domain to uniquely identify translations for your theme or plugin.

  • The __() function returns the strings
__('Hello, world!', 'your-text-domain');
  • The _e() function echoes a translatable string
_e('Hello, world!', 'your-text-domain');

These functions find the correct translation in the specified locale and domain. If no translation is available, the original string will remain unchanged.

Commit Reference: See commit 7deef5f in GitHub

Adding GetText Calls to JavaScript (JS) Code

Just like in PHP, make sure that all text in your JavaScript code can be translated into different languages.

WordPress provides the wp-i18n dependency to retrieve translations of text strings.

Specify a text domain for translations to be correctly matched and displayed based on the current language set in WordPress.

Commit Reference: See commit 7deef5f in GitHub

3. Generate the Portable Object Template (POT) File

To translate your code, you will need to generate POT files that include the original texts. You don’t need to create these files manually – below, you’ll find the WordPress commands you need to run to generate the POT files.

Generating the POT File

You need to run a Composer script that scans all the PHP and JS files in your project, looks for GetText calls (which you previously added), and creates a .pot file that includes all the translatable strings in the project.

To do this:

  1. Add the Composer script make-pot to your project to avoid executing the full command manually each time you update the POT file.

Commit Reference: See commit faca3dd in GitHub

  1. Run the make-pot command: composer make-pot

Commit Reference: See commit 452be7f in GitHub

If your project includes bundled JavaScript scripts (for example, via Webpack), use @wordpress/babel-plugin-makepot instead. 

4. Create the Translations

Now that you have the resource files, translate them with PTC.

5. Configure and Load Translation Files in WordPress

Lastly, configure WordPress to recognize and load the translation files for both PHP and JavaScript components of the plugin or theme.

Load the Plugin’s Text Domain for PHP Files

Tell WordPress where it can find the translation files for your PHP code. 

Commit Reference: See commit 270424b in GitHub

Load the Script Translations for Your JavaScript Files

To load the script translations for your JavaScript files, you need to tell WordPress where to find the JSON files. In our example, we use a file named confirm.js.

Commit Reference: See commit 3a77340 in GitHub

Make Your WordPress Projects Multilingual

By translating your WordPress themes and plugins, you can reach a broader, global audience. WordPress itself supports numerous languages, and your themes and plugins should too.

With PTC, you get…

Instant, Better Than Human Translations

Different setup options, including Integration with your software repository and translations sent as merge requests

Unlimited translation rounds, enhanced by AI and machine learning

Scroll to Top