Translation is not working through JavaScript function
-
I am doing language translation in qml, i have three text objects, if i directly assign the values and do the translations it works fine, but if i change the values of a text fields through JavaScript function then apply the translations it is not working.
-
It could be issue with property binding. Binding has to re-evaluate for the translation to work. Do you have sample program for us to check ?
-
Hi,
You should show your function and how you are doing it in qml so someone can help..
You can use QtLinguist for translations. -
@dheerendra This is my sample code, Once the button is clicked i am calling JavaScript function, i am changing all the text values after that i am translating, the translation is not working
Column { spacing: 10 anchors.centerIn: parent Text { id : t1 text :cm.buttonText + trans.lang } Text { id : t2 text :cm.buttonT1 + trans.lang } Text { id: t3 text :cm.buttonT2 + trans.lang } Button{ text : "German" onClicked: { MyScript.changeValue(); trans.selectLanguage("de"); } } }
-
trans - Is it object coming from C++ side ? If yes, is this method is really called ?Can you confirm ? Can you show me your setLanguage method ?
-
I have the following code in the function. this function is called i verified it with debugs.
if(language == "de") { qDebug() << Q_FUNC_INFO << " Germany Language " << endl; translator->load(""); translator->load("://de.qm"); QCoreApplication::instance()->installTranslator(translator); engine->retranslate(); }
-
This method looks correct from translation perspective. I'm assuming that appropriate translations exist in de.qm files. what changes are you doing in changeValue() method ? Can you show the function ?
-
@dheerendra said in Translation is not working through JavaScript function:
changeValue()
Whatever i am changing in changeValue() function is not getting translated.function changeValue() { t2.text = cm.buttonT4 t3.text = cm.buttonT5 t1.text = cm.buttonT3 }
-
hmm. You are doing the property bindings in javascript methods. This will not work. Can you try the following ?
t2.text = Qt.binding(function() { return cm.buttonT4;})
-
After replacing this like above its working now... Thank you @dheerendra
-
Cool. If you want to property binding trigger, you should call Qt.binding explicitly. Since issue is resolved you can move the case to "SOLVED" state.