Matteo
Matteo

Reputation: 1219

qsTrId and .arg(): how to use it?

for a project I'm forced to use qsTrId for i18n and I'm now in need of arguments in the string.

Sadly, the documentation for the command does not help about.

I've this sample code:

Text {
    id: someId
    //% "%1 my translatable suffix!"
    text: qsTrId("my_translatable_id_with_argument").arg("This is")
}

It will output the following error:

QString::arg: Argument missing: my_translatable_id_with_argument, This is

The documentation for arg say it need to work with strings, so I fear that the my_translatable_id_with_argument defined for qsTrId is used as base string for .arg and since there is no %1 the error is generated.

Anyone has a tip for this situation?

Thanks in advance!

EDIT:

I've tried the following with no success:

Text {
    id: someId
    //% "%1 my translatable suffix!"
    text: qsTrId("my_translatable_id_with_argument")

    Component.onCompleted: {
        text = text.arg("This is")
    }
}

Upvotes: 2

Views: 1710

Answers (1)

Gongotar
Gongotar

Reputation: 43

According to the QtTranslation documentation this is possible as follows:

//% "%1 my translatable suffix!"
QString text = qtTrId("qtn_foo_bar", var);

Upvotes: 1

Related Questions