AFAIK, there is no way. The translate
function works in the following way: it iterates over all the translators that are available for the application, and tries to translate the source text with each of them. If it succeeds, it immediately breaks out of the loop and returns the translated text. If the aforementioned loop has finished, but the translation has not been found, it returns the source text in a form of a QString:
QString QCoreApplication::translate(const char *context, const char *sourceText,
const char *disambiguation, Encoding encoding, int n)
{
QString result;
if (!sourceText)
return result;
if (self && !self->d_func()->translators.isEmpty()) {
QList<QTranslator*>::ConstIterator it;
QTranslator *translationFile;
for (it = self->d_func()->translators.constBegin(); it != self->d_func()->translators.constEnd(); ++it) {
translationFile = *it;
result = translationFile->translate(context, sourceText, disambiguation, n);
if (!result.isEmpty())
break;
}
}
if (result.isEmpty()) {
#ifdef QT_NO_TEXTCODEC
Q_UNUSED(encoding)
#else
if (encoding == UnicodeUTF8)
result = QString::fromUtf8(sourceText);
else if (QTextCodec::codecForTr() != 0)
result = QTextCodec::codecForTr()->toUnicode(sourceText);
else
#endif
result = QString::fromLatin1(sourceText);
}
replacePercentN(&result, n);
return result;
}
If you really need to be able to know if the translation could be found, you would have to subclass QTranslator
class and override it's translate()
function (since the translate()
in QCoreApplication
is non-virtual).