最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

django javascript translation with simple interpolation - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited May 22, 2021 at 7:03 ThePhi 2,6313 gold badges32 silver badges39 bronze badges asked Jul 11, 2012 at 6:28 iancolemaniancoleman 2,7862 gold badges21 silver badges17 bronze badges 2
  • You're missing true argument: interpolate(format, {"count": 5, "total": 10}, true). – freakish Commented Jul 11, 2012 at 6:34
  • ah yes I see, I was looking at the non-named interpolation example on the django docs. Perfect. – iancoleman Commented Jul 11, 2012 at 7:14
Add a ment  | 

2 Answers 2

Reset to default 11

You're missing true argument:

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]);
发布评论

评论列表(0)

  1. 暂无评论