mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-09 20:50:43 +00:00
In translations.cpp, add new language names, revise loading of qm files into translator, add debug messages, all qm files are now together in translations directory
This commit is contained in:
parent
9527aadb66
commit
acd7b04b7b
@ -46,8 +46,9 @@ void initTranslations()
|
|||||||
// Add any languages with special character set needs to this list
|
// Add any languages with special character set needs to this list
|
||||||
langNames["zh"] = "\xe6\xbc\xa2\xe8\xaa\x9e\xe7\xb9\x81\xe9\xab\x94\xe5\xad\x97";
|
langNames["zh"] = "\xe6\xbc\xa2\xe8\xaa\x9e\xe7\xb9\x81\xe9\xab\x94\xe5\xad\x97";
|
||||||
langNames["es"] = "Español";
|
langNames["es"] = "Español";
|
||||||
|
langNames["es_MX"] = "Español (Mexico)";
|
||||||
langNames["bg"] = "\xd0\xb1\xd1\x8a\xd0\xbb\xd0\xb3\xd0\xb0\xd1\x80\xd1\x81\xd0\xba\xd0\xb8";
|
langNames["bg"] = "\xd0\xb1\xd1\x8a\xd0\xbb\xd0\xb3\xd0\xb0\xd1\x80\xd1\x81\xd0\xba\xd0\xb8";
|
||||||
// langNames["fr"] = "Français"; // this just confuses Qt
|
langNames["fr"] = "Français"; // this just confuses Qt (WHY? trying enabling it -- gts 8/18/2019)
|
||||||
langNames["en_UK"] = "English (UK)";
|
langNames["en_UK"] = "English (UK)";
|
||||||
langNames["nl"] = "Nederlands";
|
langNames["nl"] = "Nederlands";
|
||||||
langNames["pt_BR"] = "Portugues (BR)";
|
langNames["pt_BR"] = "Portugues (BR)";
|
||||||
@ -71,8 +72,11 @@ void initTranslations()
|
|||||||
dir.setFilter(QDir::Files);
|
dir.setFilter(QDir::Files);
|
||||||
dir.setNameFilters(QStringList("*.qm"));
|
dir.setNameFilters(QStringList("*.qm"));
|
||||||
|
|
||||||
|
qDebug() << "number of built-in *.qm files" << dir.count();
|
||||||
QFileInfoList list = dir.entryInfoList();
|
QFileInfoList list = dir.entryInfoList();
|
||||||
for (const auto & fi : list) {
|
for (const auto & fi : list) {
|
||||||
|
if (fi.fileName().indexOf("oscar_qt", 0) == 0) // skip files named QT... These are supplemental files for QT strings
|
||||||
|
continue;
|
||||||
QString code = fi.fileName().section('.', 1, 1);
|
QString code = fi.fileName().section('.', 1, 1);
|
||||||
|
|
||||||
if (!langNames.contains(code)) langNames[code]=fi.fileName().section('.', 0, 0);
|
if (!langNames.contains(code)) langNames[code]=fi.fileName().section('.', 0, 0);
|
||||||
@ -83,19 +87,24 @@ void initTranslations()
|
|||||||
langPaths[code] = inbuiltPath;
|
langPaths[code] = inbuiltPath;
|
||||||
}
|
}
|
||||||
std::sort(inbuilt.begin(), inbuilt.end());
|
std::sort(inbuilt.begin(), inbuilt.end());
|
||||||
qDebug() << "Inbuilt Translations:" << QString(inbuilt.join(", ")).toLocal8Bit().data();;
|
qDebug() << "Inbuilt Translations:" << QString(inbuilt.join(", ")).toLocal8Bit().data();
|
||||||
|
|
||||||
QString externalPath = appResourcePath() +"/Translations";
|
QString externalPath = appResourcePath() +"/Translations";
|
||||||
dir.setPath(externalPath);
|
dir.setPath(externalPath);
|
||||||
|
dir.setFilter(QDir::Files);
|
||||||
|
dir.setNameFilters(QStringList("*.qm"));
|
||||||
list = dir.entryInfoList();
|
list = dir.entryInfoList();
|
||||||
|
qDebug() << "number of external *.qm files" << dir.count();
|
||||||
// Add default language (English)
|
|
||||||
|
|
||||||
// Scan through available translations, and add them to the list
|
// Scan through available translations, and add them to the list
|
||||||
QStringList extratrans, replaced;
|
QStringList extratrans, replaced;
|
||||||
|
int numExternal = 0;
|
||||||
for (const auto & fi : list) {
|
for (const auto & fi : list) {
|
||||||
|
if (fi.fileName().indexOf("oscar_qt", 0) == 0) // skip files named QT... These are supplemental files for QT strings
|
||||||
|
continue;
|
||||||
QString code = fi.fileName().section('.', 1, 1);
|
QString code = fi.fileName().section('.', 1, 1);
|
||||||
|
|
||||||
|
numExternal++;
|
||||||
if(!langNames.contains(code)) langNames[code] = fi.fileName().section('.', 0, 0);
|
if(!langNames.contains(code)) langNames[code] = fi.fileName().section('.', 0, 0);
|
||||||
if (inbuilt.contains(code)) replaced.push_back(code); else extratrans.push_back(code);
|
if (inbuilt.contains(code)) replaced.push_back(code); else extratrans.push_back(code);
|
||||||
|
|
||||||
@ -104,6 +113,7 @@ void initTranslations()
|
|||||||
}
|
}
|
||||||
std::sort(replaced.begin(), replaced.end());
|
std::sort(replaced.begin(), replaced.end());
|
||||||
std::sort(extratrans.begin(), extratrans.end());
|
std::sort(extratrans.begin(), extratrans.end());
|
||||||
|
qDebug() << "Number of external translations is" << numExternal;
|
||||||
if (replaced.size()>0) qDebug() << "Overridden Tranlsations:" << QString(replaced.join(", ")).toLocal8Bit().data();
|
if (replaced.size()>0) qDebug() << "Overridden Tranlsations:" << QString(replaced.join(", ")).toLocal8Bit().data();
|
||||||
if (extratrans.size()>0) qDebug() << "Extra Translations:" << QString(extratrans.join(", ")).toLocal8Bit().data();
|
if (extratrans.size()>0) qDebug() << "Extra Translations:" << QString(extratrans.join(", ")).toLocal8Bit().data();
|
||||||
|
|
||||||
@ -173,15 +183,18 @@ void initTranslations()
|
|||||||
|
|
||||||
if (language.compare(DefaultLanguage) != 0) {
|
if (language.compare(DefaultLanguage) != 0) {
|
||||||
// Install QT translation files
|
// Install QT translation files
|
||||||
QString qtLangPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
||||||
QString qtLang = language.left(2);
|
QString qtLang = language.left(2);
|
||||||
if ( qtLang.compare("zh") == 0 )
|
if ( qtLang.compare("zh") == 0 ) // QT-supplied translation files have both _CN and _TW, but are the same for our purposes
|
||||||
qtLang.append("_CN");
|
qtLang.append("_CN");
|
||||||
QString qtLangFile = "qt_" + qtLang + ".qm";
|
QString qtLangFile = "qt_" + qtLang + ".qm";
|
||||||
qDebug() << "Loading" << langname << "QT translation" << qtLangFile.toLocal8Bit().data() << "from" << qtLangPath.toLocal8Bit().data();
|
if (!QFileInfo(qtLangFile).exists()) {
|
||||||
|
qtLang = qtLang.left(2); // Undo QT suffix for zh; we don't use that for our file
|
||||||
|
qtLangFile = "Oscar_qt_" + qtLang + ".qm";
|
||||||
|
}
|
||||||
|
qDebug() << "Loading" << langname << "QT translation" << qtLangFile.toLocal8Bit().data() << "from" << langpath.toLocal8Bit().data();
|
||||||
QTranslator * qtranslator = new QTranslator();
|
QTranslator * qtranslator = new QTranslator();
|
||||||
|
|
||||||
if (!qtLangFile.isEmpty() && !qtranslator->load(qtLangFile, qtLangPath)) {
|
if (!qtLangFile.isEmpty() && !qtranslator->load(qtLangFile, langpath)) {
|
||||||
qWarning() << "Could not load QT translation" << qtLangFile << "reverting to english :(";
|
qWarning() << "Could not load QT translation" << qtLangFile << "reverting to english :(";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user