This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by jonathanW-7 1 year ago.

Assigned support staff: Bruno.

Author Posts
October 2, 2018 at 11:04 pm #2782952

jonathanW-7

Tell us what you are trying to do?

I want to "localize" a JS script with an object of translated strings with wp_localize_script, just like in the example: http://codex.wordpress.org/Function_Reference/wp_localize_script
But instead of creating the object with the translated strings on every page load, I want to save / read the whole object as a transient with set_transient() and get_transient(). This is all no problem, but what I want to know is how can I call delete_transient() whenever a string translation is saved, so that I can make sure that the transient is always up to date. I am looking for a hook like 'save_post', only for string translations.

October 5, 2018 at 12:12 am #2788998

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us. Please, my sincere apologies for the delay in answering.

You can use the hook "wpml_st_string_translation_before_save". This hook will be called before the string is updated. That way, you can remove/updated the desired transient:

// EXAMPLE
add_filter( 'wpml_st_string_translation_before_save', function( $translation_data, $language, $string_id ) {

	// delete_transient()

	return $translation_data;
}, 10, 3 );

Please, let me know if I can help with any other questions you may have. I'll be happy to help.

Thank you.

October 5, 2018 at 8:47 am #2789913

jonathanW-7

My issue is resolved now. Thank you!