From a9375add32ae6c5cd90679cf6cb7e2af18c27e7a Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Sun, 28 Jul 2019 18:40:23 -0400 Subject: Address 'sent' translation issue --- src/Utils.h | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Utils.h b/src/Utils.h index 756dc1e3..d2aa6d93 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -9,6 +9,7 @@ #include "timeline/widgets/ImageItem.h" #include "timeline/widgets/VideoItem.h" +#include #include #include #include @@ -79,7 +80,9 @@ event_body(const mtx::events::collections::TimelineEvents &event); //! Match widgets/events with a description message. template QString -messageDescription(const QString &username = "", const QString &body = "") +messageDescription(const QString &username = "", + const QString &body = "", + const bool isLocal = false) { using Audio = mtx::events::RoomEvent; using Emote = mtx::events::RoomEvent; @@ -91,24 +94,34 @@ messageDescription(const QString &username = "", const QString &body = "") using Video = mtx::events::RoomEvent; using Encrypted = mtx::events::EncryptedEvent; - if (std::is_same::value || std::is_same::value) - return QString("sent an audio clip"); - else if (std::is_same::value || std::is_same::value) - return QString("sent an image"); - else if (std::is_same::value || std::is_same::value) - return QString("sent a file"); - else if (std::is_same::value || std::is_same::value) - return QString("sent a video clip"); - else if (std::is_same::value || std::is_same::value) - return QString("sent a sticker"); - else if (std::is_same::value) - return QString("sent a notification"); - else if (std::is_same::value) + // Sometimes the verb form of sent changes in some languages depending on the actor. + auto remoteSent = + QCoreApplication::translate("utils", "sent", "For when you are the sender"); + auto localSent = + QCoreApplication::translate("utils", "sent", "For when someone else is the sender"); + QString sentVerb = isLocal ? localSent : remoteSent; + if (std::is_same::value || std::is_same::value) { + return QCoreApplication::translate("utils", "%1 an audio clip").arg(sentVerb); + } else if (std::is_same::value || std::is_same::value) { + return QCoreApplication::translate("utils", "%1 an image").arg(sentVerb); + } else if (std::is_same::value || std::is_same::value) { + return QCoreApplication::translate("utils", "%1 a file").arg(sentVerb); + } else if (std::is_same::value || std::is_same::value) { + return QCoreApplication::translate("utils", "%1 a video clip").arg(sentVerb); + } else if (std::is_same::value || std::is_same::value) { + return QCoreApplication::translate("utils", "%1 a sticker").arg(sentVerb); + } else if (std::is_same::value) { + return QCoreApplication::translate("utils", "%1 a notification").arg(sentVerb); + } else if (std::is_same::value) { return QString(": %1").arg(body); - else if (std::is_same::value) + } else if (std::is_same::value) { return QString("* %1 %2").arg(username).arg(body); - else if (std::is_same::value) - return QString("sent an encrypted message"); + } else if (std::is_same::value) { + return QCoreApplication::translate("utils", "%1 an encrypted message") + .arg(sentVerb); + } else { + return QCoreApplication::translate("utils", "Unknown Message Type"); + } } template @@ -129,10 +142,12 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin return DescInfo{ QString::fromStdString(msg.event_id), - isEmote ? "" : (sender == localUser ? "You" : username), + isEmote ? "" + : (sender == localUser ? QCoreApplication::translate("utils", "You") : username), sender, (isText || isEmote) - ? messageDescription(username, QString::fromStdString(msg.content.body).trimmed()) + ? messageDescription( + username, QString::fromStdString(msg.content.body).trimmed(), sender == localUser) : QString(" %1").arg(messageDescription()), utils::descriptiveTime(ts), ts}; -- cgit 1.5.1