简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM