Help debugging translation failure
-
wrote on 12 Sept 2021, 19:46 last edited by
I've been trying to figure out why translations don't seem to work in my app (and similar code worked in Qt4).
QLocale currentLocale; qDebug() << "Locale: " << currentLocale.name();
This looks good - we see the right
LANG
show up.avoTranslator->load(currentLocale, "avogadroapp", "-", translationPath)
returns true - so it finds the QM files
app.installTranslator()
returns true so the translator is loadedNothing in the interface shows up with translation. So I tried:
qDebug() << "Translated: " << app.translate("MainWindow", "&Export");
Nope, no translation.
Again, I just ported our working Qt4 code for Qt 5.12.x.
Now we use
.po
files and uselconvert
andlrelease
to generate the*.qm
files:
lconvert -locations none $x -o ${x%%.po}.ts
lrelease -compress -removeidentical *.ts
Again, this was the procedure with our working Qt4 app.
I'm not sure where to start. Is there a good breakpoint or method to see why my loaded translations aren't working?
Any ideas on how to debug this would be welcome. (I'm not looking for solutions - just ideas / starting places.)
Thanks in advance!
-
I don't know solution, and I've never worked with
.po
files, but maybe some of this will help:- try out different Qt versions. I've recently had a case where translations generated by Qt 5.12.10 were not working, but when Qt 5.12.5 was used all was fine (with absolutely no code changes!)
- make sure you clean up whole build directory to always have a clean compilation. It's easy to get stuck with old
.qm
file when tweaking code and doing incremental builds - open the
.ts
files in Qt Linguist and see if translations are there
-
I don't know solution, and I've never worked with
.po
files, but maybe some of this will help:- try out different Qt versions. I've recently had a case where translations generated by Qt 5.12.10 were not working, but when Qt 5.12.5 was used all was fine (with absolutely no code changes!)
- make sure you clean up whole build directory to always have a clean compilation. It's easy to get stuck with old
.qm
file when tweaking code and doing incremental builds - open the
.ts
files in Qt Linguist and see if translations are there
wrote on 13 Sept 2021, 13:50 last edited by@sierdzio - thanks. The files are definitely cleaned up. I'll try a different Qt version soon.
As to Linguist - the translations are there and "finished" (green check) so that's good.
Do the
.qm
files depend on the Qt version that generate them? Like if I generate them on Ubuntu GitHub actions, can I use them on a Mac or Windows system? -
@ghutchis said in Help debugging translation failure:
"MainWindow", "&Export"
Please take a look into the ts files and see if there is really a section
MainWindow
with the to be translated text&Export
-
@ghutchis said in Help debugging translation failure:
"MainWindow", "&Export"
Please take a look into the ts files and see if there is really a section
MainWindow
with the to be translated text&Export
wrote on 13 Sept 2021, 16:16 last edited by@Christian-Ehrlicher I've tried everything, including
nullptr
, and""
(empty string). (The source code forQTranslate
convertsnullptr
into""
.)The
lconvert
creates.ts
files with no context. So I tried manual translation both with and without context.I guess one question is if the
tr()
calls all have context, do they "fall back" to a translation without context? I'm having trouble following that part of the code:
https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qtranslator.cpp -
@ghutchis said in Help debugging translation failure:
do they "fall back" to a translation without context?
No
-
Hi,
Just a wild idea but did you check for difference in sizes between your old and working files and the new ones ?
I would also compare with files generated using the classic workflow.
Using a minimal dummy application might also help find the culprit.
-
@sierdzio - thanks. The files are definitely cleaned up. I'll try a different Qt version soon.
As to Linguist - the translations are there and "finished" (green check) so that's good.
Do the
.qm
files depend on the Qt version that generate them? Like if I generate them on Ubuntu GitHub actions, can I use them on a Mac or Windows system?@ghutchis said in Help debugging translation failure:
Do the .qm files depend on the Qt version that generate them? Like if I generate them on Ubuntu GitHub actions, can I use them on a Mac or Windows system?
No, the are usually compatible with a very wide range of Qt versions. But as I mentioned in my comment - bugs happen :-)
1/8