Skip Navigation

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..

Author Posts
January 12, 2023 at 3:20 pm #12806659

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Please take note that our development team is already working on a solution for making JSON files translatable with WPML.

The development is in the early stage yet, so it is unclear when and if this feature will be coming to WPML, as it depends on how many WPML users will request such a feature, but I want you to be aware that the team has taken note of such issues and is working towards a solution in a coming version of WPML.

Your request has been escalated to this internal feature thread so that our developers can take note of it.

Best regards
Andreas

January 12, 2023 at 3:29 pm #12806745

usahello

Thanks for the note, I'll be on the lookout for a future WPML feature that helps us translate JSON files.

August 1, 2024 at 11:16 am #16029179

Laura
Supporter

Languages: English (English ) Italian (Italiano )

Timezone: Europe/Rome (GMT+01:00)

For further updates please follow this errata.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.