[Python] Using pybabel to translate tooltip text inside a HTML tag

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    I've basically finished translating my flask frontend into a lot of different languages but there are a couple of tooltips that I just can't seem to figure out. Technically, these need to be strings against the title= property, so the unmodified version would look like:

    <div class="col col-lg-3">
    <label for="newMachineIRR">
    {{ _('Ideal Run Rate (unit/min)') }}
    <button type="button" id="irrTooltip" class="fa-solid fa-circle-info"
    data-bs-toggle="tooltip" data-bs-placement="top" data-bs-delay="0" title="Used to
    specify an optional default ideal run rate for continuous products. It has no effect on
    batch products. Setting a default does not prevent you from specifiying custom run rates
    for particular products">
    </button>
    </label>
    </div>


    No matter what I have tried, I cannot get babel to pick these strings up for translation. Naively, I thought of:

    <div class="col col-lg-3">
    <label for="newMachineIRR">
    {{ _('Ideal Run Rate (unit/min)') }}
    <button type="button" id="irrTooltip" class="fa-solid fa-circle-info"
    data-bs-toggle="tooltip" data-bs-placement="top" data-bs-delay="0" title="{{ _('Used to
    specify an optional default ideal run rate for continuous products. It has no effect on
    batch products. Setting a default does not prevent you from specifiying custom run rates
    for particular products') }}">
    </button>
    </label>
    </div>


    That won't get detected. It also won't be detected/translated if I have it all on one line. I have tried a number of increasingly abstract thoughts to no avail. I can't seem to find this use case defined or described anywhere; what is the correct way to translate the tooltip text? The best I've thought of (perhaps) is to define the text in a hidden div and then use JS to update the title property of the tag on page load but, am I missing something simple here?

    Continue reading...

Compartilhe esta Página