Skip to content

Commit 8d55db3

Browse files
committed
Qt: deploy and apply Qt translations
1 parent ee06dcc commit 8d55db3

5 files changed

Lines changed: 67 additions & 13 deletions

File tree

.ci/deploy-windows-clang.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ else
3838
echo "Failed to download translations.zip. Continuing without translations."
3939
exit 0
4040
}
41-
unzip -o translations.zip -d "./bin/share/qt6/translations" >/dev/null 2>&1 || \
41+
7z x translations.zip -o"./bin/share/qt6/translations" >/dev/null 2>&1 || \
4242
echo "Failed to extract translations.zip. Continuing without translations."
4343
rm -f translations.zip
4444
fi

.ci/setup-windows.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ QT_DECL_URL="${QT_HOST}${QT_PREFIX}${QT_PREFIX_2}qtdeclarative${QT_SUFFIX}"
1414
QT_TOOL_URL="${QT_HOST}${QT_PREFIX}${QT_PREFIX_2}qttools${QT_SUFFIX}"
1515
QT_MM_URL="${QT_HOST}${QT_PREFIX}addons.qtmultimedia.${QT_PREFIX_2}qtmultimedia${QT_SUFFIX}"
1616
QT_SVG_URL="${QT_HOST}${QT_PREFIX}${QT_PREFIX_2}qtsvg${QT_SUFFIX}"
17+
QT_TRANSLATIONS_URL="${QT_HOST}${QT_PREFIX}${QT_PREFIX_2}qttranslations${QT_SUFFIX}"
1718
LLVMLIBS_URL="https://github.com/RPCS3/llvm-mirror/releases/download/custom-build-win-${LLVM_VER}/llvmlibs_mt.7z"
1819
VULKAN_SDK_URL="https://www.dropbox.com/scl/fi/sjjh0fc4ld281pjbl2xzu/VulkanSDK-${VULKAN_VER}-Installer.exe?rlkey=f6wzc0lvms5vwkt2z3qabfv9d&dl=1"
1920
CCACHE_URL="https://github.com/ccache/ccache/releases/download/v4.11.2/ccache-4.11.2-windows-x86_64.zip"
@@ -24,6 +25,7 @@ DEP_URLS=" \
2425
$QT_TOOL_URL \
2526
$QT_MM_URL \
2627
$QT_SVG_URL \
28+
$QT_TRANSLATIONS_URL \
2729
$LLVMLIBS_URL \
2830
$VULKAN_SDK_URL\
2931
$CCACHE_URL"

rpcs3/rpcs3.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
</ResourceCompile>
111111
<PostBuildEvent>
112112
<Command>
113-
$(QTDIR)\bin\windeployqt6 --no-compiler-runtime --no-opengl-sw --no-patchqt --no-translations --no-quick --no-system-d3d-compiler --no-system-dxc-compiler --no-quick-import --plugindir "$(TargetDir)qt6\plugins" --release "$(TargetPath)"
113+
$(QTDIR)\bin\windeployqt6 --no-compiler-runtime --no-opengl-sw --no-patchqt --no-quick --no-system-d3d-compiler --no-system-dxc-compiler --no-quick-import --plugindir "$(TargetDir)qt6\plugins" --translationdir "$(TargetDir)qt6\translations" --release "$(TargetPath)"
114114
xcopy /y /d "$(SolutionDir)3rdparty\opencv\opencv\opencv412\build\x64\bin\opencv_world4120.dll" "$(OutDir)"
115115
</Command>
116116
</PostBuildEvent>
@@ -169,7 +169,7 @@
169169
</ResourceCompile>
170170
<PostBuildEvent>
171171
<Command>
172-
$(QTDIR)\bin\windeployqt6 --no-compiler-runtime --no-opengl-sw --no-patchqt --no-translations --no-quick --no-system-d3d-compiler --no-system-dxc-compiler --no-quick-import --plugindir "$(TargetDir)qt6\plugins" --debug "$(TargetPath)"
172+
$(QTDIR)\bin\windeployqt6 --no-compiler-runtime --no-opengl-sw --no-patchqt --no-quick --no-system-d3d-compiler --no-system-dxc-compiler --no-quick-import --plugindir "$(TargetDir)qt6\plugins" --translationdir "$(TargetDir)qt6\translations" --debug "$(TargetPath)"
173173
xcopy /y /d "$(SolutionDir)3rdparty\opencv\opencv\opencv412\build\x64\bin\opencv_world4120.dll" "$(OutDir)"
174174
</Command>
175175
</PostBuildEvent>

rpcs3/rpcs3qt/gui_application.cpp

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,29 +216,74 @@ bool gui_application::Init()
216216
return true;
217217
}
218218

219-
void gui_application::SwitchTranslator(QTranslator& translator, const QString& filename, const QString& language_code)
219+
void gui_application::SwitchTranslator(const QString& language_code)
220220
{
221221
// remove the old translator
222-
removeTranslator(&translator);
222+
removeTranslator(&m_translator);
223+
for (QTranslator* qt_translator : m_qt_translators)
224+
{
225+
removeTranslator(qt_translator);
226+
qt_translator->deleteLater();
227+
}
228+
m_qt_translators.clear();
223229

230+
const QString default_code = QLocale(QLocale::English).bcp47Name();
224231
const QString lang_path = QLibraryInfo::path(QLibraryInfo::TranslationsPath) + QStringLiteral("/");
225-
const QString file_path = lang_path + filename;
226232

233+
// Load qt translation files
234+
const QDir dir(lang_path);
235+
if (dir.exists())
236+
{
237+
QStringList qm_files = dir.entryList(QStringList() << QStringLiteral("qt*_%1.qm").arg(language_code), QDir::Files | QDir::Readable);
238+
if (qm_files.empty())
239+
{
240+
qm_files = dir.entryList(QStringList() << QStringLiteral("qt*_%1.qm").arg(QLocale::languageToCode(QLocale(language_code).language())), QDir::Files | QDir::Readable);
241+
}
242+
243+
for (const QString& qm_file : qm_files)
244+
{
245+
const QString file_path = lang_path + qm_file;
246+
QTranslator* qt_translator = new QTranslator(this);
247+
248+
if (qt_translator->load(file_path))
249+
{
250+
gui_log.notice("Installing translation: '%s'", file_path);
251+
installTranslator(qt_translator);
252+
m_qt_translators.push_back(std::move(qt_translator));
253+
}
254+
else
255+
{
256+
gui_log.error("Failed to load translation: '%s'", file_path);
257+
qt_translator->deleteLater();
258+
}
259+
}
260+
}
261+
else
262+
{
263+
gui_log.error("Qt translation dir '%s' does not exist", lang_path);
264+
}
265+
266+
const QString file_path = lang_path + QStringLiteral("rpcs3_%1.qm").arg(language_code);
227267
if (QFileInfo(file_path).isFile())
228268
{
229269
// load the new translator
230-
if (translator.load(file_path))
270+
if (m_translator.load(file_path))
231271
{
232-
installTranslator(&translator);
272+
gui_log.notice("Installing translation: '%s'", file_path);
273+
installTranslator(&m_translator);
274+
}
275+
else
276+
{
277+
gui_log.error("Failed to load translation: '%s'", file_path);
233278
}
234279
}
235-
else if (QString default_code = QLocale(QLocale::English).bcp47Name(); language_code != default_code)
280+
else if (language_code != default_code)
236281
{
237282
// show error, but ignore default case "en", since it is handled in source code
238-
gui_log.error("No translation file found in: %s", file_path);
283+
gui_log.error("No translation file found in: '%s'", file_path);
239284

240285
// reset current language to default "en"
241-
set_language_code(std::move(default_code));
286+
set_language_code(default_code);
242287
}
243288
}
244289

@@ -260,7 +305,7 @@ void gui_application::LoadLanguage(const QString& language_code)
260305
// As per QT recommendations to avoid conflicts for POSIX functions
261306
std::setlocale(LC_NUMERIC, "C");
262307

263-
SwitchTranslator(m_translator, QStringLiteral("rpcs3_%1.qm").arg(language_code), language_code);
308+
SwitchTranslator(language_code);
264309

265310
if (m_main_window)
266311
{
@@ -285,6 +330,7 @@ QStringList gui_application::GetAvailableLanguageCodes()
285330
QStringList language_codes;
286331

287332
const QString language_path = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
333+
gui_log.notice("Checking languages in '%s'", language_path);
288334

289335
if (QFileInfo(language_path).isDir())
290336
{
@@ -303,10 +349,15 @@ QStringList gui_application::GetAvailableLanguageCodes()
303349
}
304350
else
305351
{
352+
gui_log.notice("Found language '%s' (%s)", language_code, filename);
306353
language_codes << language_code;
307354
}
308355
}
309356
}
357+
else
358+
{
359+
gui_log.error("Language dir not found: '%s'", language_path);
360+
}
310361

311362
return language_codes;
312363
}

rpcs3/rpcs3qt/gui_application.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class gui_application : public QApplication, public main_application
8181
return thread();
8282
}
8383

84-
void SwitchTranslator(QTranslator& translator, const QString& filename, const QString& language_code);
84+
void SwitchTranslator(const QString& language_code);
8585
void LoadLanguage(const QString& language_code);
8686
static QStringList GetAvailableLanguageCodes();
8787

@@ -101,6 +101,7 @@ class gui_application : public QApplication, public main_application
101101

102102
} m_native_event_filter;
103103

104+
std::vector<QTranslator*> m_qt_translators;
104105
QTranslator m_translator;
105106
QString m_language_code;
106107
static s32 m_language_id;

0 commit comments

Comments
 (0)