November 14, 2011

durfejs durfejs
Lab Rat
4 posts

translations in QML files

 

Hi there,

I have problems with translations (using function qsTr()) in my QML file which is loadad as component into anther QML file.
I created standard “Hello world!” project in QtQuick. The MainPage.qml file created by Qt Creator is being loaded into main.qml file as a component for initialPage. Here are the codes:

main.qml:

  1. import QtQuick 1.1
  2. import com.nokia.symbian 1.1
  3.  
  4. PageStackWindow {
  5.     id: window
  6.     initialPage: MainPage {tools: toolBarLayout}
  7.     showStatusBar: true
  8.     showToolBar: true
  9.  
  10.     ToolBarLayout {
  11.         id: toolBarLayout
  12.         ToolButton {
  13.             flat: true
  14.             text: qsTr("Back")
  15.             iconSource: "toolbar-back"
  16.             onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop()
  17.         }
  18.     }
  19. }

MainPage.qml:

  1. import QtQuick 1.1
  2. import com.nokia.symbian 1.1
  3.  
  4. Page {
  5.     id: mainPage
  6.     Text {
  7.         anchors.centerIn: parent
  8.         text: qsTr('Hello world!')
  9.         color: platformStyle.colorNormalLight
  10.         font.pixelSize: 20
  11.     }
  12. }

Problem is that “Back” in main.qml is translated correctly (after all necessary steps with lupdate and linquist resp. lrelease) but “Hello world!” from MainPage.qml does not translate at all.

NB of course I performed manual loading of QTranslator and istallation in main.cpp file like this:

  1.     QTranslator* translator = new QTranslator;
  2.  
  3.     qDebug()<<"Translating: "<<translator->load(QString("qml/International/inter_sk"));
  4.  
  5.     app->installTranslator(translator);

Like this:
QML translation problem

So I think when loading component from QML file then the translation is not working.

Any guesses why? experiences????
Thanks a lot

UPDATE:
Translation files need to be prepared case sensitively:

lupdate mainpage.qml -ts inter_sk.ts is wrong
lupdate MainPage.qml -ts inter_sk.ts is correct

 Signature 

We can get richer only with progress

0 replies

 
  ‹‹ test Quick3D app outside dev environement      [solved] ReferenceError: Can’t find variable... on MeeGo Harmattan ››

You must log in to post a reply. Not a member yet? Register here!