Crossing the border with Qt: the i18n system
-
Upload
develer-srl -
Category
Technology
-
view
440 -
download
0
description
Transcript of Crossing the border with Qt: the i18n system
![Page 2: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/2.jpg)
What is i18n about?
Embracing a specific national environment:
Language Line break behaviour Writing direction Conventions
...without hampering development
![Page 3: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/3.jpg)
(True) Horror Story
We're in 2002, and a big Italian company wants to localize their CAD program in Spanish.
If only it wasn't for...
![Page 4: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/4.jpg)
(True) Horror Story
Strings were initially hardcoded in Italian, English was retrofitted at some point...
...with lots of if/else statements First try: add another else branch for each
string in code (...) Second try: tool to produce multiple
codebases – one for each language (...) AFAIK still unfinished two years later
![Page 5: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/5.jpg)
All we need is a good workflow
Developers produce i18n-ready code With no codebase pollution
Translators translate strings Iteratively (code and strings can change!) No technical knowledge needed
The framework does the rest
![Page 6: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/6.jpg)
6
Developers' step 1
QObject::tr() Parse-time: marks strings Run-time: translates strings
Not everything is a QObject... QCoreApplication::translate() QT_TR_NOOP
![Page 7: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/7.jpg)
7
Developers' step 2
Use QString for all user visible text QString are Unicode strings transparent →
processing of strings (reg exp, split etc) Programmer space strings can still be
QByteArrays or char *
![Page 8: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/8.jpg)
8
Developers' step 3
Use QString::arg() for dynamic text QString::arg() allows easy argument
reordering
void FileCopier::showProgress(int done, int total, const QString ¤tFile){ label.setText(tr("%1 of %2 files copied.\nCopying: %3") .arg(done) .arg(total) .arg(currentFile));}
![Page 9: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/9.jpg)
9
Some glue
Add a TRANSLATIONS entry to .pro Run lupdate to extract a .ts file Send .ts file to translators Run lrelease to produce translated binary
files Set up a QTranslator QCoreApplication::installTranslator()
![Page 10: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/10.jpg)
10
Translators' (only) step
Open .ts file with Linguist Fill the missing translations There is no step 3
Developer: “...hey that's not fair!”
![Page 11: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/11.jpg)
11
Some case studies
Nearing the 2.0 release: Parse again with lupdate Fill only the missing translations
Wanting to add a language Add that language to TRANSLATIONS Run lupdate, translate the new .ts file, lrelease This time it's a fairy tale!
Update language on the fly installTranslator sends a changeEvent
![Page 12: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/12.jpg)
12
Workflow demo
![Page 13: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/13.jpg)
13
Gotchas
::tr assumes latin-1 What about Designer files?
![Page 14: Crossing the border with Qt: the i18n system](https://reader034.fdocuments.in/reader034/viewer/2022052505/555ad870d8b42a024a8b4dac/html5/thumbnails/14.jpg)
THANKS !THANKS !
Contacts
Mail: [email protected]
Phone: +39-055-3984627
Fax: +39 178 6003614
http://www.develer.com
Develer S.r.l.Via Mugellese 1/A
50013 Campi BisenzioFirenze - Italy