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
2 Answers
Reset to default 11You'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]);