Darkgaze
Darkgaze

Reputation: 2573

How to translate with Qt Linguist with label arguments (%1)

I got a line for a Qlabel like this:

QString(tr("Are you sure you want to delete the scene called %1 ?")).arg(variable);

Some people told me you can't translate that. They told me to append different strings with the parameters and the text...

But what about a phrase using various parameters? How does the translator know which order if it is appended in that order?.

Has no sense for me. There must be a way!.

Upvotes: 3

Views: 3895

Answers (1)

cloose
cloose

Reputation: 956

Should should drop the QString(...) part, since tr() already returns a QString. Otherwise I don't see a problem with the translation of the following code:

tr("Are you sure you want to delete the scene called %1 ?").arg(variable);

In the Use QString::arg() for Dynamic Text part of the Qt documentation you can find more information.

Upvotes: 5

Related Questions