Hi Tim, thanks for reply.
I don’t see the .json file as a resource loaded by the browser. How can I check exactly if the js objects are correctly loaded?
I send you the scripts used in the plugin:
<?php
/*
Plugin Name: My Plugin
...
Text Domain: auteciot
Domain Path: /languages
*/
add_action( 'init', 'mmelandri_plugin_load_text_domain' );
function mmelandri_plugin_load_text_domain() {
load_plugin_textdomain( 'auteciot', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
function mmelandri_wp_enqueue_scripts()
{
wp_enqueue_script( 'auteciot-script-functions', plugins_url( '../frontend/js/functions.js', ( __FILE__ )), array ( 'wp-i18n', 'jquery' ), '1.0.0');
}
add_action( 'wp_enqueue_scripts', 'mmelandri_wp_enqueue_scripts' );
function mmelandri_wp_load_text_domain()
{
wp_set_script_translations( 'auteciot-script-functions', 'auteciot', plugin_dir_path( dirname(__FILE__) ) . 'languages/');
}
add_action( 'wp_enqueue_scripts', 'mmelandri_wp_load_text_domain', 100 );
In /plugins/auteciot/functions.js:
const { __, _x, _n, sprintf } = wp.i18n;
console.log(__('Il campo \'%s\' deve contenere %s caratteri.', 'auteciot'), 'A', '99');
console.log(sprintf(__('Il campo \'%s\' deve contenere %s caratteri.', 'auteciot'), 'A', '99'));
In auteciot-en_US.po:
#: frontend/js/functions.js:49
#, javascript-format
msgid "Il campo '%s' deve contenere %s caratteri."
msgstr "The field '%s' must contain %s characters."
In plugins/auteciot/auteciot-en_US-78aae6d73b1bd2d0505f0d1ffcd6bc85.json:
{"translation-revision-date":"2021-05-31 13:18+0000","generator":"Loco https:\/\/localise.biz\/","source":"frontend\/js\/functions.js","domain":"auteciot","locale_data":{"auteciot":{"":{"domain":"auteciot","lang":"en_US","plural-forms":"nplurals=2; plural=n != 1;"},"Il campo '%s' deve contenere %s caratteri.":["The field '%s' must contain %s characters."],"Il campo '%s' deve contenere da %s a %s caratteri.":["The field '%s' must contain %s to %s characters."]}}}
I tried with both the ‘Pretty Formatting’ setting toggle.