If you wish to translate custom text you can do this by calling the translation function trp_translate($content, $language = null, $prevent_over_translation = true );.
The following parameters are used in the translation function:
The returned value is a string containing the translated content in the initial form (text or HTML), using the translation available in DB or automatic translation if activated. The HTML structure is kept, the function translating only the node and attributes inside tags.
In the following example, we can observe the functionality of the trp_translate function:
function tpc_enqueue_scripts(){ $message = trp_translate('<div>Hey, this is a test.</div><p>This is another test.</p>', 'pt_BR'); $tpc_array = array(); $tpc_array['alert'] = $message; echo '<button id=tpc_test_button>Click Here</button>'; wp_enqueue_script( 'tpc_test_trp_translate_function', plugin_dir_url( __FILE__ ). '/assets/output.js', array("jquery"), 1.0, true ); wp_localize_script( 'tpc_test_trp_translate_function', 'tpc_alert_message', $tpc_array); } add_action('wp_enqueue_scripts', 'tpc_enqueue_scripts');
jQuery(function() { jQuery( '#tpc_test_button' ).on( 'click', function () { alert( tpc_alert_message['alert'] ); } ); });
The following example should append a button that clicked will show an alert box with the translated HTML: