I am coding a program multilanguage, as
http://www.java2s.com/Code/Cpp/Qt/UsingQTranslator.htm
but I don't know how to make data. Could you create a data for me?
thanks
Printable View
I am coding a program multilanguage, as
http://www.java2s.com/Code/Cpp/Qt/UsingQTranslator.htm
but I don't know how to make data. Could you create a data for me?
thanks
I could create "a data" for you but then I would be the one "coding a program multilanguage"
It is all there in the docs: Linguist manual
This is may data, but it is still errors
Code:
<!DOCTYPE TS><TS> <defaultcodec>iso8859-1</defaultcodec> <context> <name>QRadioButton</name> <message> <source>English</source> <translation type="unfinished">Xin </translation> </message> <name>QRadioButton</name> <message> <source>Swedish</source> <translation type="unfinished">Xin2 </translation> </message> </context> </TS>
THanks
Are we supposed to guess what you are doing with that file, what is generating an error message, and what that message is?
Uh huh. So what is the problem then?
I like this problem: Fermat's Last Theorem Simple statement of problem, devilishly complex answer ;)
The pro file:
The program:Code:
TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += . # Input SOURCES += main.cpp TRANSLATIONS += \ simple_example_es.ts \ simple_example_fr.ts
Then:Code:
#include <QtCore> #include <QDebug> int main(int argc, char *argv[]) { QTranslator translator; translator.load("simple_example_es"); // translator.load("simple_example_fr"); app.installTranslator(&translator); return app.exec(); }
Output:Code:
qmake lupdate simple_example.pro linguist simple_example_es.ts // input your translations to Spanish and mark as finished linguist simple_example_fr.ts // ditto for French lrelease simple_example.pro make ./simple_example
Try changing the loaded translation.Code:
"Es muy fácil!"
Apologies to any Spanish speakers if I have mangled your language... that's a Google Translate.
thanks so much.
Could you post data for me to run.?Because i don't see an example about data.
this is an example
http://doc.qt.nokia.com/latest/linguist-trollprint.html
but i can not run it as introduction.
What data do you want? Chris gave you a complete example with all the files.
I alway thanks you so much for good supports.
But I want to run one of examples in installed directory(C:\dev\Qt\2010.05\qt\examples\linguist) to understand about QTranslator.
I run them but none of them can run. I run lupdate, lrelease commands them raise erorrs. Maybe Qt installed incorrectly?
When i runproject and checkCode:
hellotr
ThanksCode:
bool resultLaod=translator.load("hellotr_la"); then the resultLaod=false.
What do you do step by step to build an example?
No I couldn't. What good would it be if I send you the same files you already have? Just answer my previous question.
thanks
I opened it by QtCreator then run
This is my project
Code:
/**************************************************************************** ** ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** You may use this file under the terms of the BSD license as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor ** the names of its contributors may be used to endorse or promote ** products derived from this software without specific prior written ** permission. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** $QT_END_LICENSE$ ** ****************************************************************************/ #include <QApplication> #include <QPushButton> #include <QDebug> //! [0] #include <QTranslator> //! [0] //! [1] //! [2] int main(int argc, char *argv[]) //! [1] //! [3] //! [4] { //! [3] //! [5] QTranslator translator; //! [5] //! [6] bool x=translator.load("hellotr_la"); if(x==false) qDebug()<<"Load fialed"; //! [6] //! [7] app.installTranslator(&translator); //! [4] //! [7] //! [8] //! [8] hello.resize(100, 30); hello.show(); return app.exec(); } //! [2]
Code:
!symbian: error(Only include this file for Symbian platforms) RSS_RULES ="group_name=\"QtExamples\";" vendorinfo = \ "; Localised Vendor name" \ "%{\"Nokia, Qt\"}" \ " " \ "; Unique Vendor name" \ ":\"Nokia, Qt\"" \ " " examples_deployment.pkg_prerules += vendorinfo DEPLOYMENT += examples_deployment isEmpty(ICON):ICON = $$QT_SOURCE_TREE/src/s60installs/qt.svg
Code:
#! [0] SOURCES = main.cpp #! [0] #! [1] TRANSLATIONS = hellotr_la.ts #! [1] # install target.path = $$[QT_INSTALL_EXAMPLES]/linguist/hellotr sources.files = $$SOURCES *.pro sources.path = $$[QT_INSTALL_EXAMPLES]/linguist/hellotr INSTALLS += target sources symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
Code:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.0" language="en_GB"> <context> <name>QPushButton</name> <message> <source>Hello world!</source> <translation>Xin chao</translation> </message> </context> </TS>
Where did you put these files?
Copy them elsewhere, run qmake and make.
Dead easy... I really cannot see the problem
Code:
$ cd /tmp $ cp -r /usr/share/qt4/examples/linguist/hellotr . $ cd hellotr $ qmake $ make $ lupdate hellotr.pro ... Updating 'hellotr_la.ts'... Found 1 source text(s) (1 new and 0 already existing) $ linguist hellotr_la.ts # translate the string $ lrelease hellotr.pro ... Updating '/tmp/hellotr/hellotr_la.qm'... Generated 1 translation(s) (1 finished and 0 unfinished) $ ./hellotr