SlideShare ist ein Scribd-Unternehmen logo
1 von 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(); }

Weitere ähnliche Inhalte

Was ist angesagt?

Theming Plone with Deliverance
Theming Plone with DeliveranceTheming Plone with Deliverance
Theming Plone with Deliverance
Rok Garbas
 
Repl internals
Repl internalsRepl internals
Repl internals
MongoDB
 
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
Steph Cliche
 

Was ist angesagt? (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
 

Andere mochten auch

Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 
Android Security, Signing and Publishing
Android Security, Signing and PublishingAndroid Security, Signing and Publishing
Android Security, Signing and Publishing
Jussi Pohjolainen
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX ParsingAndroid Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
Jussi 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 Connection
Jussi Pohjolainen
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt
Jussi Pohjolainen
 
Android Telephony Manager and SMS
Android Telephony Manager and SMSAndroid Telephony Manager and SMS
Android Telephony Manager and SMS
Jussi Pohjolainen
 
Short Intro to Android Fragments
Short Intro to Android FragmentsShort Intro to Android Fragments
Short Intro to Android Fragments
Jussi Pohjolainen
 

Andere mochten auch (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
 

Ähnlich wie Qt Translations

XML processing with perl
XML processing with perlXML processing with perl
XML processing with perl
Joe Jiang
 
Jsonsaga
JsonsagaJsonsaga
Jsonsaga
nohmad
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1
Ganesh Samarthyam
 
Douglas Crockford Presentation Jsonsaga
Douglas Crockford Presentation JsonsagaDouglas Crockford Presentation Jsonsaga
Douglas Crockford Presentation Jsonsaga
Ajax 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 memories
TAUS - The Language Data Network
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
Nikhil Jain
 

Ähnlich wie 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
 

Mehr von Jussi Pohjolainen

Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi 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 Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi 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 Platform
Jussi Pohjolainen
 

Mehr von 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
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Kürzlich hochgeladen (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).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(); }