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

陌路散爱 提交于 2019-12-23 03:10:00

问题


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")
    }
}

来源:https://stackoverflow.com/questions/47183038/qstrid-and-arg-how-to-use-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!