Simplify dynamic string handling and localization

Use Qt `.arg()` instead of substring replacement;
Fully remove remnants of SDL renderers from translations;
Restore platform-dependent pcap library name in the pcap
error message, but use Npcap on Windows instead
This commit is contained in:
Alexander Babikov
2024-03-20 18:52:51 +05:00
parent 82e6a7a129
commit f02fd4568c
26 changed files with 386 additions and 738 deletions

View File

@@ -581,14 +581,16 @@ c16stombs(char dst[], const uint16_t src[], int len)
#ifdef _WIN32
# if defined(__amd64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64)
# define LIB_NAME_GS "gsdll64.dll"
# define LIB_NAME_GS "gsdll64.dll"
# else
# define LIB_NAME_GS "gsdll32.dll"
# define LIB_NAME_GS "gsdll32.dll"
# endif
# define LIB_NAME_PCAP "Npcap"
# define MOUSE_CAPTURE_KEYSEQ "F8+F12"
#else
# define LIB_NAME_GS "libgs"
# define MOUSE_CAPTURE_KEYSEQ "CTRL-END"
# define LIB_NAME_PCAP "libpcap"
# define MOUSE_CAPTURE_KEYSEQ "Ctrl+End"
#endif
QMap<int, std::wstring> ProgSettings::translatedstrings;
@@ -598,14 +600,15 @@ ProgSettings::reloadStrings()
{
translatedstrings.clear();
translatedstrings[STRING_MOUSE_CAPTURE] = QCoreApplication::translate("", "Click to capture mouse").toStdWString();
translatedstrings[STRING_MOUSE_RELEASE] = QCoreApplication::translate("", "Press F8+F12 to release mouse").replace("F8+F12", MOUSE_CAPTURE_KEYSEQ).replace("CTRL-END", QLocale::system().name() == "de_DE" ? "Strg+Ende" : "CTRL-END").toStdWString();
translatedstrings[STRING_MOUSE_RELEASE_MMB] = QCoreApplication::translate("", "Press F8+F12 or middle button to release mouse").replace("F8+F12", MOUSE_CAPTURE_KEYSEQ).replace("CTRL-END", QLocale::system().name() == "de_DE" ? "Strg+Ende" : "CTRL-END").toStdWString();
translatedstrings[STRING_MOUSE_RELEASE] = QCoreApplication::translate("", "Press %1 to release mouse").arg(QCoreApplication::translate("", MOUSE_CAPTURE_KEYSEQ)).toStdWString();
translatedstrings[STRING_MOUSE_RELEASE_MMB] = QCoreApplication::translate("", "Press %1 or middle button to release mouse").arg(QCoreApplication::translate("", MOUSE_CAPTURE_KEYSEQ)).toStdWString();
translatedstrings[STRING_INVALID_CONFIG] = QCoreApplication::translate("", "Invalid configuration").toStdWString();
translatedstrings[STRING_NO_ST506_ESDI_CDROM] = QCoreApplication::translate("", "MFM/RLL or ESDI CD-ROM drives never existed").toStdWString();
translatedstrings[STRING_PCAP_ERROR_NO_DEVICES] = QCoreApplication::translate("", "No PCap devices found").toStdWString();
translatedstrings[STRING_PCAP_ERROR_INVALID_DEVICE] = QCoreApplication::translate("", "Invalid PCap device").toStdWString();
translatedstrings[STRING_PCAP_ERROR_DESC] = QCoreApplication::translate("", "Make sure libpcap is installed and that you are on a libpcap-compatible network connection.").toStdWString();
translatedstrings[STRING_PCAP_ERROR_DESC] = QCoreApplication::translate("", "Make sure %1 is installed and that you are on a %1-compatible network connection.").arg(LIB_NAME_PCAP).toStdWString();
translatedstrings[STRING_GHOSTSCRIPT_ERROR_TITLE] = QCoreApplication::translate("", "Unable to initialize Ghostscript").toStdWString();
translatedstrings[STRING_GHOSTSCRIPT_ERROR_DESC] = QCoreApplication::translate("", "%1 is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files.").arg(LIB_NAME_GS).toStdWString();
translatedstrings[STRING_HW_NOT_AVAILABLE_MACHINE] = QCoreApplication::translate("", "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine.").toStdWString();
translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO] = QCoreApplication::translate("", "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card.").toStdWString();
translatedstrings[STRING_HW_NOT_AVAILABLE_VIDEO2] = QCoreApplication::translate("", "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card.").toStdWString();
@@ -613,13 +616,6 @@ ProgSettings::reloadStrings()
translatedstrings[STRING_MONITOR_SLEEP] = QCoreApplication::translate("", "Monitor in sleep mode").toStdWString();
translatedstrings[STRING_NET_ERROR] = QCoreApplication::translate("", "Failed to initialize network driver").toStdWString();
translatedstrings[STRING_NET_ERROR_DESC] = QCoreApplication::translate("", "The network configuration will be switched to the null driver").toStdWString();
auto gsstr = QCoreApplication::translate("", " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files.");
if (gsstr.contains("libgs")) {
gsstr.replace("libgs", LIB_NAME_GS);
} else
gsstr.prepend(LIB_NAME_GS);
translatedstrings[STRING_GHOSTSCRIPT_ERROR_DESC] = gsstr.toStdWString();
}
wchar_t *