qt - Is it safe to check if a string equals to a qsTr string in a multi language app - qml -
so if have following property:
property string somestring: qstr("text")
and have following function:
function isequal(tothisstring) { if (somestring === tothisstring) { return true } else return false } }
my question if application has translation other language other english. function still compare "text" or compare translated string?
an example qt:
const qstring english = "hello world"); const qstring spanish = qobject::tr(english); // hola mundo
is equal?
qdebug() << "is equal? " << (english == spanish); qdebug() << "is equal? " << (qobject::tr(english) == spanish);
result:
is equal? false equal? true
you have translate every string, , should same string exactly. it's dificult manage, looks recipe disaster.
you have use alternative data field compare values, avoid strings. example qcombobox:
enum countries {eeuu = 0, spain, france}; qcombobox* combo = new qcombobox; combo->additem(qobject::tr("eeuu"), eeuu); combo->additem(qobject::tr("spain"), spain); combo->additem(qobject::tr("france"), france);
to selected country or compare field in combo model, use currentdata() function or this.
Comments
Post a Comment