Skip to content

Commit

Permalink
Refs #95. Work in progress on Web Login Dialog translation.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Sep 27, 2024
1 parent 44a42e7 commit 244e683
Show file tree
Hide file tree
Showing 11 changed files with 2,524 additions and 1,893 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cmake_minimum_required(VERSION 3.21)

#DEFINITIONS POLICY, NEW SINCE 3.0.2
cmake_policy(SET CMP0043 NEW)
cmake_policy(SET CMP0007 NEW)

# Software version
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
Expand Down
2,139 changes: 1,209 additions & 930 deletions client/resources/translations/openteraplus_en.ts

Large diffs are not rendered by default.

2,113 changes: 1,182 additions & 931 deletions client/resources/translations/openteraplus_fr.ts

Large diffs are not rendered by default.

78 changes: 57 additions & 21 deletions client/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ endif (MSVC)

find_package(Qt6 REQUIRED COMPONENTS LinguistTools Multimedia WebSockets Network)

qt_standard_project_setup(
I18N_SOURCE_LANGUAGE fr
I18N_TRANSLATED_LANGUAGES en fr
)

# Drivers first
add_subdirectory(drivers)

Expand Down Expand Up @@ -351,31 +356,62 @@ set(translation_files_srcs
)


#Translation files, this is done manually to avoid removing the file when doing make clean
# Add -noobsolete parameter to remove obsoleted translations
add_custom_target(openteraplus_en_ts
COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language en ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${moc_uis}
# #Translation files, this is done manually to avoid removing the file when doing make clean
# # Add -noobsolete parameter to remove obsoleted translations
# add_custom_target(openteraplus_en_ts
# COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language en ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# DEPENDS ${moc_uis}
# )

# add_custom_target(openteraplus_fr_ts
# COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language fr ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# DEPENDS ${moc_uis}
# )

# #set qm files output directory
# set_source_files_properties(${translation_files_srcs} PROPERTIES OUTPUT_LOCATION ${TERACLIENT_RES_INCLUDES}/translations/)

# #Build this target to update translations
# add_custom_target(translations DEPENDS openteraplus_en_ts openteraplus_fr_ts)
# add_custom_target(translation_files SOURCES ${translation_files_srcs})

# #Generate qm files from .ts files
# qt6_add_translation(qm_files
# ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts
# ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts)

# Translations
# if (Qt6_VERSION VERSION_GREATER_EQUAL 6.7)
# qt_add_translations(TARGETS OpenTeraPlus
# SOURCE_TARGETS ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis}
# TS_FILES ${translation_files_srcs}

# )
# else()
# qt_add_translations(OpenTeraPlus
# TS_FILES
# ${translation_files_srcs}
# )
# endif()
qt_add_lupdate(
TS_FILES
${translation_files_srcs}

SOURCES
${srcs}
${headers}
${moc_uis}

SOURCE_TARGETS opentera_shared
)

add_custom_target(openteraplus_fr_ts
COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language fr ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${moc_uis}
qt_add_lrelease(
TS_FILES
${translation_files_srcs}
)

#set qm files output directory
set_source_files_properties(${translation_files_srcs} PROPERTIES OUTPUT_LOCATION ${TERACLIENT_RES_INCLUDES}/translations/)

#Build this target to update translations
add_custom_target(translations DEPENDS openteraplus_en_ts openteraplus_fr_ts)
add_custom_target(translation_files SOURCES ${translation_files_srcs})

#Generate qm files from .ts files
qt6_add_translation(qm_files ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts)


message(STATUS "qm_files : ${qm_files}")

include_directories(
Expand Down
35 changes: 35 additions & 0 deletions client/src/dialogs/WebLoginDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "WebLoginDialog.h"
#include "ui_WebLoginDialog.h"

#include <QVBoxLayout>

#include "Utils.h"
#include "TeraSettings.h"

WebLoginDialog::WebLoginDialog(ConfigManagerClient *config, QWidget *parent)
: QDialog(parent), ui(new Ui::WebLoginDialog), m_config(config)
Expand All @@ -16,7 +19,10 @@ WebLoginDialog::WebLoginDialog(ConfigManagerClient *config, QWidget *parent)
QVBoxLayout *layout = new QVBoxLayout(ui->centralWidget);
layout->addWidget(m_webView);

m_requestInterceptor = new WebLoginRequestInterceptor(this);

m_webPage = new QWebEnginePage(m_webView);
m_webPage->setUrlRequestInterceptor(m_requestInterceptor);

QWebChannel *channel = new QWebChannel(m_webPage);

Expand Down Expand Up @@ -101,6 +107,7 @@ void WebLoginDialog::onLoginPageLoaded(bool ok)
if (ok){
ui->centralWidget->show();
ui->frameLoginMessages->hide();
m_webView->setFocus();
}else{
ui->lblError->show();
ui->lblLoading->hide();
Expand All @@ -122,3 +129,31 @@ QString WebLoginDialog::currentServerName()
}
return QString();
}


WebLoginRequestInterceptor::WebLoginRequestInterceptor(QObject *p) : QWebEngineUrlRequestInterceptor(p)
{
// Cache OS information
m_osName = Utils::getOsName();
m_osVersion = Utils::getOsVersion();
}

WebLoginRequestInterceptor::~WebLoginRequestInterceptor()
{

}

void WebLoginRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
// Inject client name and version
info.setHttpHeader("X-Client-Name", QByteArray(OPENTERAPLUS_CLIENT_NAME));
info.setHttpHeader("X-Client-Version", QByteArray(OPENTERAPLUS_VERSION));
info.setHttpHeader("X-OS-Name", m_osName.toUtf8());
info.setHttpHeader("X-OS-Version", m_osVersion.toUtf8());

// Inject required language
QString localeString = QLocale().bcp47Name();
//qDebug() << "localeString : " << localeString;
info.setHttpHeader(QByteArray("Accept-Language"), localeString.toUtf8());
}

24 changes: 20 additions & 4 deletions client/src/dialogs/WebLoginDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define WEBLOGINDIALOG_H

#include <QDialog>
#include "TeraSettings.h"

#include "managers/ConfigManagerClient.h"
#include <QWebEngineView>
#include <QWebEnginePage>
#include <QWebEngineSettings>
#include <QWebEngineCertificateError>
#include <QWebEngineUrlRequestInterceptor>

#include <QWebChannel>

Expand Down Expand Up @@ -39,6 +40,19 @@ namespace Ui {
class WebLoginDialog;
}


class WebLoginRequestInterceptor : public QWebEngineUrlRequestInterceptor {

// QWebEngineUrlRequestInterceptor interface
public:
WebLoginRequestInterceptor(QObject *p = nullptr);
~WebLoginRequestInterceptor();
void interceptRequest(QWebEngineUrlRequestInfo &info) override;
private:
QString m_osName;
QString m_osVersion;
};

class WebLoginDialog : public QDialog
{
Q_OBJECT
Expand All @@ -64,10 +78,12 @@ private slots:
void onLoginPageLoading();

private:
Ui::WebLoginDialog *ui;
QWebEngineView *m_webView;
QWebEnginePage *m_webPage;
Ui::WebLoginDialog *ui;
QWebEngineView *m_webView;
QWebEnginePage *m_webPage;
WebLoginRequestInterceptor *m_requestInterceptor;
ConfigManagerClient *m_config;
};


#endif // WEBLOGINDIALOG_H
4 changes: 2 additions & 2 deletions client/src/dialogs/WebLoginDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<width>500</width>
<height>500</height>
</rect>
</property>
Expand All @@ -18,7 +18,7 @@
</property>
<property name="minimumSize">
<size>
<width>450</width>
<width>500</width>
<height>500</height>
</size>
</property>
Expand Down
2 changes: 1 addition & 1 deletion client/src/editors/ProjectWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ bool ProjectWidget::validateData()
if (!editedProjectEnabled && m_data->getFieldValue("project_enabled").toBool()){
// We changed from "enabled" to "disabled". User confirmation required before proceeding.
GlobalMessageBox msg;
GlobalMessageBox::StandardButton rval = msg.showYesNo(tr("Confirmation - désactivation"), tr("Le project sera désactivé.") + "\n\r" +
GlobalMessageBox::StandardButton rval = msg.showYesNo(tr("Confirmation - désactivation"), tr("Le projet sera désactivé.") + "\n\r" +
tr("Tous les participants seront aussi désactivés et les appareils associés à ceux-ci seront désassociés.") + "\n\r" +
tr("Êtes-vous sûrs de vouloir continuer?"));
if (rval != GlobalMessageBox::Yes){
Expand Down
6 changes: 2 additions & 4 deletions client/src/managers/BaseComManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "BaseComManager.h"
#include <QOperatingSystemVersion>

BaseComManager::BaseComManager(QUrl serverUrl, QObject *parent)
: QObject{parent},
Expand All @@ -10,9 +9,8 @@ BaseComManager::BaseComManager(QUrl serverUrl, QObject *parent)
m_loggingInProgress = false;

// Get Operating system information to send to server for logging
QOperatingSystemVersion os = QOperatingSystemVersion::current();
m_osName = os.name();
m_osVersion = QString::number(os.majorVersion()) + "." + QString::number(os.minorVersion()) + "." + QString::number(os.microVersion());
m_osName = Utils::getOsName();
m_osVersion = Utils::getOsVersion();

// Create correct server url
m_serverUrl.setUrl("https://" + serverUrl.host() + ":" + QString::number(serverUrl.port()));
Expand Down
13 changes: 13 additions & 0 deletions shared/src/Utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Utils.h"
#include <QRegularExpression>
#include <QOperatingSystemVersion>

Utils::Utils(QObject *parent) : QObject(parent)
{
Expand Down Expand Up @@ -81,6 +82,18 @@ QString Utils::getMachineUniqueId()
return machine_id;
}

QString Utils::getOsName()
{
QOperatingSystemVersion os = QOperatingSystemVersion::current();
return os.name();
}

QString Utils::getOsVersion()
{
QOperatingSystemVersion os = QOperatingSystemVersion::current();
return QString::number(os.majorVersion()) + "." + QString::number(os.minorVersion()) + "." + QString::number(os.microVersion());
}

void Utils::inStringUnicodeConverter(QString *str)
{
if (str->contains("\\u")) {
Expand Down
2 changes: 2 additions & 0 deletions shared/src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class SHAREDLIB_EXPORT Utils : public QObject
static QList<PasswordValidationErrors> validatePassword(const QString& password);

static QString getMachineUniqueId();
static QString getOsName();
static QString getOsVersion();

static void inStringUnicodeConverter(QString* str);

Expand Down

0 comments on commit 244e683

Please sign in to comment.