From 6657745daa531c6234cfeff63c3e95749b06ff0c Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sun, 18 Dec 2011 15:19:07 +0100 Subject: [PATCH] Improved language file initialization code. --- etc/Translation/Blank.ts | 12 +++++----- etc/Translation/LameXP_PL.ts | 12 +++++----- src/Config.h | 2 +- src/Thread_Initialization.cpp | 44 +++++++++++++++++++++-------------- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index 8541b7a9..cc63e4a1 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -2289,32 +2289,32 @@ - + Meta Information - + The following meta information have been extracted from the original file. - + Meta Information: %1 - + Load Artwork - + Artwork Error - + Sorry, failed to load artwork from selected file! diff --git a/etc/Translation/LameXP_PL.ts b/etc/Translation/LameXP_PL.ts index d18c885e..c0ab6001 100644 --- a/etc/Translation/LameXP_PL.ts +++ b/etc/Translation/LameXP_PL.ts @@ -2289,32 +2289,32 @@ Usuń okładkę - + Meta Information Metadane - + The following meta information have been extracted from the original file. Następujące metadane zostały wyodrębnione z oryginalnego pliku. - + Meta Information: %1 - + Load Artwork Załaduj okładkę - + Artwork Error Błąd pliku okładki - + Sorry, failed to load artwork from selected file! Załadowanie pliku okładki zakończone niepowodzeniem! diff --git a/src/Config.h b/src/Config.h index 08a4ba06..dd1d3cb8 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 10 -#define VER_LAMEXP_BUILD 813 +#define VER_LAMEXP_BUILD 816 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index bb6bf148..9f2a0e17 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -32,6 +32,7 @@ #include #include #include +#include /* helper macros */ #define PRINT_CPU_TYPE(X) case X: qDebug("Selected CPU is: " #X) @@ -245,33 +246,42 @@ void InitializationThread::initTranslations(void) while(!qmFiles.isEmpty()) { QString langId, langName; - unsigned int systemId = 0; QString qmFile = qmFiles.takeFirst(); + unsigned int systemId = 0; QRegExp langIdExp("LameXP_(\\w\\w)\\.qm", Qt::CaseInsensitive); if(langIdExp.indexIn(qmFile) >= 0) { langId = langIdExp.cap(1).toLower(); - } - - QResource langRes = (QString(":/localization/%1.txt").arg(qmFile)); - if(langRes.isValid() && langRes.size() > 0) - { - QStringList langInfo = QString::fromUtf8(reinterpret_cast(langRes.data()), langRes.size()).simplified().split(",", QString::SkipEmptyParts); - if(langInfo.count() == 2) + QResource langRes = QResource(QString(":/localization/%1.txt").arg(qmFile)); + if(langRes.isValid() && langRes.size() > 0) { - systemId = langInfo.at(0).toUInt(); - langName = langInfo.at(1); + QByteArray data = QByteArray::fromRawData(reinterpret_cast(langRes.data()), langRes.size()); + QTextStream stream(&data, QIODevice::ReadOnly); + stream.setAutoDetectUnicode(false); stream.setCodec("UTF-8"); + while(!stream.atEnd()) + { + QStringList langInfo = stream.readLine().simplified().split(",", QString::SkipEmptyParts); + if(langInfo.count() == 2) + { + systemId = langInfo.at(0).trimmed().toUInt(); + langName = langInfo.at(1).trimmed(); + break; + } + } } } - - if(lamexp_translation_register(langId, qmFile, langName, systemId)) + + if(!(langId.isEmpty() || langName.isEmpty() || systemId == 0)) { - qDebug("Registering translation: %s = %s (%u)", qmFile.toUtf8().constData(), langName.toUtf8().constData(), systemId); - } - else - { - qWarning("Failed to register: %s", qmFile.toLatin1().constData()); + if(lamexp_translation_register(langId, qmFile, langName, systemId)) + { + qDebug("Registering translation: %s = %s (%u)", qmFile.toUtf8().constData(), langName.toUtf8().constData(), systemId); + } + else + { + qWarning("Failed to register: %s", qmFile.toLatin1().constData()); + } } }