What do you mean by that you want to dynamically change it? What do you mean by "dynamically" and what is "it"?
What do you mean by that you want to dynamically change it? What do you mean by "dynamically" and what is "it"?
Dynamically translate is changing the language of your application "on-the-fly" (without reset your application).
You can read about it in the qt programming guide.
So anyone know how to implement what i meant?
I know what is dynamic translation but seeing just one line of your code it is not possible to deduce what you want. If you want to change the language you need to retranslate all user-visible strings (like what retranslateUi() method of forms generated by uic does). Without knowing where your single line of code fits in it is not possible to suggest a solution.
Maybe you need this: dynamic translation
Oh!
So thats exactly what i'm asking! how should i write the retranslate function to fit my needs.
I know how to do it when i have the string in the tr() function (like tr("string")), but i don't know how am i suppose to retranslate when i have the string in that manner of QT_TR_NOOP array.
Hi again!
Well, i did exactly what you said, but it still doesn't work and i'm starting to get crazy.
This is what i do:
1. I have a global class, which have this strings array initialize:
Qt Code:
greeting_strings[0] = QT_TR_NOOP("France"); greeting_strings[1] = QT_TR_NOOP("Energy"); greeting_strings[2] = QT_TR_NOOP("Caps"); greeting_strings[3] = QT_TR_NOOP("Switch"); };To copy to clipboard, switch view to plain text mode
2.Now, in order to install the translator when necessary, i send from the main the QApplication pointer, and later install in it the translator:
Qt Code:
app->installTranslator(NewTranlator);To copy to clipboard, switch view to plain text mode
3. Then, I change the texts of the visible icons to the new language like this:
Qt Code:
for (i=0; i<Number_Of_Boxes; i++) boxes[i].Text = tr(generalStructObject->greeting_strings[i]);To copy to clipboard, switch view to plain text mode
The new word is exactly the same! it doesn't change at all!
What is the problem here? do i miss something?
What do you apart setting these Text properties? Do you map them to some widget or anything? What's the type of "boxes"?
the type of boxes are:
Qt Code:To copy to clipboard, switch view to plain text mode
and are placed in a widget called menu_screen:
Qt Code:
... menu_box *boxes; ...To copy to clipboard, switch view to plain text mode
Last edited by liran ritkop; 30th March 2011 at 10:25.
How are they "placed" there? Are you assuming that:
will make the label's text change from "x" to "y"? It won't.Qt Code:
QLabel lab; lab.setText(str); str = "y";To copy to clipboard, switch view to plain text mode
They are placed there as i wrote before (look at paragraph 3).
the tr() function return the same string in the default language.
Ok!
After a long digging in this issue, I succeeded to change the language "on the fly"!
The problem was here:
When you declare about QT_TR_NOOP or tr() functions, the "lupdate" tool build a ts file, where each such declaration is placed under it's object label. In my case:
Qt Code:
<context> <name>GeneralStruct</name> <message> <source>METER</source> <translation type="unfinished">translatedMeter</translation> </message> ...To copy to clipboard, switch view to plain text mode
I dont know why Qt developed it that way, i hope you can tell me the reason.
Anyway, I invoke the tr() function in another object (called menu_screen) as you can see from my previous comments.
It didn't translate the strings, till i changed the ts file manually, and turned it that way:
This time, it worked!Qt Code:
<name>menu_screen</name> <message> <source>METER</source> <translation type="unfinished">translatedMeter</translation> </message>To copy to clipboard, switch view to plain text mode
Thanks for your responses, and i hope it will help others who facing this problem.
Bookmarks