title: nodejs i18n __ is not a function issue with ejs, express
body: <p>I want to implement multi-language in my express (nodejs)
  However I cannot understand why my ejs do not understand "__" underscore.</p>
  
  <p>app.js</p>
  
  <pre><code>var i18n = require('./i18n');
  app.use(i18n);
  </code></pre>
  
  <p>i18n.js</p>
  
  <pre><code>var i18n = require('i18n');
  
  i18n.configure({
    locales:['fr', 'en'], 
    directory: __dirname + '/locales', 
    defaultLocale: 'en',
    cookie: 'lang'
  });
  
  module.exports = function(req, res, next) {
    i18n.init(req, res);
    res.locals.__ = res.__;
    var current_locale = i18n.getLocale();
    return next();
  };
  </code></pre>
  
  <p>router.js</p>
  
  <pre><code>console.log(res.__('hello'));    // print ok
  console.log(res.__('helloWithHTML')); // print ok
  
  req.app.render('index', context, function(err, html) {
    res.writeHead('200', {'Content-Type':'text/html;charset=utf8'});  
    res.end(html);
  });
  </code></pre>
  
  <p>/locales/en.json</p>
  
  <pre><code>{
    "hello": "Hello.",
    "helloWithHTML": "helloWithHTML."
  }
  </code></pre>
  
  <p>index.ejs</p>
  
  <pre><code>&lt;%= __("hello")%&gt;
  </code></pre>
  
  <p>I got an error message for this:</p>
  
  <pre><code>__ is not defined at eval (eval at compile (/home/nodejs/node_modules/ejs/lib/ejs.js:618:12), :41:7) at returnedFn 
  </code></pre>
  
  <p>However I can see the log message from router:</p>
  
  <pre><code>console.log(res.__('hello'));  // print out Hello
  console.log(res.__('helloWithHTML')); // print out helloWithHTML
  </code></pre>
  
  <p>It works fine, I can see both <code>hello</code> and <code>helloWithHTML</code> values.</p>
  
  <p>But <code>ejs</code> do not recognize <code>i18n</code> variable at all.</p>
  
  <p>How can I resolve my issue?</p>