更好的是,为此使用WP的功能,这是多语言的示例:
add_action( 'admin_enqueue_scripts', 'add_scripts' );
function add_scripts($where) {
wp_localize_script( 'post2media', 'post2media_strings', $this->localize_vars() );
}
function localize_vars() {
$strings = array(
'btntext' => __( 'Link with post', INPSYDE_P2M_TEXTDOMAIN ),
'txtallnone' => __( 'Include in gallery:', INPSYDE_P2M_TEXTDOMAIN ),
'txtall' => __( 'All', INPSYDE_P2M_TEXTDOMAIN ),
'txtnone' => __( 'None', INPSYDE_P2M_TEXTDOMAIN ),
'ttlcb' => __( 'Include image in this gallery', INPSYDE_P2M_TEXTDOMAIN )
);
return $strings;
}
在js文件中使用它:
jQuery(function ($) {
buttonaddfunc = function() {
btntext = post2media_strings.btntext;
reg = /\d+/;
$( '.savesend > .button' ) . each( function() {
inputname = $( this ) . attr( 'name' );
number = reg . exec( inputname );
$( this ) . after( '<input type="submit" value="' + btntext + '" name="link[' + number + ']" class="button">' );
} );
$( '.describe-toggle-on' ).unbind( 'click', buttonaddfunc );
};
$( '.describe-toggle-on' ).bind( 'click', buttonaddfunc );
});
另请参阅Otto的帖子