If your widgets include translatable strings, you’ll be able to edit the translation with WPML, but translations are not guaranteed to display on the site.

Method 1) Using WordPress’ filters

WPML uses the standard WordPress filters and translates content that you filter.

All the standard WordPress widgets apply filters by default. When you create your own widgets, you need to make sure that the same happens too.

For instance, to apply filters to a widget title, use this:

$wtitle = apply_filters('widget_title', $wtitle);

WPML connects to the apply_filters call and will make this string translatable via the String Translation page.

Method 2) Registering strings manually

Alternatively, you can use WPML’s string translation functions manually. You can register strings for translation and then look up their translation when displaying.

Note: Starting from WPML 3.3 the icl_register_string and icl_t hooks are no longer supported. Please use the wpml_register_single_string and wpml_translate_single_string hooks instead.

To register strings, use the icl_register_string call:

icl_register_string($context, $name, $value)
    • $context – the name of the plugin, in a human readable format
    • $name – the name of the string which helps the user (or translator) understand what’s being translated.
    • $value – the string that needs to be translated.

Then, when you display the texts, use icl_t to display with translations:

icl_t($context, $name, $value)

Method 3) Using GetText for hard-coded strings

The two methods described before are best for dynamically generated texts. These texts are editable by users via the WordPress Admin panel.

If you have static texts, which are hard-coded in the PHP, you can just use GetText calls, like:

<?php __('Hello world','cool_theme'); ?>

WPML hooks to the GetText calls and makes these texts translatable via the String Translation interface. Please note that this method only works for texts that cannot be edited and are fixed in the theme.