Originally Posted by
wysota
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
{
delete t;
}
translators.clear();
QDir dir
(translationsPath
());
else
delete qt;
{
//qDebug("entry : %s", qPrintable(s));
if ( !s.endsWith(suff) )
continue;
//qDebug("translator found!");
if ( t->load(dir.filePath(s)) )
{
#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);
}
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::TranslationsPath)) )
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);
}
To copy to clipboard, switch view to plain text mode
Originally Posted by
wysota
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?
Bookmarks