Port away from qsTr/tr

This commit is contained in:
Tobias Fella
2020-11-17 20:06:30 +01:00
parent 03921e02a6
commit 3a11ff614c
5 changed files with 45 additions and 39 deletions

View File

@@ -130,15 +130,15 @@ RowLayout {
function humanSize(bytes) function humanSize(bytes)
{ {
if (!bytes) if (!bytes)
return qsTr("Unknown", "Unknown attachment size") return i18nc("Unknown attachment size", "Unknown")
if (bytes < 4000) if (bytes < 4000)
return qsTr("%1 bytes").arg(bytes) return i18np("%1 byte", "%1 bytes", bytes)
bytes = Math.round(bytes / 100) / 10 bytes = Math.round(bytes / 100) / 10
if (bytes < 2000) if (bytes < 2000)
return qsTr("%1 KB").arg(bytes) return i18nc("KB as in kilobytes", "%1 KB", bytes)
bytes = Math.round(bytes / 100) / 10 bytes = Math.round(bytes / 100) / 10
if (bytes < 2000) if (bytes < 2000)
return qsTr("%1 MB").arg(bytes) return i18nc("MB as in megabytes", "%1 MB", bytes)
return qsTr("%1 GB").arg(Math.round(bytes / 100) / 10) return i18nc("GB as in gigabytes", "%1 GB", Math.round(bytes / 100) / 10)
} }
} }

View File

@@ -12,6 +12,8 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QThread> #include <QThread>
#include <KLocalizedString>
#include "controller.h" #include "controller.h"
using Quotient::BaseJob; using Quotient::BaseJob;
@@ -27,7 +29,7 @@ ThumbnailResponse::ThumbnailResponse(QString id, QSize size)
requestedSize.setWidth(100); requestedSize.setWidth(100);
} }
if (mediaId.count('/') != 1) { if (mediaId.count('/') != 1) {
errorStr = tr("Media id '%1' doesn't follow server/mediaId pattern").arg(mediaId); errorStr = i18n("Media id '%1' doesn't follow server/mediaId pattern", mediaId);
Q_EMIT finished(); Q_EMIT finished();
return; return;
} }
@@ -78,7 +80,7 @@ void ThumbnailResponse::prepareResult()
errorStr.clear(); errorStr.clear();
} else if (job->error() == BaseJob::Abandoned) { } else if (job->error() == BaseJob::Abandoned) {
errorStr = tr("Image request has been cancelled"); errorStr = i18n("Image request has been cancelled");
qDebug() << "ThumbnailResponse: cancelled for" << mediaId; qDebug() << "ThumbnailResponse: cancelled for" << mediaId;
} else { } else {
errorStr = job->errorString(); errorStr = job->errorString();

View File

@@ -17,6 +17,8 @@
#include <QDebug> #include <QDebug>
#include <QQmlEngine> // for qmlRegisterType() #include <QQmlEngine> // for qmlRegisterType()
#include <KLocalizedString>
#include "utils.h" #include "utils.h"
QHash<int, QByteArray> MessageEventModel::roleNames() const QHash<int, QByteArray> MessageEventModel::roleNames() const
@@ -224,11 +226,11 @@ QString MessageEventModel::renderDate(QDateTime timestamp) const
{ {
auto date = timestamp.toLocalTime().date(); auto date = timestamp.toLocalTime().date();
if (date == QDate::currentDate()) if (date == QDate::currentDate())
return tr("Today"); return i18n("Today");
if (date == QDate::currentDate().addDays(-1)) if (date == QDate::currentDate().addDays(-1))
return tr("Yesterday"); return i18n("Yesterday");
if (date == QDate::currentDate().addDays(-2)) if (date == QDate::currentDate().addDays(-2))
return tr("The day before yesterday"); return i18n("The day before yesterday");
if (date > QDate::currentDate().addDays(-7)) if (date > QDate::currentDate().addDays(-7))
return date.toString("dddd"); return date.toString("dddd");
@@ -343,7 +345,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
if (role == ContentRole) { if (role == ContentRole) {
if (evt.isRedacted()) { if (evt.isRedacted()) {
auto reason = evt.redactedBecause()->reason(); auto reason = evt.redactedBecause()->reason();
return (reason.isEmpty()) ? tr("[REDACTED]") : tr("[REDACTED: %1]").arg(evt.redactedBecause()->reason()); return (reason.isEmpty()) ? i18n("[REDACTED]") : i18n("[REDACTED: %1]").arg(evt.redactedBecause()->reason());
} }
if (auto e = eventCast<const RoomMessageEvent>(&evt)) { if (auto e = eventCast<const RoomMessageEvent>(&evt)) {

View File

@@ -32,6 +32,8 @@
#include "user.h" #include "user.h"
#include "utils.h" #include "utils.h"
#include <KLocalizedString>
NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinState) NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinState)
: Room(connection, std::move(roomId), joinState) : Room(connection, std::move(roomId), joinState)
{ {
@@ -264,7 +266,7 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format,
} else if (e.content()->fileInfo()->originalName != e.plainBody()) { } else if (e.content()->fileInfo()->originalName != e.plainBody()) {
fileCaption = e.plainBody() + " | " + fileCaption; fileCaption = e.plainBody() + " | " + fileCaption;
} }
return !fileCaption.isEmpty() ? fileCaption : tr("a file"); return !fileCaption.isEmpty() ? fileCaption : i18n("a file");
} }
// 2. prettyPrint/text 3. plainText/HTML 4. plainText/text // 2. prettyPrint/text 3. plainText/HTML 4. plainText/text
@@ -293,74 +295,72 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format,
switch (e.membership()) { switch (e.membership()) {
case MembershipType::Invite: case MembershipType::Invite:
if (e.repeatsState()) if (e.repeatsState())
return tr("reinvited %1 to the room").arg(subjectName); return i18n("reinvited %1 to the room", subjectName);
case MembershipType::Join: { case MembershipType::Join: {
if (e.repeatsState()) if (e.repeatsState())
return tr("joined the room (repeated)"); return i18n("joined the room (repeated)");
if (!e.prevContent() || e.membership() != e.prevContent()->membership) { if (!e.prevContent() || e.membership() != e.prevContent()->membership) {
return e.membership() == MembershipType::Invite ? tr("invited %1 to the room").arg(subjectName) : tr("joined the room"); return e.membership() == MembershipType::Invite ? i18n("invited %1 to the room", subjectName) : i18n("joined the room");
} }
QString text {}; QString text {};
if (e.isRename()) { if (e.isRename()) {
if (e.newDisplayName()->isEmpty()) if (e.newDisplayName()->isEmpty())
text = tr("cleared their display name"); text = i18n("cleared their display name");
else else
text = tr("changed their display name to %1").arg(e.newDisplayName()->toHtmlEscaped()); text = i18n("changed their display name to %1", e.newDisplayName()->toHtmlEscaped());
} }
if (e.isAvatarUpdate()) { if (e.isAvatarUpdate()) {
if (!text.isEmpty()) if (!text.isEmpty())
text += " and "; text += i18n(" and ");
if (!e.newAvatarUrl()) if (!e.newAvatarUrl())
text += tr("cleared their avatar"); text += i18n("cleared their avatar");
else if (!e.prevContent()->avatarUrl) else if (!e.prevContent()->avatarUrl)
text += tr("set an avatar"); text += i18n("set an avatar");
else else
text += tr("updated their avatar"); text += i18n("updated their avatar");
} }
return text; return text;
} }
case MembershipType::Leave: case MembershipType::Leave:
if (e.prevContent() && e.prevContent()->membership == MembershipType::Invite) { if (e.prevContent() && e.prevContent()->membership == MembershipType::Invite) {
return (e.senderId() != e.userId()) ? tr("withdrew %1's invitation").arg(subjectName) : tr("rejected the invitation"); return (e.senderId() != e.userId()) ? i18n("withdrew %1's invitation", subjectName) : i18n("rejected the invitation");
} }
if (e.prevContent() && e.prevContent()->membership == MembershipType::Ban) { if (e.prevContent() && e.prevContent()->membership == MembershipType::Ban) {
return (e.senderId() != e.userId()) ? tr("unbanned %1").arg(subjectName) : tr("self-unbanned"); return (e.senderId() != e.userId()) ? i18n("unbanned %1", subjectName) : i18n("self-unbanned");
} }
return (e.senderId() != e.userId()) ? tr("has put %1 out of the room: %2").arg(subjectName, e.contentJson()["reason"_ls].toString().toHtmlEscaped()) : tr("left the room"); return (e.senderId() != e.userId()) ? i18n("has put %1 out of the room: %2", subjectName, e.contentJson()["reason"_ls].toString().toHtmlEscaped()) : i18n("left the room");
case MembershipType::Ban: case MembershipType::Ban:
return (e.senderId() != e.userId()) ? tr("banned %1 from the room: %2").arg(subjectName, e.contentJson()["reason"_ls].toString().toHtmlEscaped()) : tr("self-banned from the room"); return (e.senderId() != e.userId()) ? i18n("banned %1 from the room: %2", subjectName, e.contentJson()["reason"_ls].toString().toHtmlEscaped()) : i18n("self-banned from the room");
case MembershipType::Knock: case MembershipType::Knock:
return tr("knocked"); return i18n("knocked");
default:; default:;
} }
return tr("made something unknown"); return i18n("made something unknown");
}, },
[](const RoomCanonicalAliasEvent &e) { [](const RoomCanonicalAliasEvent &e) {
return (e.alias().isEmpty()) ? tr("cleared the room main alias") : tr("set the room main alias to: %1").arg(e.alias()); return (e.alias().isEmpty()) ? i18n("cleared the room main alias") : i18n("set the room main alias to: %1", e.alias());
}, },
[](const RoomNameEvent &e) { [](const RoomNameEvent &e) {
return (e.name().isEmpty()) ? tr("cleared the room name") : tr("set the room name to: %1").arg(e.name().toHtmlEscaped()); return (e.name().isEmpty()) ? i18n("cleared the room name") : i18n("set the room name to: %1", e.name().toHtmlEscaped());
}, },
[prettyPrint](const RoomTopicEvent &e) { [prettyPrint](const RoomTopicEvent &e) {
return (e.topic().isEmpty()) ? tr("cleared the topic") : tr("set the topic to: %1").arg(prettyPrint ? Quotient::prettyPrint(e.topic()) : e.topic()); return (e.topic().isEmpty()) ? i18n("cleared the topic") : i18n("set the topic to: %1", prettyPrint ? Quotient::prettyPrint(e.topic()) : e.topic());
}, },
[](const RoomAvatarEvent &) { [](const RoomAvatarEvent &) {
return tr("changed the room avatar"); return i18n("changed the room avatar");
}, },
[](const EncryptionEvent &) { [](const EncryptionEvent &) {
return tr("activated End-to-End Encryption"); return i18n("activated End-to-End Encryption");
}, },
[](const RoomCreateEvent &e) { [](const RoomCreateEvent &e) {
return (e.isUpgrade() ? tr("upgraded the room to version %1") : tr("created the room, version %1")).arg(e.version().isEmpty() ? "1" : e.version().toHtmlEscaped()); return e.isUpgrade() ? i18n("upgraded the room to version %1", e.version().isEmpty() ? "1" : e.version().toHtmlEscaped()) : i18n("created the room, version %1", e.version().isEmpty() ? "1" : e.version().toHtmlEscaped());
}, },
[](const StateEventBase &e) { [](const StateEventBase &e) {
// A small hack for state events from TWIM bot // A small hack for state events from TWIM bot
return e.stateKey() == "twim" ? tr("updated the database", "TWIM bot updated the database") return e.stateKey() == "twim" ? i18n("updated the database") : e.stateKey().isEmpty() ? i18n("updated %1 state", e.matrixType()) : i18n("updated %1 state for %2", e.matrixType(), e.stateKey().toHtmlEscaped());
: e.stateKey().isEmpty() ? tr("updated %1 state", "%1 - Matrix event type").arg(e.matrixType())
: tr("updated %1 state for %2", "%1 - Matrix event type, %2 - state key").arg(e.matrixType(), e.stateKey().toHtmlEscaped());
}, },
tr("Unknown event")); i18n("Unknown event"));
} }
void NeoChatRoom::changeAvatar(QUrl localFile) void NeoChatRoom::changeAvatar(QUrl localFile)

View File

@@ -17,6 +17,8 @@
#include <QtMacExtras> #include <QtMacExtras>
#endif #endif
#include <KLocalizedString>
MsgCountComposedIcon::MsgCountComposedIcon(const QString &filename) MsgCountComposedIcon::MsgCountComposedIcon(const QString &filename)
: QIconEngine() : QIconEngine()
{ {
@@ -93,8 +95,8 @@ TrayIcon::TrayIcon(QObject *parent)
: QSystemTrayIcon(parent) : QSystemTrayIcon(parent)
{ {
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
viewAction_ = new QAction(tr("Show"), parent); viewAction_ = new QAction(i18n("Show"), parent);
quitAction_ = new QAction(tr("Quit"), parent); quitAction_ = new QAction(i18n("Quit"), parent);
connect(viewAction_, &QAction::triggered, this, &TrayIcon::showWindow); connect(viewAction_, &QAction::triggered, this, &TrayIcon::showWindow);
connect(quitAction_, &QAction::triggered, this, QApplication::quit); connect(quitAction_, &QAction::triggered, this, QApplication::quit);