0

I can translate strings in python and html files. But When I translate JavaScript strings, I get this error in browser console:

Uncaught ReferenceError: _ is not defined

My setup.py:

message_extractors={'wiki20': [
        ('**.py', 'python', None),
        ('templates/**.html', 'genshi', None),
        ('public/javascript/index.js', 'javascript', None),
        ('public/**', 'ignore', None)
]},

JavaScript file content:

$("#bulbunu2").html(_('jquery two add this..! bla2'));

When I run python setup.py extract_messages, I see js strings in .pot file,(command generate JavaScript strings) but browser give error.

How can I solve this problem?

JasonMArcher
  • 12,386
  • 20
  • 54
  • 51
messah
  • 13
  • 2

1 Answers1

0

TurboGears by itself does not provide a javascript gettext library, after you gathered and translated the strings like you probably already did you will need javascript library to read .po files and a javascript library to translate your strings.

You can use https://www.npmjs.com/package/po2json to read .po files and convert them to JSON, then you can use http://slexaxton.github.io/Jed/ or any other translation library for the _() function itself.

amol
  • 1,609
  • 1
  • 10
  • 15