WPML Version: 3.2


*Retrieves an individual (as opposed to a string that is part of a package**) text string translation. The filter looks for a string with matching $domain and $name. If it finds it, it looks for a translation in the current language or the language you specify. If a translation exists, it will return it. Otherwise, it will return the original string.

*To register a string for translation please see: wpml_register_single_string
**For retrieving a string translation that is part of a package please see: wpml_translate_string

Note: This hook requires the WPML String Translation module

Retrieving Localized Content
apply_filters( 'wpml_translate_single_string', string $original_value, string $domain, string $name, string $language_code )
(string) (Required) The string’s original value
(string) (Required) The string’s registered domain
(string) (Required) The string’s registered name
(string) (Optional) Return the translation in this language. Default is NULL which returns the current language
hook example usage:

We pick up the same example of the widget we used for the“wpml_register_single_string” action hook. You may want to go there to refresh your memory. We use the “wpml_translate_single_string” filter in the widget’s output function


function widget($args, $instance){
        $title               = apply_filters('widget_title', $instance['title'] );
        $custom_input        = apply_filters('wpml_translate_single_string', $instance['custom_input'], 'Widgets', 'Custom Widget - input field' );
        $custom_textarea     = apply_filters('wpml_translate_single_string', $instance['custom_textarea'], 'Widgets', 'Custom Widget - textarea field' );

        # Before the widget
        echo $before_widget;

        # The title
        if ( $title )
        echo $before_title . $title . $after_title;

        # Output...