using the standard __('some-string', 'myplugin')
for translations, strings are being correctly loaded for a Japanese (ja) locale in every function and script other than my AJAX functions.
my-plugin.php:
*Text Domain: myplugin
*Domain Path: /languages/
*/
add_action( 'init', 'myplugin_load_textdomain' );
function myplugin_load_textdomain() {
load_plugin_textdomain( 'myplugin', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
require_once(basename( dirname( __FILE__)."/classes/myplugin_handler.class.php");
global $myplugin_handler;
$myplugin_handler = new myplugin_handler();
myplugin_handler.class.php:
class myplugin_handler
{
public function __construct()
{
add_action('wp_ajax_myplugin_ajax', array($this, 'myplugin_ajax_handler'));
add_action('wp_ajax_nopriv_myplugin_ajax', array($this, 'myplugin_ajax_handler'));
}
public function myplugin_ajax_handler() {
if ($_POST['action'] != 'myplugin_ajax') {
wp_die(0);
}
if (!check_ajax_referer('myplugin-ajax-nonce', 'security')) {
wp_die(0);
}
$closemsg = __('Close', 'myplugin');
wp_die($closemsg);
}
}
Close should translate to 閉じる but it does not. Where translation does work:
- plugin function calls from the theme
- plugin function calls from an admin screen
_e()
and__()
calls in embedded js in the footer- seemingly everywhere else besides AJAX functions
any help is appreciated