Merge pull request #5 from lioncash/translate

General: Make UI strings translation-aware
This commit is contained in:
Phillip Stephens 2019-08-30 16:18:33 -07:00 committed by GitHub
commit 98b821a20a
3 changed files with 90 additions and 80 deletions

View File

@ -84,7 +84,7 @@ MainWindow::MainWindow(QWidget* parent)
m_ui->processOutput->setFont(mFont); m_ui->processOutput->setFont(mFont);
m_cursor = QTextCursor(m_ui->processOutput->document()); m_cursor = QTextCursor(m_ui->processOutput->document());
m_updateURDEButton = new QPushButton(QStringLiteral("Update URDE"), m_ui->centralwidget); m_updateURDEButton = new QPushButton(tr("Update URDE"), m_ui->centralwidget);
m_ui->gridLayout->addWidget(m_updateURDEButton, 2, 3, 1, 1); m_ui->gridLayout->addWidget(m_updateURDEButton, 2, 3, 1, 1);
m_updateURDEButton->hide(); m_updateURDEButton->hide();
QPalette pal = m_updateURDEButton->palette(); QPalette pal = m_updateURDEButton->palette();
@ -115,12 +115,15 @@ MainWindow::~MainWindow() {
} }
void MainWindow::onExtract() { void MainWindow::onExtract() {
if (m_path.isEmpty()) if (m_path.isEmpty()) {
return; return;
QString imgPath = QFileDialog::getOpenFileName(this, QStringLiteral("Extract Image"), m_path, }
QStringLiteral("Images (*.iso *.wbfs *.gcm)"));
if (imgPath.isEmpty()) const QString imgPath =
QFileDialog::getOpenFileName(this, tr("Extract Image"), m_path, tr("Images (*.iso *.wbfs *.gcm)"));
if (imgPath.isEmpty()) {
return; return;
}
m_ui->processOutput->clear(); m_ui->processOutput->clear();
KillProcessTree(m_heclProc); KillProcessTree(m_heclProc);
@ -140,7 +143,7 @@ void MainWindow::onExtract() {
m_ui->heclTabs->setCurrentIndex(0); m_ui->heclTabs->setCurrentIndex(0);
disableOperations(); disableOperations();
m_ui->extractBtn->setText(QStringLiteral("Cancel")); m_ui->extractBtn->setText(tr("Cancel"));
m_ui->extractBtn->setEnabled(true); m_ui->extractBtn->setEnabled(true);
disconnect(m_ui->extractBtn, &QPushButton::clicked, nullptr, nullptr); disconnect(m_ui->extractBtn, &QPushButton::clicked, nullptr, nullptr);
connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate); connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate);
@ -174,7 +177,7 @@ void MainWindow::onPackage() {
m_ui->heclTabs->setCurrentIndex(0); m_ui->heclTabs->setCurrentIndex(0);
disableOperations(); disableOperations();
m_ui->packageBtn->setText(QStringLiteral("Cancel")); m_ui->packageBtn->setText(tr("Cancel"));
m_ui->packageBtn->setEnabled(true); m_ui->packageBtn->setEnabled(true);
disconnect(m_ui->packageBtn, &QPushButton::clicked, nullptr, nullptr); disconnect(m_ui->packageBtn, &QPushButton::clicked, nullptr, nullptr);
connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate); connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate);
@ -266,21 +269,23 @@ void MainWindow::onUpdateURDEPressed() {
} }
void MainWindow::onBinaryDownloaded(QuaZip& file) { void MainWindow::onBinaryDownloaded(QuaZip& file) {
bool err = !ExtractZip::extractDir(file, m_path); const bool err = !ExtractZip::extractDir(file, m_path);
if (err) if (err) {
m_ui->downloadErrorLabel->setText(QStringLiteral("Error extracting zip")); m_ui->downloadErrorLabel->setText(tr("Error extracting zip"));
else } else {
m_ui->downloadErrorLabel->setText(QStringLiteral("Download successful"), true); m_ui->downloadErrorLabel->setText(tr("Download successful"), true);
}
m_ui->downloadButton->setEnabled(true); m_ui->downloadButton->setEnabled(true);
checkDownloadedBinary(); checkDownloadedBinary();
if (!err && m_ui->extractBtn->isEnabled()) if (!err && m_ui->extractBtn->isEnabled()) {
m_ui->downloadErrorLabel->setText(QStringLiteral("Download successful - Press 'Extract' to continue."), true); m_ui->downloadErrorLabel->setText(tr("Download successful - Press 'Extract' to continue."), true);
if (!err && !m_ui->sysReqTable->isBlenderVersionOk()) }
m_ui->downloadErrorLabel->setText( if (!err && !m_ui->sysReqTable->isBlenderVersionOk()) {
QStringLiteral("Blender 2.78+ must be installed. Please download via Steam or blender.org.")); m_ui->downloadErrorLabel->setText(tr("Blender 2.80+ must be installed. Please download via Steam or blender.org."));
}
} }
void MainWindow::onBinaryFailed() { void MainWindow::onBinaryFailed() {
@ -310,9 +315,9 @@ void MainWindow::enableOperations() {
if (m_heclPath.isEmpty()) if (m_heclPath.isEmpty())
return; return;
m_ui->extractBtn->setText(QStringLiteral("Extract")); m_ui->extractBtn->setText(tr("Extract"));
m_ui->packageBtn->setText(QStringLiteral("Package")); m_ui->packageBtn->setText(tr("Package"));
m_ui->launchBtn->setText(QStringLiteral("Launch")); m_ui->launchBtn->setText(tr("Launch"));
m_ui->extractBtn->setEnabled(true); m_ui->extractBtn->setEnabled(true);
if (QFile::exists(m_path + QStringLiteral("/MP1/!original_ids.yaml"))) { if (QFile::exists(m_path + QStringLiteral("/MP1/!original_ids.yaml"))) {
@ -321,14 +326,15 @@ void MainWindow::enableOperations() {
m_ui->launchBtn->setEnabled(true); m_ui->launchBtn->setEnabled(true);
} }
if (!m_ui->sysReqTable->isBlenderVersionOk()) if (!m_ui->sysReqTable->isBlenderVersionOk()) {
insertContinueNote(tr("Blender 2.78+ must be installed. Please download via Steam or blender.org.")); insertContinueNote(tr("Blender 2.80+ must be installed. Please download via Steam or blender.org."));
else if (m_ui->launchBtn->isEnabled()) } else if (m_ui->launchBtn->isEnabled()) {
insertContinueNote(tr("Package complete - Press 'Launch' to start URDE.")); insertContinueNote(tr("Package complete - Press 'Launch' to start URDE."));
else if (m_ui->packageBtn->isEnabled()) } else if (m_ui->packageBtn->isEnabled()) {
insertContinueNote(tr("Extract complete - Press 'Package' to continue.")); insertContinueNote(tr("Extract complete - Press 'Package' to continue."));
else if (m_ui->extractBtn->isEnabled()) } else if (m_ui->extractBtn->isEnabled()) {
insertContinueNote(tr("Press 'Extract' to begin.")); insertContinueNote(tr("Press 'Extract' to begin."));
}
} }
bool MainWindow::isPackageComplete() const { bool MainWindow::isPackageComplete() const {
@ -376,7 +382,7 @@ bool MainWindow::checkDownloadedBinary() {
if (m_path.isEmpty()) { if (m_path.isEmpty()) {
m_ui->heclTabs->setCurrentIndex(1); m_ui->heclTabs->setCurrentIndex(1);
m_ui->downloadErrorLabel->setText(QStringLiteral("Set working directory to continue."), true); m_ui->downloadErrorLabel->setText(tr("Set working directory to continue."), true);
enableOperations(); enableOperations();
return false; return false;
} }
@ -408,7 +414,7 @@ bool MainWindow::checkDownloadedBinary() {
m_updateURDEButton->show(); m_updateURDEButton->show();
} }
} else { } else {
m_ui->currentBinaryLabel->setText(QStringLiteral("unknown -- re-download recommended")); m_ui->currentBinaryLabel->setText(tr("unknown -- re-download recommended"));
} }
m_urdePath = urdePath; m_urdePath = urdePath;
@ -417,9 +423,9 @@ bool MainWindow::checkDownloadedBinary() {
enableOperations(); enableOperations();
return true; return true;
} else { } else {
m_ui->currentBinaryLabel->setText(QStringLiteral("none")); m_ui->currentBinaryLabel->setText(tr("none"));
m_ui->heclTabs->setCurrentIndex(1); m_ui->heclTabs->setCurrentIndex(1);
m_ui->downloadErrorLabel->setText(QStringLiteral("Press 'Download' to fetch latest URDE binary."), true); m_ui->downloadErrorLabel->setText(tr("Press 'Download' to fetch latest URDE binary."), true);
enableOperations(); enableOperations();
} }
@ -427,21 +433,25 @@ bool MainWindow::checkDownloadedBinary() {
} }
void MainWindow::setPath(const QString& path) { void MainWindow::setPath(const QString& path) {
QFileInfo finfo(path); const QFileInfo finfo(path);
QString usePath; QString usePath;
if (!path.isEmpty()) if (!path.isEmpty()) {
usePath = finfo.absoluteFilePath(); usePath = finfo.absoluteFilePath();
}
if (!usePath.isEmpty() && !finfo.exists()) { if (!usePath.isEmpty() && !finfo.exists()) {
if (QMessageBox::question(this, QStringLiteral("Make Directory"), if (QMessageBox::question(this, tr("Make Directory"), tr("%1 does not exist. Create it now?").arg(usePath)) ==
QStringLiteral("%1 does not exist. Create it now?").arg(usePath)) == QMessageBox::Yes) QMessageBox::Yes) {
QDir().mkpath(usePath); QDir().mkpath(usePath);
else } else {
usePath = QString(); usePath = QString();
}
} }
if (!usePath.isEmpty() && !finfo.isDir()) { if (!usePath.isEmpty() && !finfo.isDir()) {
QMessageBox::warning(this, QStringLiteral("Directory Error"), QStringLiteral("%1 is not a directory").arg(usePath), QMessageBox::warning(this, tr("Directory Error"), tr("%1 is not a directory").arg(usePath), QMessageBox::Ok,
QMessageBox::Ok, QMessageBox::NoButton); QMessageBox::NoButton);
usePath = QString(); usePath = QString();
} }
@ -453,9 +463,9 @@ void MainWindow::setPath(const QString& path) {
m_ui->downloadButton->setToolTip(QString()); m_ui->downloadButton->setToolTip(QString());
m_ui->downloadButton->setEnabled(m_ui->binaryComboBox->isEnabled()); m_ui->downloadButton->setEnabled(m_ui->binaryComboBox->isEnabled());
} else { } else {
m_ui->downloadButton->setToolTip(QStringLiteral("Working directory must be set")); m_ui->downloadButton->setToolTip(tr("Working directory must be set"));
m_ui->downloadButton->setEnabled(false); m_ui->downloadButton->setEnabled(false);
m_ui->currentBinaryLabel->setText(QStringLiteral("none")); m_ui->currentBinaryLabel->setText(tr("none"));
} }
m_ui->sysReqTable->updateFreeDiskSpace(m_path); m_ui->sysReqTable->updateFreeDiskSpace(m_path);

View File

@ -23,21 +23,21 @@
#elif _WIN32 #elif _WIN32
static QString GetWindowsVersionString() { static QString GetWindowsVersionString() {
if (IsWindows10OrGreater()) if (IsWindows10OrGreater())
return QStringLiteral("Windows 10"); return QObject::tr("Windows 10");
else if (IsWindows8Point1OrGreater()) else if (IsWindows8Point1OrGreater())
return QStringLiteral("Windows 8.1"); return QObject::tr("Windows 8.1");
else if (IsWindows8OrGreater()) else if (IsWindows8OrGreater())
return QStringLiteral("Windows 8"); return QObject::tr("Windows 8");
else if (IsWindows7SP1OrGreater()) else if (IsWindows7SP1OrGreater())
return QStringLiteral("Windows 7 SP1"); return QObject::tr("Windows 7 SP1");
else if (IsWindows7OrGreater()) else if (IsWindows7OrGreater())
return QStringLiteral("Windows 7"); return QObject::tr("Windows 7");
else if (IsWindowsVistaOrGreater()) else if (IsWindowsVistaOrGreater())
return QStringLiteral("Windows Vista"); return QObject::tr("Windows Vista");
else if (IsWindowsXPOrGreater()) else if (IsWindowsXPOrGreater())
return QStringLiteral("Windows XP"); return QObject::tr("Windows XP");
else else
return QStringLiteral("Windows Old And Won't Work"); return QObject::tr("Windows Old And Won't Work");
} }
#endif #endif
@ -47,7 +47,7 @@ SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent
if (file.open(QFile::ReadOnly)) { if (file.open(QFile::ReadOnly)) {
const QString str(QString::fromUtf8(file.readAll())); const QString str(QString::fromUtf8(file.readAll()));
m_cpuSpeed = str.toInt() / 1000; m_cpuSpeed = str.toInt() / 1000;
m_cpuSpeedStr.sprintf("%g GHz", m_cpuSpeed / 1000.0); m_cpuSpeedStr = tr("%1 GHz").arg(m_cpuSpeed / 1000.0);
} }
#elif defined(__APPLE__) #elif defined(__APPLE__)
QProcess spProc; QProcess spProc;
@ -77,7 +77,7 @@ SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent
n = n.nextSiblingElement(QStringLiteral("string")); n = n.nextSiblingElement(QStringLiteral("string"));
const double speed = n.text().split(QLatin1Char{' '}).front().toDouble(); const double speed = n.text().split(QLatin1Char{' '}).front().toDouble();
m_cpuSpeed = uint64_t(speed * 1000.0); m_cpuSpeed = uint64_t(speed * 1000.0);
m_cpuSpeedStr.sprintf("%g GHz", speed); m_cpuSpeedStr = tr("%1 GHz").arg(speed);
} }
} }
#elif _WIN32 #elif _WIN32
@ -88,7 +88,7 @@ SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent
DWORD size = sizeof(MHz); DWORD size = sizeof(MHz);
if (RegQueryValueEx(hkey, _SYS_STR("~MHz"), nullptr, nullptr, (LPBYTE)&MHz, &size) == ERROR_SUCCESS) { if (RegQueryValueEx(hkey, _SYS_STR("~MHz"), nullptr, nullptr, (LPBYTE)&MHz, &size) == ERROR_SUCCESS) {
m_cpuSpeed = uint64_t(MHz); m_cpuSpeed = uint64_t(MHz);
m_cpuSpeedStr.sprintf("%1.1f GHz", MHz / 1000.f); m_cpuSpeedStr = tr("%1 GHz").arg(MHz / 1000.f, 1, 'f', 1);
} }
} }
RegCloseKey(hkey); RegCloseKey(hkey);
@ -100,7 +100,7 @@ SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent
zeus::getCpuInfo(0x16, regs); zeus::getCpuInfo(0x16, regs);
m_cpuSpeed = uint64_t(regs[0]); m_cpuSpeed = uint64_t(regs[0]);
} }
m_cpuSpeedStr.sprintf("%g GHz", m_cpuSpeed / 1000.f); m_cpuSpeedStr = tr("%1 GHz").arg(m_cpuSpeed / 1000.f);
#endif #endif
#if _WIN32 #if _WIN32
ULONGLONG memSize; ULONGLONG memSize;
@ -109,35 +109,35 @@ SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent
#else #else
m_memorySize = uint64_t(sysconf(_SC_PHYS_PAGES)) * sysconf(_SC_PAGESIZE); m_memorySize = uint64_t(sysconf(_SC_PHYS_PAGES)) * sysconf(_SC_PAGESIZE);
#endif #endif
m_memorySizeStr.sprintf("%g GiB", m_memorySize / 1024.f / 1024.f / 1024.f); m_memorySizeStr = tr("%1 GiB").arg(m_memorySize / 1024.f / 1024.f / 1024.f);
#ifdef __APPLE__ #ifdef __APPLE__
GetMacOSSystemVersion(m_macosMajor, m_macosMinor, m_macosPatch); GetMacOSSystemVersion(m_macosMajor, m_macosMinor, m_macosPatch);
if (m_macosPatch == 0) if (m_macosPatch == 0) {
m_osVersion.sprintf("macOS %d.%d", m_macosMajor, m_macosMinor); m_osVersion = tr("macOS %1.%2").arg(m_macosMajor, m_macosMinor);
else } else {
m_osVersion.sprintf("macOS %d.%d.%d", m_macosMajor, m_macosMinor, m_macosPatch); m_osVersion = tr("macOS %1.%2.%3").arg(m_macosMajor, m_macosMinor, m_macosPatch);
}
#elif _WIN32 #elif _WIN32
m_win7SP1OrGreater = IsWindows7SP1OrGreater(); m_win7SP1OrGreater = IsWindows7SP1OrGreater();
m_osVersion = GetWindowsVersionString(); m_osVersion = GetWindowsVersionString();
#elif __linux__ #elif __linux__
m_osVersion = QStringLiteral("Linux"); m_osVersion = tr("Linux");
#endif #endif
hecl::blender::FindBlender(m_blendMajor, m_blendMinor); hecl::blender::FindBlender(m_blendMajor, m_blendMinor);
if (m_blendMajor) { if (m_blendMajor) {
m_blendVersionStr = m_blendVersionStr = tr("Blender %1.%2").arg(QString::number(m_blendMajor), QString::number(m_blendMinor));
QStringLiteral("Blender ") + QString::number(m_blendMajor) + QLatin1Char{'.'} + QString::number(m_blendMinor);
} else { } else {
m_blendVersionStr = QStringLiteral("Not Found"); m_blendVersionStr = tr("Not Found");
} }
} }
void SysReqTableModel::updateFreeDiskSpace(const QString& path) { void SysReqTableModel::updateFreeDiskSpace(const QString& path) {
if (path.isEmpty()) { if (path.isEmpty()) {
m_freeDiskSpace = 0; m_freeDiskSpace = 0;
m_freeDiskSpaceStr = QStringLiteral("<Set Working Directory>"); m_freeDiskSpaceStr = tr("<Set Working Directory>");
} else { } else {
m_freeDiskSpace = QStorageInfo(path).bytesFree(); m_freeDiskSpace = QStorageInfo(path).bytesFree();
m_freeDiskSpaceStr.sprintf("%1.1f GB", m_freeDiskSpace / 1000.f / 1000.f / 1000.f); m_freeDiskSpaceStr = tr("%1 GB").arg(m_freeDiskSpace / 1000.f / 1000.f / 1000.f, 1, 'f', 1);
} }
emit dataChanged(index(3, 0), index(3, 0)); emit dataChanged(index(3, 0), index(3, 0));
} }
@ -178,28 +178,28 @@ QVariant SysReqTableModel::data(const QModelIndex& index, int role) const {
switch (index.row()) { switch (index.row()) {
case 0: case 0:
#if ZEUS_ARCH_X86 || ZEUS_ARCH_X86_64 #if ZEUS_ARCH_X86 || ZEUS_ARCH_X86_64
return QStringLiteral("x86_64"); return tr("x86_64");
#else #else
return {}; return {};
#endif #endif
case 1: case 1:
return QStringLiteral("1.5 GHz"); return tr("1.5 GHz");
case 2: case 2:
return QStringLiteral("3 GiB"); return tr("3 GiB");
case 3: case 3:
return QStringLiteral("5 GB (MP1)"); return tr("5 GB (MP1)");
case 4: case 4:
#ifdef __APPLE__ #ifdef __APPLE__
return QStringLiteral("macOS 10.9"); return tr("macOS 10.9");
#elif defined(_WIN32) #elif defined(_WIN32)
return QStringLiteral("Windows 7 SP1"); return tr("Windows 7 SP1");
#elif defined(__linux__) #elif defined(__linux__)
return QStringLiteral("Linux"); return tr("Linux");
#else #else
return {}; return {};
#endif #endif
case 5: case 5:
return QStringLiteral("Blender 2.78"); return tr("Blender 2.80");
} }
} else if (index.column() == 1) { } else if (index.column() == 1) {
/* Your System */ /* Your System */
@ -235,27 +235,27 @@ QVariant SysReqTableModel::headerData(int section, Qt::Orientation orientation,
switch (section) { switch (section) {
case 0: case 0:
default: default:
return QStringLiteral("Recommended"); return tr("Recommended");
case 1: case 1:
return QStringLiteral("Your System"); return tr("Your System");
} }
} else { } else {
switch (section) { switch (section) {
case 0: case 0:
default: default:
return QStringLiteral("Architecture"); return tr("Architecture");
case 1: case 1:
return QStringLiteral("CPU Speed"); return tr("CPU Speed");
case 2: case 2:
return QStringLiteral("Memory"); return tr("Memory");
case 3: case 3:
return QStringLiteral("Disk Space"); return tr("Disk Space");
case 4: case 4:
return QStringLiteral("OS"); return tr("OS");
case 5: case 5:
return QStringLiteral("Blender"); return tr("Blender");
case 6: case 6:
return QStringLiteral("Vector ISA"); return tr("Vector ISA");
} }
} }
} }

View File

@ -12,7 +12,7 @@ class SysReqTableModel : public QAbstractTableModel {
uint64_t m_memorySize = 0; uint64_t m_memorySize = 0;
QString m_memorySizeStr; QString m_memorySizeStr;
qint64 m_freeDiskSpace = 0; qint64 m_freeDiskSpace = 0;
QString m_freeDiskSpaceStr = QStringLiteral("<Set Working Directory>"); QString m_freeDiskSpaceStr = tr("<Set Working Directory>");
#if __APPLE__ #if __APPLE__
int m_macosMajor = 0; int m_macosMajor = 0;
int m_macosMinor = 0; int m_macosMinor = 0;
@ -31,7 +31,7 @@ public:
int columnCount(const QModelIndex& parent = QModelIndex()) const; int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
bool isBlenderVersionOk() const { return m_blendMajor > 2 || (m_blendMajor == 2 && m_blendMinor >= 78); } bool isBlenderVersionOk() const { return m_blendMajor > 2 || (m_blendMajor == 2 && m_blendMinor >= 80); }
void updateFreeDiskSpace(const QString& path); void updateFreeDiskSpace(const QString& path);
}; };