title: Flask-Babel localized strings within js
body: <p>I'm pretty new to both Python and Flask (with Jinja2 as template engine) and I am not sure I am doing it the right way. I am using Flask-Babel extension to add i18n support to my web application. I want to get localized strings from my js code, for instance:</p>
  
  <pre><code>var helloWorld = gettext('Hello, world');
  console.log(helloWorld); //should log a localized hello world message
  </code></pre>
  
  <p>For this, I configured babel (babel.cfg):</p>
  
  <pre><code>[python: **/**.py]
  [jinja2: **/**.html]
  extensions=jinja2.ext.autoescape,jinja2.ext.with_
  [javascript: **/**.js]
  encoding = utf-8
  </code></pre>
  
  <p>And its initialization is (imports omitted for simplicity):</p>
  
  <pre><code>#main Flask app
  app = Flask(__name__)
  
  #localization
  babel = Babel(app)
  
  LANGUAGES = {
      'ca': 'Catalan',
      'en': 'English',
      'de': 'Deutsch',
      'es': 'Español',
      'fi': 'Finnish',
      'it': 'Italian'
  }
  
  @babel.localeselector
  def get_locale():
      return request.accept_languages.best_match(LANGUAGES.keys())
  
  #some more stuff...
  </code></pre>
  
  <p>Babel identifies that string when building the POT/PO language files, but it seems I can't access these localized strings from js code since gettext function is not defined. It seems like Jinja2 is ignoring this part.</p>
  
  <p>Any hints?</p>