Host: Re-introduce plural translation support

This commit is contained in:
Stenzek
2024-05-13 01:46:45 +10:00
parent a2abcc9bb3
commit f3aec0c965
13 changed files with 230 additions and 150 deletions

View File

@ -173,6 +173,11 @@ s32 Host::Internal::GetTranslatedStringImpl(std::string_view context, std::strin
return static_cast<s32>(translated_size);
}
std::string Host::TranslatePluralToString(const char* context, const char* msg, const char* disambiguation, int count)
{
return qApp->translate(context, msg, disambiguation, count).toStdString();
}
std::span<const std::pair<const char*, const char*>> Host::GetAvailableLanguageList()
{
static constexpr const std::pair<const char*, const char*> languages[] = {{"English", "en"},

View File

@ -66,7 +66,7 @@ REM A good .ts file has been passed
ECHO Updating %filename%...
ECHO.
SET "linguist=..\..\..\dep\msvc\deps-x64\bin"
SET "context=.././ ../../core/ ../../util/ -tr-function-alias QT_TRANSLATE_NOOP+=TRANSLATE,QT_TRANSLATE_NOOP+=TRANSLATE_SV,QT_TRANSLATE_NOOP+=TRANSLATE_STR,QT_TRANSLATE_NOOP+=TRANSLATE_FS,QT_TRANSLATE_N_NOOP3+=TRANSLATE_FMT,QT_TRANSLATE_NOOP+=TRANSLATE_NOOP"
SET "context=.././ ../../core/ ../../util/ -tr-function-alias QT_TRANSLATE_NOOP+=TRANSLATE,QT_TRANSLATE_NOOP+=TRANSLATE_SV,QT_TRANSLATE_NOOP+=TRANSLATE_STR,QT_TRANSLATE_NOOP+=TRANSLATE_FS,QT_TRANSLATE_N_NOOP3+=TRANSLATE_FMT,QT_TRANSLATE_NOOP+=TRANSLATE_NOOP,translate+=TRANSLATE_PLURAL_STR,translate+=TRANSLATE_PLURAL_FS"
"%linguist%\lupdate.exe" %context% -ts %filename%
ECHO.

View File

@ -7,17 +7,46 @@
<location filename="../achievementsettingswidget.cpp" line="164"/>
<location filename="../achievementsettingswidget.cpp" line="171"/>
<source>%n seconds</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
<translation>
<numerusform>%n second</numerusform>
<numerusform>%n seconds</numerusform>
</translation>
</message>
</context>
<context>
<name>EmuThread</name>
<name>Achievements</name>
<message numerus="yes">
<location filename="../../core/achievements.cpp" line="1022"/>
<source>You have unlocked {} of %n achievements</source>
<comment>Achievement popup</comment>
<translation>
<numerusform>You have unlocked {} of %n achievements</numerusform>
<numerusform>You have unlocked {} of %n achievements</numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="../../core/achievements.cpp" line="1025"/>
<source>and earned {} of %n points</source>
<comment>Achievement popup</comment>
<translation>
<numerusform>and earned {} of %n points</numerusform>
<numerusform>and earned {} of %n points</numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="../../core/achievements.cpp" line="1100"/>
<source>%n achievements</source>
<comment>Mastery popup</comment>
<translation>
<numerusform>%n achievement</numerusform>
<numerusform>%n achievements</numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="../../core/achievements.cpp" line="1102"/>
<source>%n points</source>
<translation type="vanished">
<comment>Mastery popup</comment>
<translation>
<numerusform>%n point</numerusform>
<numerusform>%n points</numerusform>
</translation>
@ -26,7 +55,7 @@
<context>
<name>EmulationSettingsWidget</name>
<message numerus="yes">
<location filename="../emulationsettingswidget.cpp" line="196"/>
<location filename="../emulationsettingswidget.cpp" line="242"/>
<source>Rewind for %n frame(s), lasting %1 second(s) will require up to %2MB of RAM and %3MB of VRAM.</source>
<translation>
<numerusform>Rewind for %n frame, lasting %1 second(s) will require up to %2MB of RAM and %3MB of VRAM.</numerusform>
@ -34,6 +63,17 @@
</translation>
</message>
</context>
<context>
<name>GameList</name>
<message numerus="yes">
<location filename="../../core/game_list.cpp" line="1070"/>
<source>%n minutes</source>
<translation>
<numerusform>%n minute</numerusform>
<numerusform>%n minutes</numerusform>
</translation>
</message>
</context>
<context>
<name>InputBindingWidget</name>
<message numerus="yes">
@ -46,9 +86,9 @@
</message>
</context>
<context>
<name>MemoryCardEditorDialog</name>
<name>MemoryCardEditorWindow</name>
<message numerus="yes">
<location filename="../memorycardeditordialog.cpp" line="296"/>
<location filename="../memorycardeditorwindow.cpp" line="301"/>
<source>%n block(s) free%1</source>
<translation>
<numerusform>%n block free%1</numerusform>
@ -57,33 +97,29 @@
</message>
</context>
<context>
<name>OSDMessage</name>
<name>System</name>
<message numerus="yes">
<source>%n cheats are now active.</source>
<translation type="vanished">
<location filename="../../core/system.cpp" line="2941"/>
<source>%n cheat(s) are now active.</source>
<translation>
<numerusform>%n cheat is now active.</numerusform>
<numerusform>%n cheats are now active.</numerusform>
</translation>
</message>
<message numerus="yes">
<source>%n cheats are now inactive.</source>
<translation type="vanished">
<location filename="../../core/system.cpp" line="2942"/>
<source>%n cheat(s) are now inactive.</source>
<translation>
<numerusform>%n cheat is now inactive.</numerusform>
<numerusform>%n cheats are now inactive.</numerusform>
</translation>
</message>
<message numerus="yes">
<source>Saved %n cheats to &apos;%s&apos;.</source>
<translation type="vanished">
<numerusform>Saved %n cheat to &apos;%s&apos;.</numerusform>
<numerusform>Saved %n cheats to &apos;%s&apos;.</numerusform>
</translation>
</message>
<message numerus="yes">
<source>%n cheats are enabled. This may result in instability.</source>
<translation type="vanished">
<numerusform>%n cheat is enabled. This may result in instability.</numerusform>
<numerusform>%n cheats are enabled. This may result in instability.</numerusform>
<location filename="../../core/system.cpp" line="4034"/>
<source>%n cheat(s) are enabled. This may crash games.</source>
<translation>
<numerusform>%n cheat is enabled. This may crash games.</numerusform>
<numerusform>%n cheats are enabled. This may crash games.</numerusform>
</translation>
</message>
</context>

View File

@ -1,7 +1,7 @@
@echo off
set "linguist=..\..\..\dep\msvc\deps-x64\bin"
set context=../ ../../core/ ../../util/ -tr-function-alias QT_TRANSLATE_NOOP+=TRANSLATE,QT_TRANSLATE_NOOP+=TRANSLATE_SV,QT_TRANSLATE_NOOP+=TRANSLATE_STR,QT_TRANSLATE_NOOP+=TRANSLATE_FS,QT_TRANSLATE_N_NOOP3+=TRANSLATE_FMT,QT_TRANSLATE_NOOP+=TRANSLATE_NOOP -pluralonly
set context=../ ../../core/ ../../util/ -tr-function-alias QT_TRANSLATE_NOOP+=TRANSLATE,QT_TRANSLATE_NOOP+=TRANSLATE_SV,QT_TRANSLATE_NOOP+=TRANSLATE_STR,QT_TRANSLATE_NOOP+=TRANSLATE_FS,QT_TRANSLATE_N_NOOP3+=TRANSLATE_FMT,QT_TRANSLATE_NOOP+=TRANSLATE_NOOP,translate+=TRANSLATE_PLURAL_STR,translate+=TRANSLATE_PLURAL_FS -pluralonly -no-obsolete
"%linguist%\lupdate.exe" %context% -ts duckstation-qt_en.ts
pause

View File

@ -3,7 +3,7 @@
if not defined lang (echo Please set your language first & pause & exit)
set "linguist=..\..\..\dep\msvc\deps-x64\bin"
SET "context=.././ ../../core/ ../../util/ -tr-function-alias QT_TRANSLATE_NOOP+=TRANSLATE,QT_TRANSLATE_NOOP+=TRANSLATE_SV,QT_TRANSLATE_NOOP+=TRANSLATE_STR,QT_TRANSLATE_NOOP+=TRANSLATE_FS,QT_TRANSLATE_N_NOOP3+=TRANSLATE_FMT,QT_TRANSLATE_NOOP+=TRANSLATE_NOOP"
SET "context=.././ ../../core/ ../../util/ -tr-function-alias QT_TRANSLATE_NOOP+=TRANSLATE,QT_TRANSLATE_NOOP+=TRANSLATE_SV,QT_TRANSLATE_NOOP+=TRANSLATE_STR,QT_TRANSLATE_NOOP+=TRANSLATE_FS,QT_TRANSLATE_N_NOOP3+=TRANSLATE_FMT,QT_TRANSLATE_NOOP+=TRANSLATE_NOOP,translate+=TRANSLATE_PLURAL_STR,translate+=TRANSLATE_PLURAL_FS"
"%linguist%\lupdate.exe" %context% -noobsolete -ts duckstation-qt_%lang%.ts
pause