This forum has been archived. All content is frozen. Please use KDE Discuss instead.

ki18n vs tr

Tags: None
(comma "," separated)
kalle1950
Registered Member
Posts
16
Karma
0

ki18n vs tr

Fri Jan 08, 2010 12:41 pm
Hi,

I was looking for a documentation for the ki18n function. I thought it belongs to KLocale, but I cannot find it there. I wonder when and how to use ki18n and when tr. Don't they do the same?

Code: Select all
QLabel *NameLabel = new QLabel(ki18n("Name:"));


doesn't work, but

Code: Select all
QLabel *NameLabel = new QLabel(tr("Name:"));


does.

The first gives a compile error

Code: Select all
uiComponent.cpp:53: error: no matching function for call to ‘QLabel::QLabel(KLocalizedString)’
/usr/include/QtGui/qlabel.h:158: note: candidates are: QLabel::QLabel(const QLabel&)
/usr/include/QtGui/qlabel.h:71: note:                 QLabel::QLabel(const QString&, QWidget*, Qt::WindowFlags)
/usr/include/QtGui/qlabel.h:70: note:                 QLabel::QLabel(QWidget*, Qt::WindowFlags)


Some include missing? KLocale is included, anything else I have to obey?

What do I have to do to use it and when shall I use it compared to tr?

Thanks.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: ki18n vs tr  Topic is solved

Sat Jan 09, 2010 12:38 am
ki18n() is for use before you have instantiated KApplication. It delays the translation until KApplication has been constructed.

You should not be using tr() in normal KDE applications, but i18n() instead.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

Re: ki18n vs tr

Tue Jan 12, 2010 11:43 am
The most useful variant is i18nc() because it allows to specify a translation context.

This context will be visible to the translators and help them to distinguish between ambiguous terms, e.g. whether "title" refers to a position or academic title of a person or the title of a book.

KDE's developer wiki techbase.kde.org has a couple of tutorials and information pages on the topic of internationalization

http://techbase.kde.org/Development/Tut ... calization

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]