This thread is resolved. Here is a description of the problem and solution.
Problem:
The client is trying to fetch a localized string for a JavaScript file in the Gutenberg editor, but the string is not being returned in the current language of the admin screen, even after attempting to switch languages programmatically.
Solution:
We recommend using the
wp_set_script_translations
function to ensure that the JavaScript file recognizes the localized strings. This involves generating a .json file from the .po file and ensuring it is loaded through a WordPress hook. Here are the steps:
function usahello_demo_set_script_translations() {<br /> wp_set_script_translations('create-block-usahello-demo-editor-script', 'usahello-demo', plugin_dir_path(__FILE__) . 'languages');<br />}<br />add_action('init', 'usahello_demo_set_script_translations');<br /><br />function usahello_demo_block_load_textdomain() {<br /> load_plugin_textdomain('usahello-demo', false, 'usahello-demo/languages');<br />}<br />add_action('plugins_loaded', 'usahello_demo_block_load_textdomain');
For more detailed guidance, refer to the WordPress documentation on how to handle internationalization in block editors: Internationalization in Gutenberg.
If this solution does not resolve your issue, or if it seems outdated or irrelevant to your specific case, we highly recommend checking related known issues at WPML Known Issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. Additionally, you can open a new support ticket for further assistance at WPML Support Forum.
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 17 replies, has 3 voices.
Last updated by Laura 3 months, 1 week ago.
Assisted by: Andreas W..