1

I have an qt quick application that works with a web service

behind code for qml file here I want get list of book

void BookManager::findBook(QString bookName){    

    QNetworkReply* reply=getRequest("api/Book/Find/"+bookName);
    connect(reply,SIGNAL(finished()),this,SLOT(getListFinished()));
 }

and here assume that user is not authenticated and must login first and from server i send "First Login and then try again" .. message to display in client side to user

Here i get the message or book list

 void BookManager::getListFinished(){
    QNetworkReply* reply=convertToReply(sender());
    if(reply->error()==QNetworkReply::NoError)
    {
       //Display books
    }
    else
    {
        readReplyMessage(reply);//Here I get the message and disply it to user
    }
 }

I want to know how should i create multi-language application?

qStr and ... is for time that strings are used in UI .

but when i make request from web service ,it will return a string message in English .If user select Persian language how can I translate this string?

mohsen
  • 1,763
  • 3
  • 17
  • 55

1 Answers1

0

qsTr() or qsTranslate() are commonly used in QML text. However it doesn't happen like magic! The strings are entered in the translation file as a key entry. With the help of qt linguist tool you have to create a translation for the string in some language, say (en_EN). Based on your current system locale the string will be replaced by your translation text.

Use is easy.

Text {
    id: txt;
    text: qsTr("First Login and then try again");
}

To get some motivation read: https://wiki.qt.io/How_to_create_a_multi_language_application

Manual: http://doc.qt.io/qt-5/qtlinguist-index.html

dDebug
  • 57
  • 1
  • 1
  • 8
  • Tanks for your answer.but i want to know how should i create multilanguage when i use web service,your answer is when i use string in user interface .but when i make request from web servce for example it will return a string message .that is in english.but if use select persian language how can i translate this string? – mohsen Mar 15 '18 at 13:25
  • I would recommend you to elaborate the problem in the description properly. What I understand you have a client application, and a server application. The server send the client Strings in English and the client will translate it to some other language. If this is the case, do it in you C++ code using remote procedure calls. The servers calls a function in your client and client can take the message and return tr(message). But in this case also tr() uses the same translation engine and the same process, starting from creating a translation file with Qt Linguist – dDebug Mar 15 '18 at 13:35
  • @mohsen, if you know in advance all the messages that might be replied back from the server, then you can just clone them in your client side and create the translation. – Mohammad Kanan Mar 15 '18 at 13:41