Solved qtranslator with dynamic labels
-
@Pablo-J.-Rogina I want to translate from italian to english, so how must i write in .pro?
and an other question, if I write manually,like this..void MainWindow::on_Traduzione_Inglese_clicked() { qApp->installTranslator(&Lingua_Italiana); ui->Traduzione_Italiano->setDisabled(false); // if(ui->info->text=="CONF. IN CARICAMENTO") if(ui->Info->text()=="CONF. IN CARICAMENTO") ui->Info->setText("cONF..lOADING"); }
in Info doesn't wtite conf loading..because installTranslaton block this I think
-
@vale88 it looks like you're not following the suggestions, like reading the documentation...
-
@Pablo-J.-Rogina yes I read but if I must translate from italian to english,I must write.
TRANSLATIONS = yourApp_en.ts ? -
@vale88
Hi
The ts files can be named anything.
it is just a normal convention to name them
appname_languagecode.ts
as then the filename can be constructed based on locale
But yes, your English language could be
TRANSLATIONS = yourApp_en.ts
and you simply used that name to load it. -
@mrjj ok, so with this I call a file ts that I must build? it's not automatic..sorry but i read documentation but i don't find a example clear
-
@vale88 said in qtranslator with dynamic labels:
@mrjj ok, so with this I call a file ts that I must build? it's not automatic..sorry but i read documentation but i don't find a example clear
than you didn‘t read carefully enough the docs even have an example
https://doc.qt.io/qt-5/qtlinguist-hellotr-example.htmla compileable one.
-
@J.Hilk yes, I read..
Tries to load a file called hellotr_la.qm (the .qm file extension is implicit) that contains Latin translations for the source texts used in the program. No error will occur if the file is not found.but I would like see an exaple of file ts to see how I must write it
-
Hi
No, the translation is not automatic.
You use lupdate to extract the texts to the TS
Then qt linguist to open and help translate
then qt linguist can compile the ts to qm
and you load the qm version to translate the app.But try to do the sample @J-Hilk links.
Its very basic and shows the procedure very well. -
@mrjj ok, I found a tutorial, tomorrow I try, thanks anyway
-
@vale88
Hi
Just a note.- but I would like see an exaple of file ts to see how I must write it
You don't write the ts file your self. that part is from extracting the texts with the tool
-
@mrjj I found an example in youTube, without see I didn't understand, I solved, I used prompt di comandi, thanks anyway
-
@vale88
Ok. super :) -
@mrjj only a thing..if I change something in my project, must I recreated my file ts? or I can update it
-
@vale88
You can update it.
Just like how you created it first time.
It will then add new texts to the file. -
@vale88 said in qtranslator with dynamic labels:
I found an example in youTube
It'd be great you can share the link so other users in your same condition could benefit.
In addition, since your issue seems solved, please don't forget to update your post. Thanks.
-
@Pablo-J.-Rogina https://www.youtube.com/watch?v=In5QH_ZrDJE
but I noticed that if I push in button english then labels are written in english because I put tr, but the labels just written in Italian aren't changed in english if I click button after...is it normal? -
@vale88
Hi
Yes that is normal.
Only when you call setText , new text can be used if you loaded a installTranslator
in the mean time. -
@mrjj a ok, is there a way to solve it?if I try manually it isn't work because there the translator
-
@vale88
Hi
Im not sure what you are doing.
After you loaded a new translator.
You must call setText on all Labels etc. to have them show translated text. -
@mrjj maybe i understood what you say, but I shoul control the text of the label and then setText inside I think