简体   繁体   中英

django javascript translation with simple interpolation

The documentation for javascript translation in django only gives examples of pluralised interpolation. I want to do something simple like below:

var format = gettext("Displaying %(count)s / %(total)s")
var text = interpolate(format, {"count": 5, "total": 10})

which should set text to Displaying 5 / 10

But this isn't working for me. I get Displaying %(count)s / %(total)s as the value for for text .

Does anyone know how to do this simple sort of interpolation?

你错过了true论点:

var text = interpolate(format, {"count": 5, "total": 10}, true);

And without named = true, you can do:

var format = gettext("Displaying %s / %s")
var text = interpolate(format, [5, 10]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM