Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 61d1d9a0 authored by Simon Depiets's avatar Simon Depiets

Only display the first line of messages in the catalog

BUG:402931
parent 011e1f48
......@@ -198,11 +198,11 @@ QString Catalog::msgid(const DocPosition& pos) const
return m_storage->source(alterForSinglePlural(this, pos));
}
QString Catalog::msgidWithPlurals(const DocPosition& pos) const
QString Catalog::msgidWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
if (Q_UNLIKELY(!m_storage))
return QString();
return m_storage->sourceWithPlurals(pos);
return m_storage->sourceWithPlurals(pos, truncateFirstLine);
}
QString Catalog::msgstr(const DocPosition& pos) const
......@@ -213,12 +213,12 @@ QString Catalog::msgstr(const DocPosition& pos) const
return m_storage->target(pos);
}
QString Catalog::msgstrWithPlurals(const DocPosition& pos) const
QString Catalog::msgstrWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
if (Q_UNLIKELY(!m_storage))
return QString();
return m_storage->targetWithPlurals(pos);
return m_storage->targetWithPlurals(pos, truncateFirstLine);
}
......
......@@ -84,8 +84,8 @@ public:
QString msgid(const DocPosition&) const;
virtual QString msgstr(const DocPosition&) const;
QString msgidWithPlurals(const DocPosition&) const;
QString msgstrWithPlurals(const DocPosition&) const;
QString msgidWithPlurals(const DocPosition&, bool truncateFirstLine) const;
QString msgstrWithPlurals(const DocPosition&, bool truncateFirstLine) const;
static QStringList supportedExtensions();
static bool extIsSupported(const QString& path);
......
......@@ -69,8 +69,8 @@ public:
**/
virtual QString source(const DocPosition& pos) const = 0;
virtual QString target(const DocPosition& pos) const = 0;
virtual QString sourceWithPlurals(const DocPosition& pos) const = 0;
virtual QString targetWithPlurals(const DocPosition& pos) const = 0;
virtual QString sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const = 0;
virtual QString targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const = 0;
virtual CatalogString sourceWithTags(DocPosition pos) const = 0;
virtual CatalogString targetWithTags(DocPosition pos) const = 0;
virtual CatalogString catalogString(const DocPosition& pos) const = 0;
......
......@@ -177,36 +177,64 @@ QString GettextStorage::target(const DocPosition& pos) const
{
return m_entries.at(pos.entry).msgstr(pos.form);
}
QString GettextStorage::sourceWithPlurals(const DocPosition& pos) const
QString GettextStorage::sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
if (m_entries.at(pos.entry).isPlural()) {
const QVector<QString> plurals = m_entries.at(pos.entry).msgidPlural();
QString pluralString;
for (int i = 0; i < plurals.size(); i++) {
pluralString += plurals.at(i);
QString str = plurals.at(i);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
pluralString += str;
if (i != plurals.size() - 1) {
pluralString += '|';
}
}
return pluralString;
} else {
return m_entries.at(pos.entry).msgid(pos.form);
QString str = m_entries.at(pos.entry).msgid(pos.form);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
return str;
}
}
QString GettextStorage::targetWithPlurals(const DocPosition& pos) const
QString GettextStorage::targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
if (m_entries.at(pos.entry).isPlural()) {
const QVector<QString> plurals = m_entries.at(pos.entry).msgstrPlural();
QString pluralString;
for (int i = 0; i < plurals.size(); i++) {
pluralString += plurals.at(i);
QString str = plurals.at(i);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
pluralString += str;
if (i != plurals.size() - 1) {
pluralString += '|';
}
}
return pluralString;
} else {
return m_entries.at(pos.entry).msgstr(pos.form);
QString str = m_entries.at(pos.entry).msgstr(pos.form);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
return str;
}
}
......
......@@ -56,8 +56,8 @@ public:
//flat-model interface (ignores XLIFF grouping)
QString source(const DocPosition& pos) const override;
QString target(const DocPosition& pos) const override;
QString sourceWithPlurals(const DocPosition& pos) const override;
QString targetWithPlurals(const DocPosition& pos) const override;
QString sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const override;
QString targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const override;
CatalogString sourceWithTags(DocPosition pos) const override;
CatalogString targetWithTags(DocPosition pos) const override;
CatalogString catalogString(const DocPosition& pos) const override
......
......@@ -278,13 +278,27 @@ QString TsStorage::target(const DocPosition& pos) const
return content(targetForPos(pos));
}
QString TsStorage::sourceWithPlurals(const DocPosition& pos) const
{
return source(pos);
QString TsStorage::sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
QString str = source(pos);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
return str;
}
QString TsStorage::targetWithPlurals(const DocPosition& pos) const
QString TsStorage::targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
return target(pos);
QString str = target(pos);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
return str;
}
......
......@@ -46,8 +46,8 @@ public:
//flat-model interface (ignores TS grouping)
QString source(const DocPosition& pos) const override;
QString target(const DocPosition& pos) const override;
QString sourceWithPlurals(const DocPosition& pos) const override;
QString targetWithPlurals(const DocPosition& pos) const override;
QString sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const override;
QString targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const override;
CatalogString targetWithTags(DocPosition pos) const override;
CatalogString sourceWithTags(DocPosition pos) const override;
CatalogString catalogString(const DocPosition& pos) const override;
......
......@@ -509,13 +509,27 @@ QString XliffStorage::target(const DocPosition& pos) const
{
return genericContent(targetForPos(pos.entry), pos.entry < size());
}
QString XliffStorage::sourceWithPlurals(const DocPosition& pos) const
QString XliffStorage::sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
return source(pos);
QString str = source(pos);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
return str;
}
QString XliffStorage::targetWithPlurals(const DocPosition& pos) const
QString XliffStorage::targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const
{
return target(pos);
QString str = target(pos);
if (truncateFirstLine)
{
int truncatePos = str.indexOf("\n");
if (truncatePos != -1)
str.truncate(truncatePos);
}
return str;
}
......
......@@ -47,8 +47,8 @@ public:
//flat-model interface (ignores XLIFF grouping)
QString source(const DocPosition& pos) const override;
QString target(const DocPosition& pos) const override;
QString sourceWithPlurals(const DocPosition& pos) const override;
QString targetWithPlurals(const DocPosition& pos) const override;
QString sourceWithPlurals(const DocPosition& pos, bool truncateFirstLine) const override;
QString targetWithPlurals(const DocPosition& pos, bool truncateFirstLine) const override;
CatalogString targetWithTags(DocPosition pos) const override;
CatalogString sourceWithTags(DocPosition pos) const override;
CatalogString catalogString(const DocPosition& pos) const override;
......
......@@ -159,7 +159,7 @@ QVariant CatalogTreeModel::data(const QModelIndex& index, int role) const
if (index.column() >= TranslationStatus)
return QVariant();
else if (index.column() == Source || index.column() == Target) {
QString str = index.column() == Source ? m_catalog->msgidWithPlurals(index.row()) : m_catalog->msgstrWithPlurals(index.row());
QString str = index.column() == Source ? m_catalog->msgidWithPlurals(index.row(), false) : m_catalog->msgstrWithPlurals(index.row(), false);
return m_ignoreAccel ? str.remove(Project::instance()->accel()) : str;
}
role = Qt::DisplayRole;
......@@ -172,9 +172,9 @@ QVariant CatalogTreeModel::data(const QModelIndex& index, int role) const
switch (index.column()) {
case Key: return index.row() + 1;
case Source:
return m_catalog->msgidWithPlurals(index.row());
return m_catalog->msgidWithPlurals(index.row(), true);
case Target:
return m_catalog->msgstrWithPlurals(index.row());
return m_catalog->msgstrWithPlurals(index.row(), true);
case Notes: {
QString result;
foreach (const Note &note, m_catalog->notes(index.row()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment