From edeed89648822e4229a3d2b6d19b5ee90b01d7ea Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 2 Mar 2021 20:11:40 +0100 Subject: [PATCH] Add support for plural forms in Qt forms --- src/duckstation-qt/CMakeLists.txt | 1 + src/duckstation-qt/audiosettingswidget.cpp | 3 +- src/duckstation-qt/duckstation-qt.vcxproj | 3 ++ .../duckstation-qt.vcxproj.filters | 3 ++ .../emulationsettingswidget.cpp | 3 +- src/duckstation-qt/inputbindingwidgets.cpp | 2 +- src/duckstation-qt/memorycardeditordialog.cpp | 2 +- src/duckstation-qt/qthostinterface.cpp | 4 +- .../translations/duckstation-qt_en.ts | 44 +++++++++++++++++++ .../translations/update-and-edit-english.bat | 10 +++++ 10 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/duckstation-qt/translations/duckstation-qt_en.ts create mode 100644 src/duckstation-qt/translations/update-and-edit-english.bat diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index 0aeb07c97..33434ae31 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -116,6 +116,7 @@ endif() set(TS_FILES translations/duckstation-qt_de.ts + translations/duckstation-qt_en.ts translations/duckstation-qt_es.ts translations/duckstation-qt_fr.ts translations/duckstation-qt_he.ts diff --git a/src/duckstation-qt/audiosettingswidget.cpp b/src/duckstation-qt/audiosettingswidget.cpp index 573936159..da64c3f59 100644 --- a/src/duckstation-qt/audiosettingswidget.cpp +++ b/src/duckstation-qt/audiosettingswidget.cpp @@ -83,8 +83,7 @@ void AudioSettingsWidget::updateBufferingLabel() } const float max_latency = AudioStream::GetMaxLatency(HostInterface::AUDIO_SAMPLE_RATE, actual_buffer_size); - m_ui.bufferingLabel->setText(tr("Maximum Latency: %1 frames (%2ms)") - .arg(actual_buffer_size) + m_ui.bufferingLabel->setText(tr("Maximum Latency: %n frames (%1ms)", "", actual_buffer_size) .arg(static_cast(max_latency) * 1000.0, 0, 'f', 2)); } diff --git a/src/duckstation-qt/duckstation-qt.vcxproj b/src/duckstation-qt/duckstation-qt.vcxproj index 6b20ee4e3..789e008d1 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj +++ b/src/duckstation-qt/duckstation-qt.vcxproj @@ -286,6 +286,9 @@ Document + + + Document Document diff --git a/src/duckstation-qt/duckstation-qt.vcxproj.filters b/src/duckstation-qt/duckstation-qt.vcxproj.filters index fc250c6e7..b374176ce 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj.filters +++ b/src/duckstation-qt/duckstation-qt.vcxproj.filters @@ -180,6 +180,9 @@ translations + + + translations translations diff --git a/src/duckstation-qt/emulationsettingswidget.cpp b/src/duckstation-qt/emulationsettingswidget.cpp index f4087906e..31b3757be 100644 --- a/src/duckstation-qt/emulationsettingswidget.cpp +++ b/src/duckstation-qt/emulationsettingswidget.cpp @@ -121,8 +121,7 @@ void EmulationSettingsWidget::updateRewind() System::CalculateRewindMemoryUsage(frames, &ram_usage, &vram_usage); m_ui.rewindSummary->setText( - tr("Rewind for %1 frames, lasting %2 seconds will require up to %3MB of RAM and %4MB of VRAM.") - .arg(frames) + tr("Rewind for %n frame(s), lasting %1 second(s) will require up to %2MB of RAM and %3MB of VRAM.", "", frames) .arg(duration) .arg(ram_usage / 1048576) .arg(vram_usage / 1048576)); diff --git a/src/duckstation-qt/inputbindingwidgets.cpp b/src/duckstation-qt/inputbindingwidgets.cpp index 98a84470e..f251d7978 100644 --- a/src/duckstation-qt/inputbindingwidgets.cpp +++ b/src/duckstation-qt/inputbindingwidgets.cpp @@ -36,7 +36,7 @@ void InputBindingWidget::updateText() if (m_bindings.empty()) setText(QString()); else if (m_bindings.size() > 1) - setText(tr("%1 bindings").arg(m_bindings.size())); + setText(tr("%n bindings", "", m_bindings.size())); else setText(QString::fromStdString(m_bindings[0])); } diff --git a/src/duckstation-qt/memorycardeditordialog.cpp b/src/duckstation-qt/memorycardeditordialog.cpp index 1db23d233..0877c681a 100644 --- a/src/duckstation-qt/memorycardeditordialog.cpp +++ b/src/duckstation-qt/memorycardeditordialog.cpp @@ -215,7 +215,7 @@ void MemoryCardEditorDialog::updateCardBlocksFree(Card* card) { card->blocks_free = MemoryCardImage::GetFreeBlockCount(card->data); card->blocks_free_label->setText( - tr("%1 blocks free%2").arg(card->blocks_free).arg(card->dirty ? QStringLiteral(" (*)") : QString())); + tr("%n block(s) free%1", "", card->blocks_free).arg(card->dirty ? QStringLiteral(" (*)") : QString())); } void MemoryCardEditorDialog::setCardDirty(Card* card) diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index d1ceeecb0..b9176cf7d 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -64,7 +64,7 @@ const char* QtHostInterface::GetFrontendName() const std::vector> QtHostInterface::getAvailableLanguageList() { - return {{QStringLiteral("English"), QStringLiteral("")}, + return {{QStringLiteral("English"), QStringLiteral("en")}, {QStringLiteral("Deutsch"), QStringLiteral("de")}, {QStringLiteral("Español"), QStringLiteral("es")}, {QStringLiteral("Français"), QStringLiteral("fr")}, @@ -129,7 +129,7 @@ void QtHostInterface::installTranslator() std::string language = GetStringSettingValue("Main", "Language", ""); if (language.empty()) - return; + language = "en"; const QString path = QStringLiteral("%1/translations/duckstation-qt_%3.qm").arg(qApp->applicationDirPath()).arg(language.c_str()); diff --git a/src/duckstation-qt/translations/duckstation-qt_en.ts b/src/duckstation-qt/translations/duckstation-qt_en.ts new file mode 100644 index 000000000..115a55cc3 --- /dev/null +++ b/src/duckstation-qt/translations/duckstation-qt_en.ts @@ -0,0 +1,44 @@ + + + + + AudioSettingsWidget + + Maximum Latency: %n frames (%1ms) + + Maximum Latency: %n frame (%1ms) + Maximum Latency: %n frames (%1ms) + + + + + EmulationSettingsWidget + + Rewind for %n frame(s), lasting %1 second(s) will require up to %2MB of RAM and %3MB of VRAM. + + Rewind for %n frame, lasting %1 second(s) will require up to %2MB of RAM and %3MB of VRAM. + Rewind for %n frames, lasting %1 second(s) will require up to %2MB of RAM and %3MB of VRAM. + + + + + InputBindingWidget + + %n bindings + + %n binding + %n bindings + + + + + MemoryCardEditorDialog + + %n block(s) free%1 + + %n block free%1 + %n blocks free%1 + + + + diff --git a/src/duckstation-qt/translations/update-and-edit-english.bat b/src/duckstation-qt/translations/update-and-edit-english.bat new file mode 100644 index 000000000..d1269d9bd --- /dev/null +++ b/src/duckstation-qt/translations/update-and-edit-english.bat @@ -0,0 +1,10 @@ +@echo off + +set "linguist=..\..\..\dep\msvc\qt\5.15.0\msvc2017_64\bin" +set context=../ ../../core/ ../../frontend-common/ -tr-function-alias translate+=TranslateString -tr-function-alias translate+=TranslateStdString -tr-function-alias QT_TRANSLATE_NOOP+=TRANSLATABLE -pluralonly + +"%linguist%\lupdate.exe" %context% -ts duckstation-qt_en.ts +pause + +cd "%linguist%" +start /B linguist.exe "%~dp0\duckstation-qt_en.ts"