SlideShare une entreprise Scribd logo
1  sur  15
Qt Translations Jussi Pohjolainen Tampere University of Applied Sciences
How to Translate? Every string (visible to user) surrounded by tr() QLabel mytext(tr("Hello World!")); Load a translation (.qm) file at startup Using tr() is good practice, even though you don't have translation files yet.. they can be added later!
tr()? tr() function is a static function defined in QObject QObject::tr(..); tr() returns the translation, if not found, it will return original text // if translation is not found,  // "hello" is returned tr("hello")
Example #include <QtGui> int main(int argc, char *argv[]) {     QApplication a(argc, argv);     QLabel mytext(QObject::tr("Hello World!"));     mytext.show();     return a.exec(); }
Loading Translation Files #include <QtGui> int main(int argc, char *argv[]) {     QApplication a(argc, argv);     QTranslator appTranslator;     // QLocale::system().name() => for example, en_US     appTranslator.load("myapp_" + QLocale::system().name(), ".");     a.installTranslator(&appTranslator);     QLabel mytext(QObject::tr("Hello World!"));     mytext.show();     return a.exec(); }
Translating Applications Run lupdate to extract all tr strings from the application's source code. Translate the application using Qt Linguist Run lrelease to generate binary .qm files that the app can load using QTranslator (done automatically)
lupdate i18n-example.pro lrelease i18n-example.pro  appTranslator.load(...);
1. lupdate Modify .pro file to specify language support TRANSLATIONS = myapp_fi.ts                myapp_fr.ts lupdate will generate these xml-based files lupdate –verbose myapp.pro
tb308pohjus-l:i18n-example pohjus$ cat i18n-example.pro SOURCES += main.cpp TRANSLATIONS = i18n-example_fi.ts i18n-example_en_US.ts tb308pohjus-l:i18n-example pohjus$ lupdate -verbose i18n-example.pro Updating 'i18n-example_en_US.ts'...     Found 1 source text(s) (1 new and 0 already existing) Updating 'i18n-example_fi.ts'...     Found 1 source text(s) (1 new and 0 already existing) tb308pohjus-l:i18n-example pohjus$ ls -al total 1624 drwxr-xr-x  9 pohjus  staff     306  8 Hel 09:38 . drwxr-xr-x  9 pohjus  staff     306  8 Hel 09:16 .. -rw-r--r--  1 pohjus  staff    9484  8 Hel 09:35 Makefile drwxr-xr-x  3 pohjus  staff     102  8 Hel 09:18 i18n-example.app -rw-r--r--  1 pohjus  staff      76  8 Hel 09:38 i18n-example.pro -rw-r--r--  1 pohjus  staff     312  8 Hel 09:38 i18n-example_en_US.ts -rw-r--r--  1 pohjus  staff     312  8 Hel 09:38 i18n-example_fi.ts -rw-r--r--  1 pohjus  staff     371  8 Hel 09:25 main.cpp -rw-r--r--  1 pohjus  staff  799096  8 Hel 09:25 main.o tb308pohjus-l:i18n-example pohjus$
i18n-example_fi.ts <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.0" language="fi_FI"> <context>     <name>QObject</name>     <message>         <location filename="main.cpp" line="12"/>         <source>Hello World!</source>         <translation type="unfinished"></translation>     </message> </context> </TS>
2. Translate: i18n-example_fi.ts <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.0" language="fi_FI"> <context>     <name>QObject</name>     <message>         <location filename="main.cpp" line="12"/>         <source>Hello World!</source>         <translation type="unfinished">Terve maailma!</translation>     </message> </context> </TS>
2. Translate using Qt Linguist
3. Run lrelease Generate .ts files to binary (.qm) either 1) Using Qt Linguist File/Release 2) lrelease lrelease -verbose i18n-example.pro
tb308pohjus-l:i18n-example pohjus$ lrelease -verbose i18n-example.pro Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_en_US.qm'...     Generated 1 translation(s) (0 finished and 1 unfinished) Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_fi.qm'...     Generated 1 translation(s) (0 finished and 1 unfinished)     Generated 1 translation(s) (0 finished and 1 unfinished) tb308pohjus-l:i18n-example pohjus$ rm *.qm tb308pohjus-l:i18n-example pohjus$ lrelease -verbose i18n-example.pro Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_en_US.qm'...     Generated 1 translation(s) (0 finished and 1 unfinished) Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_fi.qm'...     Generated 1 translation(s) (0 finished and 1 unfinished)     Generated 1 translation(s) (0 finished and 1 unfinished) tb308pohjus-l:i18n-example pohjus$ ls -al total 1640 drwxr-xr-x  11 pohjus  staff     374  8 Hel 09:59 . drwxr-xr-x   9 pohjus  staff     306  8 Hel 09:16 .. -rw-r--r--   1 pohjus  staff    9484  8 Hel 09:35 Makefile drwxr-xr-x   3 pohjus  staff     102  8 Hel 09:18 i18n-example.app -rw-r--r--   1 pohjus  staff      76  8 Hel 09:38 i18n-example.pro -rw-r--r--   1 pohjus  staff     127  8 Hel 09:59 i18n-example_en_US.qm -rw-r--r--   1 pohjus  staff     335  8 Hel 09:49 i18n-example_en_US.ts -rw-r--r--   1 pohjus  staff     109  8 Hel 09:59 i18n-example_fi.qm -rw-r--r--   1 pohjus  staff     326  8 Hel 09:49 i18n-example_fi.ts -rw-r--r--   1 pohjus  staff     371  8 Hel 09:25 main.cpp -rw-r--r--   1 pohjus  staff  799096  8 Hel 09:25 main.o
Running #include <QtGui> int main(int argc, char *argv[]) {     QApplication a(argc, argv);     QTranslator appTranslator;     // Path is now ../../../ because of OS X app bundle!     appTranslator.load("i18n-example_fi, "../../../");     a.installTranslator(&appTranslator);     QLabel mytext(QObject::tr("Hello World!"));     mytext.show();     return a.exec(); }

Contenu connexe

Tendances

Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetupsource{d}
 
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...Tsundere Chen
 
Theming Plone with Deliverance
Theming Plone with DeliveranceTheming Plone with Deliverance
Theming Plone with DeliveranceRok Garbas
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Languageguestaa63aa
 
Life without CPAN
Life without CPANLife without CPAN
Life without CPANBob Ernst
 
C 檔案輸入與輸出
C 檔案輸入與輸出C 檔案輸入與輸出
C 檔案輸入與輸出PingLun Liao
 
Scaling FastAGI Applications with Go
Scaling FastAGI Applications with GoScaling FastAGI Applications with Go
Scaling FastAGI Applications with GoDigium
 
C-spirit reborn: why Go was bound to be created
C-spirit reborn: why Go was bound to be createdC-spirit reborn: why Go was bound to be created
C-spirit reborn: why Go was bound to be createdArtem Kovardin
 
PHP-FIG: Past, Present and Future
PHP-FIG: Past, Present and FuturePHP-FIG: Past, Present and Future
PHP-FIG: Past, Present and FuturePhil Sturgeon
 
Golang concurrency design
Golang concurrency designGolang concurrency design
Golang concurrency designHyejong
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMRaveen Perera
 
Repl internals
Repl internalsRepl internals
Repl internalsMongoDB
 
Demystifying the Go Scheduler
Demystifying the Go SchedulerDemystifying the Go Scheduler
Demystifying the Go Schedulermatthewrdale
 
Introduction to the Python Debugger (pdb)
Introduction to the Python Debugger (pdb)Introduction to the Python Debugger (pdb)
Introduction to the Python Debugger (pdb)Raul Cumplido
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XSbyterock
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdbOwen Hsu
 
2009 10-28-peeking-into-pandoras-bochs red-team-pentesting
2009 10-28-peeking-into-pandoras-bochs red-team-pentesting2009 10-28-peeking-into-pandoras-bochs red-team-pentesting
2009 10-28-peeking-into-pandoras-bochs red-team-pentestingSteph Cliche
 

Tendances (20)

Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetup
 
L8 file
L8 fileL8 file
L8 file
 
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
 
Theming Plone with Deliverance
Theming Plone with DeliveranceTheming Plone with Deliverance
Theming Plone with Deliverance
 
C: A Humbling Language
C: A Humbling LanguageC: A Humbling Language
C: A Humbling Language
 
Life without CPAN
Life without CPANLife without CPAN
Life without CPAN
 
C 檔案輸入與輸出
C 檔案輸入與輸出C 檔案輸入與輸出
C 檔案輸入與輸出
 
Scaling FastAGI Applications with Go
Scaling FastAGI Applications with GoScaling FastAGI Applications with Go
Scaling FastAGI Applications with Go
 
C-spirit reborn: why Go was bound to be created
C-spirit reborn: why Go was bound to be createdC-spirit reborn: why Go was bound to be created
C-spirit reborn: why Go was bound to be created
 
PHP-FIG: Past, Present and Future
PHP-FIG: Past, Present and FuturePHP-FIG: Past, Present and Future
PHP-FIG: Past, Present and Future
 
Golang concurrency design
Golang concurrency designGolang concurrency design
Golang concurrency design
 
Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
Repl internals
Repl internalsRepl internals
Repl internals
 
Demystifying the Go Scheduler
Demystifying the Go SchedulerDemystifying the Go Scheduler
Demystifying the Go Scheduler
 
Introduction to the Python Debugger (pdb)
Introduction to the Python Debugger (pdb)Introduction to the Python Debugger (pdb)
Introduction to the Python Debugger (pdb)
 
abu.rpc intro
abu.rpc introabu.rpc intro
abu.rpc intro
 
Embed--Basic PERL XS
Embed--Basic PERL XSEmbed--Basic PERL XS
Embed--Basic PERL XS
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
2009 10-28-peeking-into-pandoras-bochs red-team-pentesting
2009 10-28-peeking-into-pandoras-bochs red-team-pentesting2009 10-28-peeking-into-pandoras-bochs red-team-pentesting
2009 10-28-peeking-into-pandoras-bochs red-team-pentesting
 

En vedette

Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android DevelopmentJussi Pohjolainen
 
Android Security, Signing and Publishing
Android Security, Signing and PublishingAndroid Security, Signing and Publishing
Android Security, Signing and PublishingJussi Pohjolainen
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX ParsingAndroid Http Connection and SAX Parsing
Android Http Connection and SAX ParsingJussi Pohjolainen
 
Android Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionAndroid Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionJussi Pohjolainen
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkJussi Pohjolainen
 
00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.pptJussi Pohjolainen
 
Android Telephony Manager and SMS
Android Telephony Manager and SMSAndroid Telephony Manager and SMS
Android Telephony Manager and SMSJussi Pohjolainen
 
Short Intro to Android Fragments
Short Intro to Android FragmentsShort Intro to Android Fragments
Short Intro to Android FragmentsJussi Pohjolainen
 

En vedette (20)

Building Web Services
Building Web ServicesBuilding Web Services
Building Web Services
 
Responsive Web Site Design
Responsive Web Site DesignResponsive Web Site Design
Responsive Web Site Design
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
C# for Java Developers
C# for Java DevelopersC# for Java Developers
C# for Java Developers
 
Android Security, Signing and Publishing
Android Security, Signing and PublishingAndroid Security, Signing and Publishing
Android Security, Signing and Publishing
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX ParsingAndroid Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
 
Android Essential Tools
Android Essential ToolsAndroid Essential Tools
Android Essential Tools
 
Android Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionAndroid Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth Connection
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
 
00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt
 
Android UI Development
Android UI DevelopmentAndroid UI Development
Android UI Development
 
Android Location and Maps
Android Location and MapsAndroid Location and Maps
Android Location and Maps
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
Android Sensors
Android SensorsAndroid Sensors
Android Sensors
 
Android Multimedia Support
Android Multimedia SupportAndroid Multimedia Support
Android Multimedia Support
 
Android Telephony Manager and SMS
Android Telephony Manager and SMSAndroid Telephony Manager and SMS
Android Telephony Manager and SMS
 
Short Intro to Android Fragments
Short Intro to Android FragmentsShort Intro to Android Fragments
Short Intro to Android Fragments
 
Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 

Similaire à Qt Translations

XML processing with perl
XML processing with perlXML processing with perl
XML processing with perlJoe Jiang
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARStephan Schmidt
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate WorksGoro Fuji
 
Php Training
Php TrainingPhp Training
Php Trainingadfa
 
Jsonsaga
JsonsagaJsonsaga
Jsonsaganohmad
 
The bones of a nice Python script
The bones of a nice Python scriptThe bones of a nice Python script
The bones of a nice Python scriptsaniac
 
The JSON Saga
The JSON SagaThe JSON Saga
The JSON Sagakaven yan
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
 
Python 3000
Python 3000Python 3000
Python 3000Bob Chao
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1Ganesh Samarthyam
 
Douglas Crockford Presentation Jsonsaga
Douglas Crockford Presentation JsonsagaDouglas Crockford Presentation Jsonsaga
Douglas Crockford Presentation JsonsagaAjax Experience 2009
 
TAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS - The Language Data Network
 
Phylogenetics in R
Phylogenetics in RPhylogenetics in R
Phylogenetics in Rschamber
 
PHP Presentation
PHP PresentationPHP Presentation
PHP PresentationNikhil Jain
 

Similaire à Qt Translations (20)

XML processing with perl
XML processing with perlXML processing with perl
XML processing with perl
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEAR
 
How Xslate Works
How Xslate WorksHow Xslate Works
How Xslate Works
 
Odp
OdpOdp
Odp
 
Php Training
Php TrainingPhp Training
Php Training
 
Jsonsaga
JsonsagaJsonsaga
Jsonsaga
 
The bones of a nice Python script
The bones of a nice Python scriptThe bones of a nice Python script
The bones of a nice Python script
 
The JSON Saga
The JSON SagaThe JSON Saga
The JSON Saga
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
 
Python 3000
Python 3000Python 3000
Python 3000
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1
 
Php
PhpPhp
Php
 
John Rowley Notes
John Rowley NotesJohn Rowley Notes
John Rowley Notes
 
Douglas Crockford Presentation Jsonsaga
Douglas Crockford Presentation JsonsagaDouglas Crockford Presentation Jsonsaga
Douglas Crockford Presentation Jsonsaga
 
TAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memories
 
Phylogenetics in R
Phylogenetics in RPhylogenetics in R
Phylogenetics in R
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Easy R
Easy REasy R
Easy R
 

Plus de Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformJussi Pohjolainen
 

Plus de Jussi Pohjolainen (20)

Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 

Dernier

Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 

Dernier (20)

Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 

Qt Translations

  • 1. Qt Translations Jussi Pohjolainen Tampere University of Applied Sciences
  • 2. How to Translate? Every string (visible to user) surrounded by tr() QLabel mytext(tr("Hello World!")); Load a translation (.qm) file at startup Using tr() is good practice, even though you don't have translation files yet.. they can be added later!
  • 3. tr()? tr() function is a static function defined in QObject QObject::tr(..); tr() returns the translation, if not found, it will return original text // if translation is not found, // "hello" is returned tr("hello")
  • 4. Example #include <QtGui> int main(int argc, char *argv[]) { QApplication a(argc, argv); QLabel mytext(QObject::tr("Hello World!")); mytext.show(); return a.exec(); }
  • 5. Loading Translation Files #include <QtGui> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTranslator appTranslator; // QLocale::system().name() => for example, en_US appTranslator.load("myapp_" + QLocale::system().name(), "."); a.installTranslator(&appTranslator); QLabel mytext(QObject::tr("Hello World!")); mytext.show(); return a.exec(); }
  • 6. Translating Applications Run lupdate to extract all tr strings from the application's source code. Translate the application using Qt Linguist Run lrelease to generate binary .qm files that the app can load using QTranslator (done automatically)
  • 7. lupdate i18n-example.pro lrelease i18n-example.pro appTranslator.load(...);
  • 8. 1. lupdate Modify .pro file to specify language support TRANSLATIONS = myapp_fi.ts myapp_fr.ts lupdate will generate these xml-based files lupdate –verbose myapp.pro
  • 9. tb308pohjus-l:i18n-example pohjus$ cat i18n-example.pro SOURCES += main.cpp TRANSLATIONS = i18n-example_fi.ts i18n-example_en_US.ts tb308pohjus-l:i18n-example pohjus$ lupdate -verbose i18n-example.pro Updating 'i18n-example_en_US.ts'... Found 1 source text(s) (1 new and 0 already existing) Updating 'i18n-example_fi.ts'... Found 1 source text(s) (1 new and 0 already existing) tb308pohjus-l:i18n-example pohjus$ ls -al total 1624 drwxr-xr-x 9 pohjus staff 306 8 Hel 09:38 . drwxr-xr-x 9 pohjus staff 306 8 Hel 09:16 .. -rw-r--r-- 1 pohjus staff 9484 8 Hel 09:35 Makefile drwxr-xr-x 3 pohjus staff 102 8 Hel 09:18 i18n-example.app -rw-r--r-- 1 pohjus staff 76 8 Hel 09:38 i18n-example.pro -rw-r--r-- 1 pohjus staff 312 8 Hel 09:38 i18n-example_en_US.ts -rw-r--r-- 1 pohjus staff 312 8 Hel 09:38 i18n-example_fi.ts -rw-r--r-- 1 pohjus staff 371 8 Hel 09:25 main.cpp -rw-r--r-- 1 pohjus staff 799096 8 Hel 09:25 main.o tb308pohjus-l:i18n-example pohjus$
  • 10. i18n-example_fi.ts <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.0" language="fi_FI"> <context> <name>QObject</name> <message> <location filename="main.cpp" line="12"/> <source>Hello World!</source> <translation type="unfinished"></translation> </message> </context> </TS>
  • 11. 2. Translate: i18n-example_fi.ts <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.0" language="fi_FI"> <context> <name>QObject</name> <message> <location filename="main.cpp" line="12"/> <source>Hello World!</source> <translation type="unfinished">Terve maailma!</translation> </message> </context> </TS>
  • 12. 2. Translate using Qt Linguist
  • 13. 3. Run lrelease Generate .ts files to binary (.qm) either 1) Using Qt Linguist File/Release 2) lrelease lrelease -verbose i18n-example.pro
  • 14. tb308pohjus-l:i18n-example pohjus$ lrelease -verbose i18n-example.pro Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_en_US.qm'... Generated 1 translation(s) (0 finished and 1 unfinished) Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_fi.qm'... Generated 1 translation(s) (0 finished and 1 unfinished) Generated 1 translation(s) (0 finished and 1 unfinished) tb308pohjus-l:i18n-example pohjus$ rm *.qm tb308pohjus-l:i18n-example pohjus$ lrelease -verbose i18n-example.pro Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_en_US.qm'... Generated 1 translation(s) (0 finished and 1 unfinished) Updating '/Users/pohjus/Documents/Kurssit/TAMK Mobiiliohjelmointi 2 (Symbian)/qt/examples/i18n-example/i18n-example_fi.qm'... Generated 1 translation(s) (0 finished and 1 unfinished) Generated 1 translation(s) (0 finished and 1 unfinished) tb308pohjus-l:i18n-example pohjus$ ls -al total 1640 drwxr-xr-x 11 pohjus staff 374 8 Hel 09:59 . drwxr-xr-x 9 pohjus staff 306 8 Hel 09:16 .. -rw-r--r-- 1 pohjus staff 9484 8 Hel 09:35 Makefile drwxr-xr-x 3 pohjus staff 102 8 Hel 09:18 i18n-example.app -rw-r--r-- 1 pohjus staff 76 8 Hel 09:38 i18n-example.pro -rw-r--r-- 1 pohjus staff 127 8 Hel 09:59 i18n-example_en_US.qm -rw-r--r-- 1 pohjus staff 335 8 Hel 09:49 i18n-example_en_US.ts -rw-r--r-- 1 pohjus staff 109 8 Hel 09:59 i18n-example_fi.qm -rw-r--r-- 1 pohjus staff 326 8 Hel 09:49 i18n-example_fi.ts -rw-r--r-- 1 pohjus staff 371 8 Hel 09:25 main.cpp -rw-r--r-- 1 pohjus staff 799096 8 Hel 09:25 main.o
  • 15. Running #include <QtGui> int main(int argc, char *argv[]) { QApplication a(argc, argv); QTranslator appTranslator; // Path is now ../../../ because of OS X app bundle! appTranslator.load("i18n-example_fi, "../../../"); a.installTranslator(&appTranslator); QLabel mytext(QObject::tr("Hello World!")); mytext.show(); return a.exec(); }