PDA

View Full Version : Fall back to untranslated mode



fullmetalcoder
28th June 2007, 12:11
My application is able to perform run-time translation but I'm facing a weird issue : after switching between various available languages I want to have english (default language) again. I thus created proper files using prefix _untranslated instead of, for instance, _fr or _de. These are empty .qm files. I load remove old translators load new files and install them but the texts everywhere in the app remain in the previous language... as if translators were remanent and continued to work even after having been removed (and deleted...). I'm just wondering if it's a Qt bug. Will I be forced to create an english translation (of english texts... :rolleyes: )?

wysota
28th June 2007, 12:26
I'm just wondering if it's a Qt bug.
No, I don't think so.

Will I be forced to create an english translation (of english texts... :rolleyes: )?

It's advised to have an english catalog file so I'm wondering why you haven't done that yet. The texts inside can be untranslated, but the files can't be empty.

fullmetalcoder
28th June 2007, 12:50
It's advised to have an english catalog file so I'm wondering why you haven't done that yet. The texts inside can be untranslated, but the files can't be empty.
My understanding was that, without any translator loaded, the text wouldn't be translated and will rename as they are inside the code (thus in english in my case). That's why I didn't filled an english ts file (isn't it tedious to fill about 300 translations by hand when you don't have anything to translate actually...).

wysota
28th June 2007, 12:55
My understanding was that, without any translator loaded, the text wouldn't be translated and will rename as they are inside the code (thus in english in my case).
Yes, but you have to apply the new translator, otherwise strings already translated won't be "untranslated".


That's why I didn't filled an english ts file (isn't it tedious to fill about 300 translations by hand when you don't have anything to translate actually...).

As I mentioned you don't have to "translate" those messages, it's only important that you apply a valid qm file containing message ids.

fullmetalcoder
28th June 2007, 13:10
As I mentioned you don't have to "translate" those messages, it's only important that you apply a valid qm file containing message ids.
But that's exactly what I'm doing... Maybe the fact that I "lrealease" a .ts file which holds only "unfinished" translations make it empty and prevents the "untranslation"... If so how do I get a valid qm file from an ts file with only empty translations?

wysota
28th June 2007, 13:26
But do you install the translator? Could you show your code? Which Qt version do you use? I used english translations files successfully without problems...

BTW. You can try loading the .ts file instead of .qm. And what does installTranslator report?

Edit: Sorry, I meant QTranslator::load. installTranslator returns void.

fullmetalcoder
28th June 2007, 13:31
But do you install the translator? Could you show your code? Which Qt version do you use?
I'm using the prebuilt Qt 4.3.0 package that comes with Frugalware.
Here comes the code :


void EdyukTranslator::setLanguage(const QString& lang)
{
#ifdef _EDYUK_DEBUG_
qDebug("setting language to : %s", qPrintable(lang));
#endif

foreach ( QTranslator *t, translators )
{
QCoreApplication::removeTranslator(t);
delete t;
}

translators.clear();

QString suff = lang + ".qm";
QDir dir(translationsPath());

QTranslator *qt = new QTranslator(this);

if ( qt->load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsP ath)) )
QCoreApplication::installTranslator(qt);
else
delete qt;

foreach ( QString s, dir.entryList(QDir::Files | QDir::Readable) )
{
//qDebug("entry : %s", qPrintable(s));

if ( !s.endsWith(suff) )
continue;

//qDebug("translator found!");

QTranslator *t = new QTranslator(this);

if ( t->load(dir.filePath(s)) )
{
QCoreApplication::installTranslator(t);
#ifdef _EDYUK_DEBUG_
qDebug("successfuly loaded data from %s", qPrintable(dir.filePath(s)));
#endif
} else {
delete t;
#ifdef _EDYUK_DEBUG_
qDebug("failed to load data from %s", qPrintable(dir.filePath(s)));
#endif
}
}

pMenu->setTitle(tr("Language"));

sLang = lang;
setValue("last", sLang);

emit languageChanged(sLang);

QEvent e((QEvent::Type)Edyuk::RunTimeTranslation);
QCoreApplication::sendEvent(qApp, &e);
}


BTW. You can try loading the .ts file instead of .qm. And what does installTranslator report?
Do you mean that I would not have to generate a .qm from the .ts but just load the .ts as is? Are you sure this would work?

wysota
28th June 2007, 21:38
Here comes the code :
So which part is responsible for loading the "untranslated" catalog? From what I see you try to install every possible translator at once.


Are you sure this would work?

Yes.

Your code is a bit strange... Try this:


int main(int argc, char **argv){
QApplication app(argc, argv);
QTranslator translator; // search in current directory
translator.load("test_en"); // ignore the suffix
app.installTranslator(&translator);
QPushButton b;
b.setText(QObject::tr("Testing"));
b.show();
return app.exec();
}

fullmetalcoder
29th June 2007, 15:09
So which part is responsible for loading the "untranslated" catalog? From what I see you try to install every possible translator at once.
This code is in charge of switcing the current language. It removes all previous translators and installs new one. There's no specific code in charge of "untranslation" but specific .ts and .qm files instead...



Your code is a bit strange... Try this:


int main(int argc, char **argv){
QApplication app(argc, argv);
QTranslator translator; // search in current directory
translator.load("test_en"); // ignore the suffix
app.installTranslator(&translator);
QPushButton b;
b.setText(QObject::tr("Testing"));
b.show();
return app.exec();
}
I'm not trying to translate... it works well already ;) The wrong thing is that despite removing previous translators and installing new stub ones I can't seem to fallback to untranslated mode...:(

wysota
1st July 2007, 21:34
That's why I ask you to try with my code... there is no such thing as "untranslated" mode. There always is a translation (of course if you use tr() calls), even if you don't provide any. Try loading an "empty" translation catalog (note my "en" suffix) and see if it works properly (especially if "load" returns true).

fullmetalcoder
2nd July 2007, 09:33
There always is a translation (of course if you use tr() calls)
The point is, and I can confirm this happens even with a translation loaded, a string that IS NOT handled by current translators WILL BE handled by old translators EVEN IF they have been REMOVED and DESTROYED... This is merely what I call a bug... Does anyone know a way to prevent such thing to happen?