How to combine 'blocktanslate' with 'humanize' tag in templates?

Viewed 50

blocktranslate allows me to display a localized plural, whereas humanize allows me to display a grouped-by-hundred number.

Each of them works when used independently but I'd like to have both in the same time.

I've tried:

(words_number is the integer sent by the view)

{% load humanize %}
{% blocktranslate count counter=words_number %}
1 word
{% plural %}
{{ counter|intcomma }} words
{% endblocktranslate %}

But it displays: words (empty space where the number should be)

EDIT: Before a solution will be found, I'm using Javascript to group by hundred:

{% blocktranslate count counter=words_number %}
1 word
{% plural %}
<span id="counter">{{ counter }}</span> words
{% endblocktranslate %}

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
    let counter = document.getElementById('counter');   
    let counter_loc = parseInt(counter.innerHTML).toLocaleString();
    counter.innerHTML = counter_loc;
});
</script>
1 Answers

As described in the documentation for the blocktranslate template tag to use filters or expressions on variables you need to bind them to some local variable using with, so you can do something like follows:

{% load humanize %}
{% blocktranslate with count_humanized=words_number|intcomma count counter=words_number %}
1 word
{% plural %}
{{ count_humanized }} words
{% endblocktranslate %}
Related