feat: add translation function on the engine
This commit is contained in:
parent
3cb8c466a4
commit
2dfb92a160
|
@ -142,6 +142,11 @@ DOS_API void DOS_CALL dos_qqmlapplicationengine_load_url(DosQQmlApplicationEngin
|
||||||
/// \param data The UTF-8 string of the QML to load
|
/// \param data The UTF-8 string of the QML to load
|
||||||
DOS_API void DOS_CALL dos_qqmlapplicationengine_load_data(DosQQmlApplicationEngine *vptr, const char *data);
|
DOS_API void DOS_CALL dos_qqmlapplicationengine_load_data(DosQQmlApplicationEngine *vptr, const char *data);
|
||||||
|
|
||||||
|
/// \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);
|
||||||
|
|
||||||
/// \brief Calls the QQmlApplicationEngine::addImportPath function
|
/// \brief Calls the QQmlApplicationEngine::addImportPath function
|
||||||
/// \param vptr The QQmlApplicationEngine
|
/// \param vptr The QQmlApplicationEngine
|
||||||
/// \param path The path to be added to the list of import paths
|
/// \param path The path to be added to the list of import paths
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <QtQml/QQmlApplicationEngine>
|
#include <QtQml/QQmlApplicationEngine>
|
||||||
#include <QtQuick/QQuickView>
|
#include <QtQuick/QQuickView>
|
||||||
#include <QtQuick/QQuickImageProvider>
|
#include <QtQuick/QQuickImageProvider>
|
||||||
|
#include <QTranslator>
|
||||||
#ifdef QT_QUICKCONTROLS2_LIB
|
#ifdef QT_QUICKCONTROLS2_LIB
|
||||||
#include <QtQuickControls2/QQuickStyle>
|
#include <QtQuickControls2/QQuickStyle>
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,6 +58,9 @@ void register_meta_types()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// jrainville: I'm not sure where to put this, but it works like so
|
||||||
|
QTranslator *m_translator = new QTranslator();
|
||||||
|
|
||||||
char *convert_to_cstring(const QByteArray &array)
|
char *convert_to_cstring(const QByteArray &array)
|
||||||
{
|
{
|
||||||
return qstrdup(array.data());
|
return qstrdup(array.data());
|
||||||
|
@ -167,6 +171,20 @@ void dos_qqmlapplicationengine_load_data(::DosQQmlApplicationEngine *vptr, const
|
||||||
engine->loadData(data);
|
engine->loadData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dos_qapplication_load_translation(::DosQQmlApplicationEngine *vptr, const char* translationPackage)
|
||||||
|
{
|
||||||
|
if (!m_translator->isEmpty()) {
|
||||||
|
QCoreApplication::removeTranslator(m_translator);
|
||||||
|
}
|
||||||
|
if (m_translator->load(translationPackage)) {
|
||||||
|
bool success = QCoreApplication::installTranslator(m_translator);
|
||||||
|
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
||||||
|
engine->retranslate();
|
||||||
|
} else {
|
||||||
|
printf("Failed to load translation file %s\n", translationPackage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dos_qqmlapplicationengine_add_import_path(::DosQQmlApplicationEngine *vptr, const char *path)
|
void dos_qqmlapplicationengine_add_import_path(::DosQQmlApplicationEngine *vptr, const char *path)
|
||||||
{
|
{
|
||||||
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
||||||
|
@ -1092,4 +1110,6 @@ void dos_qncm_delete(::DosQNetworkConfigurationManager *vptr)
|
||||||
{
|
{
|
||||||
auto ncm = static_cast<QNetworkConfigurationManager *>(vptr);
|
auto ncm = static_cast<QNetworkConfigurationManager *>(vptr);
|
||||||
delete ncm;
|
delete ncm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "DOtherSide.moc"
|
||||||
|
|
Loading…
Reference in New Issue