Am Dienstag, 6. Mai 2014 02:48:29 UTC+2 schrieb Anthony: > > var set_info_text = function (txt) { >> $('#info_text').innerHTML = '{{=T(txt)}}'; >> }; >> >> Keep in mind that the web2py template syntax is Python that gets executed > on the sever in order to generate the HTML page. On the other hand, any > JavaScript in the page gets executed in the browser, after the HTML has > been generated on the server. You cannot mix JavaScript and Python as if > they will be executed in the same context. > > In the above, the {{=T(txt)}} will be executed only once on the server > when the HTML page is generated. The problem is that the "txt" variable > passed to T() doesn't actually exist in Python on the server, so you are > getting that error. > > If you need to use JS to dynamically insert web2py translations into the > page, you would have to make Ajax calls to the server to request and > receive the translated strings. Hard to say whether that's actually a good > idea without knowing more about what you are trying to do. > > Anthony > > > Ok, i understand my mistake. I have some strings which need to replaced within javascript (klick on a button) and without reloading the page. One possible solution is an ajax call. I have fixed this with another solution like this:
var msg1 = {{T('message one')}} var msg2 = {{T('message two')}} and use this inside my javascript function. This is possible because there only 5 strings which need to be translated. This works for me. Thanks for your help. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.