cegthgtlhj
cegthgtlhj

Reputation: 311

Django blocktrans problems with rendered variables

I have already translated in this project in the same way a number of similar templates in the same directory, which are nearly equal to this one. But this template makes me helpless.

Without a translation tag {% blocktrans %} it properly works and renders the variable. enter image description here

c_filter_size.html

{% load i18n %}
{% if ffilter %}
  <div class="badge badge-success text-wrap" style="width: 12rem;"">{% trans "Filter sizing check" %}</div>
  <h6><small><p class="p-1 mb-2 bg-info text-white">{% trans "The filter sizing is successfully performed." %}
  </p></small></h6>

    {% if ffilter1 and ffilter.wfsubtype != ffilter1.wfsubtype %}
      <div class="badge badge-success text-wrap" style="width: 12rem;"">{% trans "Filter sizing check" %}</div>
      <h6><small><p class="p-1 mb-2 bg-info text-white">
        If you insist on the fineness, but allow
        to reduce flow rate up to {{ffilter1.flowrate}} m3/hr the filter size and therefore filter
        price can be reduced.
      </p></small></h6>
    {% endif %}

with a translation tag {% blocktrans %} it works neither in English nor in the translated language for the rendered variable. Other similar templates smoothely work. enter image description here

c_filter_size.html

{% load i18n %}
{% if ffilter %}
  <div class="badge badge-success text-wrap" style="width: 12rem;"">{% trans "Filter sizing check" %}</div>
  <h6><small><p class="p-1 mb-2 bg-info text-white">{% trans "The filter sizing is successfully performed." %}
  </p></small></h6>

    {% if ffilter1 and ffilter.wfsubtype != ffilter1.wfsubtype %}
      <div class="badge badge-success text-wrap" style="width: 12rem;"">{% trans "Filter sizing check" %}</div>
      <h6><small><p class="p-1 mb-2 bg-info text-white">
    {% blocktrans %}
        If you insist on the fineness, but allow
        to reduce flow rate up to {{ffilter1.flowrate}} m3/hr the filter size and therefore filter
        price can be reduced.
    {% endblocktrans %}
      </p></small></h6>
    {% endif %}

enter image description here

django.po 

...

#: rsf/templates/rsf/comments/c_filter_size.html:11
#, python-format
msgid ""
"\n"
"        If you insist on the fineness, but allow\n"
"        to reduce flow rate up to <b>%(ffilter1.flowrate)s</b> m3/hr the "
"filter size and therefore filter\n"
"        price can be reduced.\n"
"        "
msgstr ""
"\n"
" Если тонкость фильтрации изменить невозможно, но возможно уменьшить "
"расход до <b>%(ffilter1.flowrate)s</b> м3/час, то "
"размер фильтра и соответственно его цена могут быть уменьшены."

...

Thank you

Upvotes: 0

Views: 1042

Answers (2)

Gavin
Gavin

Reputation: 874

Maybe you could break up your trans blocks into two sections.

{% blocktrans %}
        If you insist on the fineness, but allow
        to reduce flow rate up to {% endblocktrans %}
{{ffilter1.flowrate}}
{% blocktrans %} m3/hr the filter size and therefore filter
        price can be reduced.
{% endblocktrans %}

It doesn't look the best, but it would be impossible to put a variable inside the trans block I think.

On a different note. I noticed you have an error in your inline styles, you have an extra " mark in the following line.

<div class="badge badge-success text-wrap" style="width: 12rem;"">

Upvotes: 0

gdvalderrama
gdvalderrama

Reputation: 806

You can't access to variable properties inside blocktrans. Instead of using {{ffilter1.flowrate}} inside blocktrans you should use the keyword with:

{% blocktrans with flowrate=ffilter1.flowrate %}
    If you insist on the fineness, but allow to reduce
    flow rate up to {{ flowrate }} m3/hr the filter size and
    therefore filter price can be reduced.
{% endblocktrans %}

Also, to avoid having indents inside your translation use the keyword trimmed:

{% blocktrans with flowrate=ffilter1.flowrate trimmed %}

Source: https://docs.djangoproject.com/en/3.0/topics/i18n/translation/#blocktrans-template-tag

Upvotes: 1

Related Questions