WPML Translate Custom WordPress Plugin Text Fields

I will explain how to translate custom text fields of WordPress plugins using WPML (WordPress Multilingual Plugin) and XML formatted “Language Configuration Files“. Even thought not mandatory, phpMyAdmin and Firebug have been used in this example. I’ve tried to make this guide easier to understand and more useful than the official documentation which can be a headache for newbies.

To demonstrate the process I set up a “multilingual coming soon page” using the Ultimate Coming Soon Page plugin for WordPress. The plugin settings contain custom text boxes where you can write content in one language only. To translate this text in WPML, it requires the “WPML String Translation” plugin and a bit of extra effort which I will explain here.

I would like to note that (unlike WPML) in Qtranslate for WordPress, you can use “language tags” to enter content in different languages within the same text field. But this feature does not work within plugin settings. Comparing the “work arounds” for translating plugin content between the two, I think the one for Qtranslate isn’t any easier.

First make sure you have these two plugins installed and activated:

WPML Multilingual CMS
WPML String Translation

When you have the “String Translation” plugin installed, you can see an additional menu option for it in the admin dashboard. On this page you can translate content, however in the case of plugin text fields the strings are not shown automatically. So we need to create a “Language Configuration File” for each plugin in XML format.

To create the file, you need to find the attributes used by the plugin to fetch the strings of text from your MySQL database. There are a few ways around it, here is a few that I prefer.

Using for example, the Firebug page inspector or anything that will show you the source code of a page that has plugin content that you want translated.. Look for the text inside the source code, and what kind of DIV it’s wrapped inside of.

So in the case of the “Ultimate Coming Soon Page” plugin. The coming soon page has the following HTML:

<h1 id="teaser-headline">The title in English to be translated</h1>

Now locate the plugin file that uses the ID attribute. An easy way to do this in a linux console is:

grep -r -H “teaser-headline” /path/to/your/plugin/directory

The above query results in the following piece of code:

./ultimate-coming-soon-page/inc/template/template-coming-soon.php: <h1 id="teaser-headline"><?php echo $sc_jdt['comingsoo
n_headline'] ?></h1>

The MySQL attribute here is “comingsoon_headline“.

Next you could have a further look into the file, template-coming-soon.php and look for  the get_option line, on the top of the page.

$sc_jdt = get_option('seedprod_comingsoon_options');

The attribute you need here is “seedprod_comingsoon_options“.

The other way is to go to phpMyAdmin or another MySQL client and search for “comingsoon_headline” which is a table value inside the “wp_options” table. This will also discover the name of the table option, “seedprod_comingsoon_options” and inside it are all the rest of the attributes you might need.

Once all the attributes are collected, we create a file named: wpml-config.xml & place it inside the plugin directory. Ex: “~/public_html/wp-content/plugins/ultimate-coming-soon-page”. Examples of the file format below.

First comes the name of the table option and then the string values inside of it. This is the example for the “Ultimate Coming Soon Page” plugin:

<wpml-config>
<admin-texts>
<key name="seedprod_comingsoon_options">
<key name="comingsoon_description" />
<key name="comingsoon_headline" />
</key>
</admin-texts>
</wpml-config>

And this one is for the Easy Coming Soon plugin:

<wpml-config>
<admin-texts>
<key name="soon_page_settings">
<key name="title" />
<key name="descrip" />
</key>
</admin-texts>
</wpml-config>

The change should be instant and you can see the strings in the string translation menu of WPML, ready to be translated!

1 thought on “WPML Translate Custom WordPress Plugin Text Fields”

Leave a Comment