Let me have wordpress to complete I18N for my javascript. My plan's to possess javascript code in php file. For instance, one sample.js.php file as below:

function foo()
{
   alert(<?php _e('do something'); ?>);
}

The sample.js.php file is known as javascript.

<script type='text/javascript'>url-to-myplugin/sample.js.php</script>

However, it appears __() and _e() does't work because they are not defined. Steps to make the _e() and __() operate in my situation?

Thanks


I discovered the solution. Below code is going to do the job.

<?php
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
?>

Just include Wordpress configuration file into sample.js.php script:

<?php require_once 'your-path-to/wp-config.php'; ?>

function foo()
{
   alert(<?php _e('do something'); ?>);
}

Perhaps you have installed gettext extenssion?