Daniel Below
Daniel Below

Reputation: 118

Qt translations with arguments

I've run into a problem using Qt to dynamically translate an application. All strings shown in the UI are wrapped in tr() calls, so I can see them in the QtLinguist.

My problem now is this: Let's say I have a string with a placeholder %1: tr("Foo %1");

I understand that I can fill the placeholder like this

tr("Foo %1").arg(myPlaceholder); or tr("Foo %1").arg(tr(myPlaceholder));

but there are no seperate calls to the possible values of myPlaceholder, so they don't show up in QtLinguist.

What would be the best way to add the possible placeholder values to my translation files? I've read in another thread that it would be wrong to manually edit the *.ts files.

Upvotes: 1

Views: 1088

Answers (1)

The argument to tr() must be a string literal. The value of the tr-expression is a QString - that's why you can use its arg method etc.

Upvotes: 2

Related Questions