So you have embedded Redux into your theme or plugin, and you want to translate it with WPML.

What happens with the option fields used with Redux?
Can they also be translated with WPML?

The answer is yes and we’ll explain everything in simple steps.

Step 1: Find your opt_name variable

The opt_name variable can be found in your Redux configuration file. An example can be found in /sample/sample-config.php, included in the Redux plugin.

This is the variable name saved in the wp_options table. In this example opt_name is: my-theme-options.

Of course you’ll need to define your own unique variable name for your theme or plugin.

    public function setArguments() {

$theme = wp_get_theme();

$this->args = array(
'opt_name' => 'my-theme-options',
'display_name' => $theme->get( 'Name' ),
'display_version' => $theme->get( 'Version' ),

Step 2: Select the options you want to translate

Lets say we want to translate three fields. To make it more interesting we’ll demonstrate three different types of options.

textfield

    array(
'id' => 'my-sample-textfield',
'type' => 'text',
'title' => __( 'Sample Text Field', 'my-text-domain' ),
'subtitle' => __( 'This is the subtitle.', 'my-text-domain' ),
'desc' => __( 'This is the description.', 'my-text-domain' ),
'default' => 'Sample Text'
),

textarea with editor

    array(
'id' => 'my-sample-textarea',
'type' => 'editor',
'title' => __( 'Sample Text Area', 'my-text-domain' ),
'subtitle' => __( 'Write here your copyright text!', 'my-text-domain' ),
'default' => 'Powered by Redux Framework.',
),

sortable textfield array

    array(
'id' => 'my-sample-sortable-textfield',
'type' => 'sortable',
'title' => __( 'Sample Sortable Text Option', 'my-text-domain' ),
'subtitle' => __( 'This is a subtitle.', 'my-text-domain' ),
'desc' => __( 'This is the description.', 'my-text-domain' ),
'options' => array(
'si1' => 'Item 1',
'si2' => 'Item 2',
'si3' => 'Item 3',
)
),

To summarize, in our scenario we have:

A textfield with id: my-sample-textfield
A textarea with id: my-sample-textarea
A sortable text array with id: my-sample-sortable-textfield and options si1 si2 si3

The id’s of the fields will be our WPML translation keys. In case of an array also the options are keys. Write them down.

Step 3: Add your keys in wpml-config.xml

WPML can read a configuration file that tells it what needs translation in themes and plugins. The file is named wpml-config.xml and it’s placed in the root folder of the plugin or theme.

To translate a single option, we need a key entry under admin-texts. To translate a serialized array, we must add several keys under a key.

If the admin-texts block does not exist, you have to write it yourself.
This is how our admin-texts block should look like.

    <admin-texts>
<key name="my-theme-options">
<key name="my-sample-textfield" />
<key name="my-sample-textarea" />
<key name="my-sample-sortable-textfield">
<key name="si1" />
<key name="si2" />
<key name="si3" />
</key>
</key>
</admin-texts>

The first key is always our opt_name e.g: my-theme-options.
The single options as a self-closed key tag and the serialized array as a nested key block.
For the WPML config file you can also refer to the official website:
WPML Language Configuration Files

Step 4: Translate your admin texts via WPML

If not already, you have to save the Admin Language in WPML menu ( Set Default admin language ).
Now you can translate your admin texts via WPML interface under WPML – String Translation.
The context for themes is a concatenation of admin_texts_theme_ + your theme name

And you are finally set!

Leave a Reply