initial code translation preparation, russian localization

This commit is contained in:
Blue 2019-10-05 14:27:39 +03:00
parent 746fdef013
commit 8afdb81314
14 changed files with 781 additions and 75 deletions

View file

@ -151,7 +151,7 @@ QVariant Models::Account::data(int column) const
case 1:
return server;
case 2:
return Shared::connectionStateNames[state];
return QCoreApplication::translate("Global", Shared::connectionStateNames[state].toLatin1());
case 3:
return error;
case 4:
@ -159,7 +159,7 @@ QVariant Models::Account::data(int column) const
case 5:
return password;
case 6:
return Shared::availabilityNames[availability];
return QCoreApplication::translate("Global", Shared::availabilityNames[availability].toLatin1());
case 7:
return resource;
default:

View file

@ -20,13 +20,9 @@
#include "../../global.h"
#include <QIcon>
#include <QDebug>
std::deque<QString> Models::Accounts::columns = {
"name",
"server",
"state",
"error"
};
std::deque<QString> Models::Accounts::columns = {"Name", "Server", "State", "Error"};
Models::Accounts::Accounts(QObject* parent):
QAbstractTableModel(parent),
@ -72,7 +68,7 @@ int Models::Accounts::rowCount ( const QModelIndex& parent ) const
QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
return columns[section];
return tr(columns[section].toLatin1());
}
return QVariant();
}
@ -81,7 +77,18 @@ QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation,
void Models::Accounts::addAccount(Account* account)
{
beginInsertRows(QModelIndex(), accs.size(), accs.size());
accs.push_back(account);
int index = 0;
std::deque<Account*>::const_iterator before = accs.begin();
while (before != accs.end()) {
Account* bfr = *before;
if (bfr->getDisplayedName() > account->getDisplayedName()) {
break;
}
index++;
before++;
}
accs.insert(before, account);
connect(account, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onAccountChanged(Models::Item*, int, int)));
endInsertRows();
@ -96,8 +103,32 @@ void Models::Accounts::onAccountChanged(Item* item, int row, int col)
return; //it means the signal is emitted by one of accounts' children, not exactly him, this model has no interest in that
}
if (col == 0) {
int newRow = 0;
std::deque<Account*>::const_iterator before = accs.begin();
while (before != accs.end()) {
Item* bfr = *before;
if (bfr->getDisplayedName() > item->getDisplayedName()) {
break;
}
newRow++;
before++;
}
if (newRow != row || (before != accs.end() && *before != item)) {
emit beginMoveRows(createIndex(row, 0), row, row, createIndex(newRow, 0), newRow);
std::deque<Account*>::const_iterator old = accs.begin();
old += row;
accs.erase(old);
accs.insert(before, acc);
emit endMoveRows();
row = newRow;
}
}
if (col < columnCount(QModelIndex())) {
emit dataChanged(createIndex(row, col, this), createIndex(row, col, this));
emit dataChanged(createIndex(row, col), createIndex(row, col));
}
emit changed();
}

View file

@ -193,15 +193,15 @@ QString Models::Room::getStatusText() const
{
if (autoJoin) {
if (joined) {
return "Subscribed";
return tr("Subscribed");
} else {
return "Temporarily unsubscribed";
return tr("Temporarily unsubscribed");
}
} else {
if (joined) {
return "Temporarily subscribed";
return tr("Temporarily subscribed");
} else {
return "Unsubscribed";
return tr("Unsubscribed");
}
}
}

View file

@ -21,8 +21,6 @@
#include <QIcon>
#include <QFont>
using namespace Models;
Models::Roster::Roster(QObject* parent):
QAbstractItemModel(parent),
accountsModel(new Accounts()),
@ -78,7 +76,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
str += gr->getName();
unsigned int amount = gr->getUnreadMessages();
if (amount > 0) {
str += QString(" (") + "New messages" + ")";
str += QString(" (") + tr("New messages") + ")";
}
result = str;
@ -143,7 +141,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
switch (item->type) {
case Item::account: {
Account* acc = static_cast<Account*>(item);
result = QString(Shared::availabilityNames[acc->getAvailability()]);
result = QCoreApplication::translate("Global", Shared::availabilityNames[acc->getAvailability()].toLatin1());
}
break;
case Item::contact: {
@ -151,22 +149,22 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
QString str("");
int mc = contact->getMessagesCount();
if (mc > 0) {
str += QString("New messages: ") + std::to_string(mc).c_str() + "\n";
str += QString(tr("New messages: ")) + std::to_string(mc).c_str() + "\n";
}
str += "Jabber ID: " + contact->getJid() + "\n";
str += tr("Jabber ID: ") + contact->getJid() + "\n";
Shared::SubscriptionState ss = contact->getState();
if (ss == Shared::both) {
Shared::Availability av = contact->getAvailability();
str += "Availability: " + Shared::availabilityNames[av];
str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1());
if (av != Shared::offline) {
QString s = contact->getStatus();
if (s.size() > 0) {
str += "\nStatus: " + s;
str += "\n" + tr("Status: ") + s;
}
}
str += "\nSubscription: " + Shared::subscriptionStateNames[ss];
str += "\n" + tr("Subscription: ") + QCoreApplication::translate("Global", Shared::subscriptionStateNames[ss].toLatin1());
} else {
str += "Subscription: " + Shared::subscriptionStateNames[ss];
str += tr("Subscription: ") + QCoreApplication::translate("Global", Shared::subscriptionStateNames[ss].toLatin1());
}
result = str;
@ -177,13 +175,13 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
QString str("");
int mc = contact->getMessagesCount();
if (mc > 0) {
str += QString("New messages: ") + std::to_string(mc).c_str() + "\n";
str += tr("New messages: ") + std::to_string(mc).c_str() + "\n";
}
Shared::Availability av = contact->getAvailability();
str += "Availability: " + Shared::availabilityNames[av];
str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1());
QString s = contact->getStatus();
if (s.size() > 0) {
str += "\nStatus: " + s;
str += "\n" + tr("Status: ") + s;
}
result = str;
@ -193,14 +191,18 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
Participant* p = static_cast<Participant*>(item);
QString str("");
Shared::Availability av = p->getAvailability();
str += "Availability: " + Shared::availabilityNames[av] + "\n";
str += tr("Availability: ") + QCoreApplication::translate("Global", Shared::availabilityNames[av].toLatin1()) + "\n";
QString s = p->getStatus();
if (s.size() > 0) {
str += "Status: " + s + "\n";
str += tr("Status: ") + s + "\n";
}
str += "Affiliation: " + Shared::affiliationNames[static_cast<unsigned int>(p->getAffiliation())] + "\n";
str += "Role: " + Shared::roleNames[static_cast<unsigned int>(p->getRole())];
str += tr("Affiliation: ") +
QCoreApplication::translate("Global",
Shared::affiliationNames[static_cast<unsigned int>(p->getAffiliation())].toLatin1()) + "\n";
str += tr("Role: ") +
QCoreApplication::translate("Global",
Shared::roleNames[static_cast<unsigned int>(p->getRole())].toLatin1());
result = str;
}
@ -210,10 +212,10 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
unsigned int count = gr->getUnreadMessages();
QString str("");
if (count > 0) {
str += QString("New messages: ") + std::to_string(count).c_str() + "\n";
str += tr("New messages: ") + std::to_string(count).c_str() + "\n";
}
str += QString("Online contacts: ") + std::to_string(gr->getOnlineContacts()).c_str() + "\n";
str += QString("Total contacts: ") + std::to_string(gr->childCount()).c_str();
str += tr("Online contacts: ") + std::to_string(gr->getOnlineContacts()).c_str() + "\n";
str += tr("Total contacts: ") + std::to_string(gr->childCount()).c_str();
result = str;
}
break;
@ -222,11 +224,11 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
unsigned int count = rm->getUnreadMessagesCount();
QString str("");
if (count > 0) {
str += QString("New messages: ") + std::to_string(count).c_str() + "\n";
str += tr("New messages: ") + std::to_string(count).c_str() + "\n";
}
str += QString("Subscription: ") + rm->getStatusText();
str += tr("Subscription: ") + rm->getStatusText();
if (rm->getJoined()) {
str += QString("\nMembers: ") + std::to_string(rm->childCount()).c_str();
str += QString("\n") + tr("Members: ") + std::to_string(rm->childCount()).c_str();
}
result = str;
}