feat: add parameter to make the translation dynamic or not

This commit is contained in:
Richard Ramos 2021-07-28 13:36:03 -04:00 committed by Michał
parent 0d4916d033
commit 1c3bbe1b8e
2 changed files with 4 additions and 3 deletions

View File

@ -172,7 +172,8 @@ DOS_API void DOS_CALL dos_qqmlapplicationengine_load_data(DosQQmlApplicationEngi
/// \brief Calls the load and install function for translations and calls retranslate on QQmlApplicationEngine
/// \param vptr The QQmlApplicationEngine
/// \param data The UTF-8 string of the path to the translation file (.qm)
DOS_API void DOS_CALL dos_qapplication_load_translation(DosQQmlApplicationEngine *vptr, const char* translationPackage);
/// \param shouldRetranslate Should retranslate() be called after loading a translation
DOS_API void DOS_CALL dos_qapplication_load_translation(DosQQmlApplicationEngine *vptr, const char* translationPackage, bool shouldRetranslate);
/// \brief Calls the QQmlApplicationEngine::addImportPath function
/// \param vptr The QQmlApplicationEngine

View File

@ -259,7 +259,7 @@ void dos_qqmlapplicationengine_load_data(::DosQQmlApplicationEngine *vptr, const
engine->loadData(data);
}
void dos_qapplication_load_translation(::DosQQmlApplicationEngine *vptr, const char* translationPackage)
void dos_qapplication_load_translation(::DosQQmlApplicationEngine *vptr, const char* translationPackage, bool shouldRetranslate)
{
if (!m_translator->isEmpty()) {
QCoreApplication::removeTranslator(m_translator);
@ -267,7 +267,7 @@ void dos_qapplication_load_translation(::DosQQmlApplicationEngine *vptr, const c
if (m_translator->load(translationPackage)) {
bool success = QCoreApplication::installTranslator(m_translator);
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
engine->retranslate();
if (shouldRetranslate) engine->retranslate();
} else {
printf("Failed to load translation file %s\n", translationPackage);
}