[Wordpress] i18n works with gutenberg & js 

//Please install wp-cli
https://www.neverj.com/linux-how-to-install-wp-cli/

//Please install Loco Translate plugin to your wordpress

//create pot file
wp i18n make-pot . [textdomain].pot

why don't using Loco Translate to create pot, coz it can't scanning all js file which is containing wp.i18n function. So the pot file will be get the php translate line only. This is the reason.

//create po file
after install Loco Translate then click inside and select your translate target
after that select the language you have to make it. done.

//update po file
use Loco Translate to add the new language content then save. the translation json file will be created automatically.

//All file Done.

//then program
wp_register_script([js_name],[js_file_path],['wp-i18n','...'],[file_version]);
wp_enqueue_script([js_name]);
wp_set_script_translations(
        '[js_name]',    //script_name
        '[text_domain]',                  //text domain
        '[path_of_the_translate_file]'  //json path, no need point file. Just folder is fine. And make sure the path is correct.
    );

//All Done.

//Suggestion
//after all action, you can move the translate file(pot/po/mo/json) into lang folder for easier manage.





Back