1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Linguist of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef TRANSLATORMESSAGE_H
30#define TRANSLATORMESSAGE_H
31
32#include <QString>
33#include <QStringList>
34#include <QHash>
35
36
37QT_BEGIN_NAMESPACE
38
39enum TranslatorSaveMode { SaveEverything, SaveStripped };
40
41class TranslatorMessage
42{
43public:
44 enum Type { Unfinished, Finished, Vanished, Obsolete };
45 typedef QHash<QString, QString> ExtraData;
46 class Reference
47 {
48 QString m_fileName;
49 int m_lineNumber;
50 public:
51 Reference(const QString &n, int l) : m_fileName(n), m_lineNumber(l) {}
52 bool operator==(const Reference &other) const
53 { return fileName() == other.fileName() && lineNumber() == other.lineNumber(); }
54 QString fileName() const { return m_fileName; }
55 int lineNumber() const { return m_lineNumber; }
56 };
57 typedef QList<Reference> References;
58
59 TranslatorMessage();
60 TranslatorMessage(const QString &context, const QString &sourceText,
61 const QString &comment, const QString &userData,
62 const QString &fileName, int lineNumber,
63 const QStringList &translations = QStringList(),
64 Type type = Unfinished, bool plural = false);
65
66 uint hash() const;
67
68 QString id() const { return m_id; }
69 void setId(const QString &id) { m_id = id; }
70
71 QString context() const { return m_context; }
72 void setContext(const QString &context) { m_context = context; }
73
74 QString sourceText() const { return m_sourcetext; }
75 void setSourceText(const QString &sourcetext) { m_sourcetext = sourcetext; }
76 QString oldSourceText() const { return m_oldsourcetext; }
77 void setOldSourceText(const QString &oldsourcetext) { m_oldsourcetext = oldsourcetext; }
78
79 QString comment() const { return m_comment; }
80 void setComment(const QString &comment) { m_comment = comment; }
81 QString oldComment() const { return m_oldcomment; }
82 void setOldComment(const QString &oldcomment) { m_oldcomment = oldcomment; }
83
84 QStringList translations() const { return m_translations; }
85 void setTranslations(const QStringList &translations) { m_translations = translations; }
86 QString translation() const { return m_translations.value(i: 0); }
87 void setTranslation(const QString &translation) { m_translations = QStringList(translation); }
88 void appendTranslation(const QString &translation) { m_translations.append(t: translation); }
89 bool isTranslated() const
90 {
91 foreach (const QString &trans, m_translations)
92 if (!trans.isEmpty())
93 return true;
94 return false;
95 }
96
97 QString fileName() const { return m_fileName; }
98 void setFileName(const QString &fileName) { m_fileName = fileName; }
99 int lineNumber() const { return m_lineNumber; }
100 void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; }
101 void clearReferences();
102 void setReferences(const References &refs);
103 void addReference(const QString &fileName, int lineNumber);
104 void addReference(const Reference &ref) { addReference(fileName: ref.fileName(), lineNumber: ref.lineNumber()); }
105 void addReferenceUniq(const QString &fileName, int lineNumber);
106 References extraReferences() const { return m_extraRefs; }
107 References allReferences() const;
108 QString userData() const { return m_userData; }
109 void setUserData(const QString &userData) { m_userData = userData; }
110 QString extraComment() const { return m_extraComment; }
111 void setExtraComment(const QString &extraComment) { m_extraComment = extraComment; }
112 QString translatorComment() const { return m_translatorComment; }
113 void setTranslatorComment(const QString &translatorComment) { m_translatorComment = translatorComment; }
114
115 bool isNull() const { return m_sourcetext.isNull() && m_lineNumber == -1 && m_translations.isEmpty(); }
116
117 Type type() const { return m_type; }
118 void setType(Type t) { m_type = t; }
119 bool isPlural() const { return m_plural; }
120 void setPlural(bool isplural) { m_plural = isplural; }
121
122 // note: use '<fileformat>:' as prefix for file format specific members,
123 // e.g. "po-msgid_plural"
124 QString extra(const QString &ba) const;
125 void setExtra(const QString &ba, const QString &var);
126 bool hasExtra(const QString &ba) const;
127 const ExtraData &extras() const { return m_extra; }
128 void setExtras(const ExtraData &extras) { m_extra = extras; }
129 void unsetExtra(const QString &key);
130
131 void dump() const;
132
133private:
134 QString m_id;
135 QString m_context;
136 QString m_sourcetext;
137 QString m_oldsourcetext;
138 QString m_comment;
139 QString m_oldcomment;
140 QString m_userData;
141 ExtraData m_extra; // PO flags, PO plurals
142 QString m_extraComment;
143 QString m_translatorComment;
144 QStringList m_translations;
145 QString m_fileName;
146 int m_lineNumber;
147 References m_extraRefs;
148
149 Type m_type;
150 bool m_plural;
151};
152
153Q_DECLARE_TYPEINFO(TranslatorMessage, Q_MOVABLE_TYPE);
154
155QT_END_NAMESPACE
156
157#endif // TRANSLATORMESSAGE_H
158

source code of qttools/src/linguist/shared/translatormessage.h