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?
The issue here almost entirely came down to the --no-wrap argument for both the init and extract commands. Even if you do everything to prevent text wrapping in the HTML template itself (I had dynamic loading from templates that forced no wrapping), babel itself will still wrap the text. Then you'll get a .pot file that is broken and can't be translated properly.
Instead, I use --no-wrap in both my subprocess calls in my automatic pipeline to do translations:
subprocess.run(
[
"pybabel",
"extract",
"--no-wrap",
"-F",
"babel.cfg",
"-k",
"_l",
"-o",
"messages.pot",
".",
],
check=True,
text=True,
)
And
subprocess.run(
[
"pybabel",
"init",
"--no-wrap",
"-i",
"messages.pot",
"-d",
"src/pro_machina/translations",
"-l",
lang,
],
check=True,
text=True,
)
Now it picks up and recognises the text listed against the title property.