Gutenberg translation is not working

I’ve spent all day debugging this issue, and by looking at the code I can guess we shared the same problems:

  1. assuming $script_handle is CUSTOM-block-ref-holder, the PHP file is almost correct.
  2. wp_set_script_translations needs the full path to work. In your case, although you probably need to adjust for your path, it should be something like
wp_set_script_translations(
  'CUSTOM-block-ref-holder',
  'custom-blocks',
  plugin_dir_path(__FILE__) . 'languages/'
);
  1. The name of the JSON file should be custom-blocks-zh_HK-CUSTOM-block-ref-holder.json
  2. The “domain” fields don’t really matter in the JSON (as of today), I left them as messages, as per default from WP CLI, but in my tests they worked even with totally arbitrary and random strings.

Reference: JavaScript i18n support in WordPress 5 | Advanced usage

Leave a Comment