Autonomía digital y tecnológica

Código e ideas para una internet distribuida

Linkoteca. wp_set_script_translations


You need to “tell” WP that your script has a translation, and specify which text domain (ID) should be used for this translation. This is done using the wp_set_script_translations() function.

So, the registration of your script with translation should look like this:

wp_register_script( ‘my-handle’, plugins_url( ‘/js/my-file.js’, __FILE__ ) );
wp_set_script_translations( ‘my-handle’, ‘my-domain’ );

The wp_set_script_translations() function adds a dependency on the main script for wp-i18n and includes the .json file.