QMessageBox buttons translation not working
-
I need to translate the buttons on a QMessageBox. For example if I have this code:
QMessageBox::question(NULL, QObject::tr("Sure want to quit?"), QObject::tr("Sure to quit?"), QMessageBox::Yes | QMessageBox::No);
I would like to translate "Yes" and "No". After searching on the web, I found that I need to add this code to main.cpp (for Swedish):
QTranslator translator; baseTranslator.load("qtbase_sv", QLibraryInfo::location(QLibraryInfo::TranslationsPath)); app.installTranslator(&baseTranslator);
This works for French (replacing
"qtbase_sv"
with"qtbase_fr"
), but when I try to translate it in Swedish (using"qtbase_sv"
), the buttons are in English (it says "Yes" and "No" instead of "Ja" and "Nej"). How do I fix that? -
Hi
Check there even is such file.
C:\Qt\5.9.1\msvc2015_64\translations
( note compiler name)a---- 28-06-2017 14:54 165327 qtbase_bg.qm
-a---- 28-06-2017 14:54 179242 qtbase_ca.qm
-a---- 28-06-2017 14:54 174691 qtbase_cs.qm
-a---- 28-06-2017 14:54 169653 qtbase_da.qm
-a---- 28-06-2017 14:54 187985 qtbase_de.qm
-a---- 28-06-2017 14:54 16 qtbase_en.qm
-a---- 28-06-2017 14:54 165160 qtbase_es.qm
-a---- 28-06-2017 14:54 161027 qtbase_fi.qm
-a---- 28-06-2017 14:54 166157 qtbase_fr.qm
-a---- 28-06-2017 14:54 173572 qtbase_gd.qm
-a---- 28-06-2017 14:54 138680 qtbase_he.qm
-a---- 28-06-2017 14:54 91101 qtbase_hu.qm
-a---- 28-06-2017 14:54 161162 qtbase_it.qm
-a---- 28-06-2017 14:54 129904 qtbase_ja.qm
-a---- 28-06-2017 14:54 131255 qtbase_ko.qm
-a---- 28-06-2017 14:54 153598 qtbase_lv.qm
-a---- 28-06-2017 14:54 162972 qtbase_pl.qm
-a---- 28-06-2017 14:54 157842 qtbase_ru.qm
-a---- 28-06-2017 14:54 125753 qtbase_sk.qm
-a---- 28-06-2017 14:54 158264 qtbase_uk.qm -
@mrjj No, there wan't that file, but I found a file named qt_sv.qm. If I use that file, it translates the half select color dialog (on this screenshot I've circled in green the translated parts and in red the non-translated parts), but it doesn't translate the yes and no buttons (the French qt_fr.qm translates everything). How can I make it translate everything in Swedish?
Also, I have another question. Since the translated files are in a Qt folder, do I need to release them with the executable so that people who install my program but don't have Qt can use them? Or is that done automatically (in a DLL file, when compiling the executable or other)?
-
@Donald-Duck said in QMessageBox buttons translation not working:
How can I make it translate everything in Swedish?
First read
http://doc.qt.io/qt-5/linguist-overview.htmlThen open the corresponding TS file and have a look what is included.
Then translate the rest and compile it.As far as you know you must include all qm with your installer.
-
Where do I find the TS file? I can only find QM files in that folder and they're already compiled so I can't really edit them. Or do I need to make my own TS file and translate everything myself, even the parts that are already translated?
-
Hi
I think they are included in the source code.
You can use the maintenance.exe to install it.But please note that different text belongs to different files.
like the msg text is from qtbase_ i guess. etc.I recommend a bit of research before fiddling around with it.
-
@Donald-Duck
If you get svensk going, please post link to file here.
i will find out how we can get it included.
God fornøjelse :) -
@mrjj I've uploaded a ZIP file containing the TS and QM files for my translation of
qtbase_sv
here: http://www.files.com/shared/59e610d1e9105/qtbase_sv.zip. This translation should be as complete as the French one (which is one of the most complete ones I've found).