WPML Version: 3.2


*Registers a individual (as opposed to a string that is part of a package**) text string for translation. This action is usually used for user input texts otherwise referred to as “dynamic text strings”

*For retrieving a string translation please see: wpml_translate_single_string
**For registering a text string that is part of a package please see: wpml_register_string

Note: This hook requires the WPML String Translation module

Inserting Content
do_action( 'wpml_register_single_string', string $context, string $name, string $value )
(string) (Required) This value gives the string you are about a context. This will usually be the name of the plugin or theme, in a human readable format
(string) (Required) The name of the string which helps the translator understand what’s being translated
(string) (Required) The string that needs to be translated
hook example usage:

Imagine you have created a custom widget with a title input field and some other options. You can register the widget title for translation using apply_filters but you also want to register the input text you can save in the widget’s other option fields.

Registering input texts for translation is best done when the widget options are saved or updated i.e. inside the ‘update’ method of widgets.

Below is an example of what the code could look like. Our example custom widget has a title, a single line input field and a text area.


function update($new_instance, $old_instance){
	$instance = $old_instance;
	$instance['title'] 		= strip_tags($new_instance['title']);
	$instance['custom_input'] 	= strip_tags($new_instance['custom_input']);
	$instance['custom_textarea'] 	= $new_instance['custom_textarea'];

	 * register strings for translation
	do_action( 'wpml_register_single_string', 'Widgets', 'Custom Widget - input field', $instance['custom_input'] );
	do_action( 'wpml_register_single_string', 'Widgets', 'Custom Widget - textarea field', $instance['custom_textarea'] );

	return $instance;

The code above tells WPML that the user input text for the input field and textarea needs to be translated. The texts will be registered under the “Widgets” strings context with the name “Custom Widget – input field” and “Custom Widget – textarea field” respectively.