Using XML to define translatable strings in WPML

WPML, a plugin for handling multilingual content in WordPress, has the ability to read an XML file  for its configuration. In this language configuration file, we can define which custom fields, custom post types, taxonomies and admin texts we want translatable in our theme.

I’ve been using a WooThemes commercial theme for a client, but ran in to a problem when trying to translate the footer. The theme allows the user to add custom content for the footer through a text field in its options panel; this text is therefore not wrapped in any gettext function, blocking WPML from hooking in to it automatically.

The problem was solved by adding the following (saved as wpml-config.xml) to the root of the parent theme folder:

        <key name='woo_options'>
            <key name='woo_footer_left_text' />
            <key name='woo_footer_right_text' />

This file tells WPML to make the values of the two listed keys into translatable strings, to be found under WPML → String Translation. woo_options is the name of the option (itself an array) containing the needed values.

wpml-config.xml provides a clean, simple way to define translatable strings for the often troublesome elements of a theme; ask your commercial theme providers to provide these configuration files with all of their themes.

Published by

Kirk Wight

I am a Code Wrangler at Automattic, helping make the best it can be. Pender Island, British Columbia, Canada is where I call home. Lover, not a fighter.

3 thoughts on “Using XML to define translatable strings in WPML”

  1. Just echo out the option as you normally would, and WPML will provide the correct string:

    echo esc_html( $woo_options[ ‘woo_footer_right_text’ ] );

  2. Hey Kirk – thanks for posting this solution to Canvas not wrapping the footer custom text in gettext. I’m rebuilding my own multilingual site (teaching English) using Canvas and find it and WPML very good, but there are always snags along the way. I managed to carefully edit in what you suggested into my wpml-config.xml file and then rescanned with for strings with WPML and up popped my footer text. I’m not a developer, just an enthusiast of necessity here in Dublin. – rgds, Todd ( new site will be up and running hopefully in the coming weeks)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s