简体   繁体   English

django javascript 翻译与简单的插值

[英]django javascript translation with simple interpolation

The documentation for javascript translation in django only gives examples of pluralised interpolation. django 中javascript 翻译文档只给出了复数插值的例子。 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应该将text设置为Displaying 5 / 10

But this isn't working for me.但这对我不起作用。 I get Displaying %(count)s / %(total)s as the value for for text .我得到Displaying %(count)s / %(total)s作为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:没有named = true,你可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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