Merge pull request #353 from amnezia-vpn/feature/added_i18n_for_v4

added i18n for v4
This commit is contained in:
Nethius 2023-10-06 11:49:17 +03:00 committed by GitHub
commit 5c121ea48d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 3896 additions and 2024 deletions

View file

@ -19,6 +19,8 @@ ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &s
Qt::QueuedConnection);
connect(this, &ConnectionController::disconnectFromVpn, m_vpnConnection.get(), &VpnConnection::disconnectFromVpn,
Qt::QueuedConnection);
m_state = Vpn::ConnectionState::Disconnected;
}
void ConnectionController::openConnection()
@ -53,6 +55,8 @@ QString ConnectionController::getLastConnectionError()
void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state)
{
m_state = state;
m_isConnected = false;
m_connectionStateText = tr("Connection...");
switch (state) {
@ -109,6 +113,17 @@ void ConnectionController::onCurrentContainerUpdated()
}
}
void ConnectionController::onTranslationsUpdated()
{
// get translated text of current state
onConnectionStateChanged(getCurrentConnectionState());
}
Vpn::ConnectionState ConnectionController::getCurrentConnectionState()
{
return m_state;
}
QString ConnectionController::connectionStateText() const
{
return m_connectionStateText;

View file

@ -34,6 +34,8 @@ public slots:
void onCurrentContainerUpdated();
void onTranslationsUpdated();
signals:
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
const QJsonObject &containerConfig);
@ -44,6 +46,8 @@ signals:
void reconnectWithUpdatedContainer(const QString &message);
private:
Vpn::ConnectionState getCurrentConnectionState();
QSharedPointer<ServersModel> m_serversModel;
QSharedPointer<ContainersModel> m_containersModel;
@ -52,6 +56,8 @@ private:
bool m_isConnected = false;
bool m_isConnectionInProgress = false;
QString m_connectionStateText = tr("Connect");
Vpn::ConnectionState m_state;
};
#endif // CONNECTIONCONTROLLER_H

View file

@ -107,10 +107,9 @@ void InstallController::installServer(DockerContainer container, QJsonObject &co
if (!installedContainers.contains(container)) {
errorCode = serverController.setupContainer(m_currentlyInstalledServerCredentials, container, config);
installedContainers.insert(container, config);
finishMessage = ContainerProps::containerHumanNames().value(container) + tr(" installed successfully. ");
finishMessage = tr("%1 installed successfully. ").arg(ContainerProps::containerHumanNames().value(container));
} else {
finishMessage =
ContainerProps::containerHumanNames().value(container) + tr(" is already installed on the server. ");
finishMessage = tr("%1 is already installed on the server. ").arg(ContainerProps::containerHumanNames().value(container));
}
if (installedContainers.size() > 1) {
finishMessage += tr("\nAdded containers that were already installed on the server");
@ -159,10 +158,9 @@ void InstallController::installContainer(DockerContainer container, QJsonObject
if (!installedContainers.contains(container)) {
errorCode = serverController.setupContainer(serverCredentials, container, config);
installedContainers.insert(container, config);
finishMessage = ContainerProps::containerHumanNames().value(container) + tr(" installed successfully. ");
finishMessage = tr("%1 installed successfully. ").arg(ContainerProps::containerHumanNames().value(container));
} else {
finishMessage =
ContainerProps::containerHumanNames().value(container) + tr(" is already installed on the server. ");
finishMessage = tr("%1 is already installed on the server. ").arg(ContainerProps::containerHumanNames().value(container));
}
bool isInstalledContainerAddedToGui = false;
@ -277,7 +275,7 @@ void InstallController::removeCurrentlyProcessedServer()
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
m_serversModel->removeServer();
emit removeCurrentlyProcessedServerFinished(tr("Server '") + serverName + tr("' was removed"));
emit removeCurrentlyProcessedServerFinished(tr("Server '%1' was removed").arg(serverName));
}
void InstallController::removeAllContainers()
@ -287,7 +285,7 @@ void InstallController::removeAllContainers()
ErrorCode errorCode = m_containersModel->removeAllContainers();
if (errorCode == ErrorCode::NoError) {
emit removeAllContainersFinished(tr("All containers from server '") + serverName + ("' have been removed"));
emit removeAllContainersFinished(tr("All containers from server '%1' have been removed").arg(serverName));
return;
}
emit installationErrorOccurred(errorString(errorCode));
@ -303,8 +301,8 @@ void InstallController::removeCurrentlyProcessedContainer()
ErrorCode errorCode = m_containersModel->removeCurrentlyProcessedContainer();
if (errorCode == ErrorCode::NoError) {
emit removeCurrentlyProcessedContainerFinished(containerName + tr(" has been removed from the server '")
+ serverName + "'");
emit removeCurrentlyProcessedContainerFinished(tr("%1 has been removed from the server '%2'").arg(containerName).arg(serverName));
return;
}
emit installationErrorOccurred(errorString(errorCode));

View file

@ -64,7 +64,7 @@ void SitesController::addSite(QString hostname)
QHostInfo::lookupHost(hostname, this, resolveCallback);
}
emit finished(tr("New site added: ") + hostname);
emit finished(tr("New site added: %1").arg(hostname));
}
void SitesController::removeSite(int index)
@ -77,7 +77,7 @@ void SitesController::removeSite(int index)
Q_ARG(QStringList, QStringList() << hostname));
QMetaObject::invokeMethod(m_vpnConnection.get(), "flushDns", Qt::QueuedConnection);
emit finished(tr("Site removed: ") + hostname);
emit finished(tr("Site removed: %1").arg(hostname));
}
void SitesController::importSites(const QString &fileName, bool replaceExisting)
@ -85,19 +85,19 @@ void SitesController::importSites(const QString &fileName, bool replaceExisting)
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
emit errorOccurred(tr("Can't open file: ") + fileName);
emit errorOccurred(tr("Can't open file: %1").arg(fileName));
return;
}
QByteArray jsonData = file.readAll();
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonData);
if (jsonDocument.isNull()) {
emit errorOccurred(tr("Failed to parse JSON data from file: ") + fileName);
emit errorOccurred(tr("Failed to parse JSON data from file: %1").arg(fileName));
return;
}
if (!jsonDocument.isArray()) {
emit errorOccurred(tr("The JSON data is not an array in file: ") + fileName);
emit errorOccurred(tr("The JSON data is not an array in file: ").arg(fileName));
return;
}