1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef TRANSLATORMESSAGE_H |
5 | #define TRANSLATORMESSAGE_H |
6 | |
7 | #include <QString> |
8 | #include <QStringList> |
9 | #include <QHash> |
10 | |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | enum TranslatorSaveMode { SaveEverything, SaveStripped }; |
15 | |
16 | class TranslatorMessage |
17 | { |
18 | public: |
19 | enum Type { Unfinished, Finished, Vanished, Obsolete }; |
20 | typedef QHash<QString, QString> ; |
21 | class Reference |
22 | { |
23 | QString m_fileName; |
24 | int m_lineNumber; |
25 | public: |
26 | Reference(const QString &n, int l) : m_fileName(n), m_lineNumber(l) {} |
27 | bool operator==(const Reference &other) const |
28 | { return fileName() == other.fileName() && lineNumber() == other.lineNumber(); } |
29 | QString fileName() const { return m_fileName; } |
30 | int lineNumber() const { return m_lineNumber; } |
31 | }; |
32 | typedef QList<Reference> References; |
33 | |
34 | TranslatorMessage(); |
35 | TranslatorMessage(const QString &context, const QString &sourceText, |
36 | const QString &, const QString &userData, |
37 | const QString &fileName, int lineNumber, |
38 | const QStringList &translations = QStringList(), |
39 | Type type = Unfinished, bool plural = false); |
40 | |
41 | uint hash() const; |
42 | |
43 | QString id() const { return m_id; } |
44 | void setId(const QString &id) { m_id = id; } |
45 | |
46 | QString context() const { return m_context; } |
47 | void setContext(const QString &context) { m_context = context; } |
48 | |
49 | QString sourceText() const { return m_sourcetext; } |
50 | void setSourceText(const QString &sourcetext) { m_sourcetext = sourcetext; } |
51 | QString oldSourceText() const { return m_oldsourcetext; } |
52 | void setOldSourceText(const QString &oldsourcetext) { m_oldsourcetext = oldsourcetext; } |
53 | |
54 | QString () const { return m_comment; } |
55 | void (const QString &) { m_comment = comment; } |
56 | QString () const { return m_oldcomment; } |
57 | void (const QString &) { m_oldcomment = oldcomment; } |
58 | |
59 | QStringList translations() const { return m_translations; } |
60 | void setTranslations(const QStringList &translations) { m_translations = translations; } |
61 | QString translation() const { return m_translations.value(i: 0); } |
62 | void setTranslation(const QString &translation) { m_translations = QStringList(translation); } |
63 | void appendTranslation(const QString &translation) { m_translations.append(t: translation); } |
64 | bool isTranslated() const |
65 | { |
66 | for (const QString &trans : m_translations) |
67 | if (!trans.isEmpty()) |
68 | return true; |
69 | return false; |
70 | } |
71 | |
72 | QString fileName() const { return m_fileName; } |
73 | void setFileName(const QString &fileName) { m_fileName = fileName; } |
74 | int lineNumber() const { return m_lineNumber; } |
75 | void setLineNumber(int lineNumber) { m_lineNumber = lineNumber; } |
76 | int tsLineNumber() const { return m_tsLineNumber; } |
77 | void setTsLineNumber(int lineNumber) { m_tsLineNumber = lineNumber; } |
78 | void clearReferences(); |
79 | void setReferences(const References &refs); |
80 | void addReference(const QString &fileName, int lineNumber); |
81 | void addReference(const Reference &ref) { addReference(fileName: ref.fileName(), lineNumber: ref.lineNumber()); } |
82 | void addReferenceUniq(const QString &fileName, int lineNumber); |
83 | References () const { return m_extraRefs; } |
84 | References allReferences() const; |
85 | QString userData() const { return m_userData; } |
86 | void setUserData(const QString &userData) { m_userData = userData; } |
87 | QString () const { return m_extraComment; } |
88 | void (const QString &) { m_extraComment = extraComment; } |
89 | QString () const { return m_translatorComment; } |
90 | void (const QString &) { m_translatorComment = translatorComment; } |
91 | QString warning() const {return m_warning;} |
92 | void setWarning(const QString &warning) {m_warning = warning;} |
93 | |
94 | |
95 | bool isNull() const { return m_sourcetext.isNull() && m_lineNumber == -1 && m_translations.isEmpty(); } |
96 | |
97 | Type type() const { return m_type; } |
98 | void setType(Type t) { m_type = t; } |
99 | bool isPlural() const { return m_plural; } |
100 | void setPlural(bool isplural) { m_plural = isplural; } |
101 | |
102 | // note: use '<fileformat>:' as prefix for file format specific members, |
103 | // e.g. "po-msgid_plural" |
104 | QString (const QString &ba) const; |
105 | void (const QString &ba, const QString &var); |
106 | bool (const QString &ba) const; |
107 | const ExtraData &() const { return m_extra; } |
108 | void (const ExtraData &) { m_extra = extras; } |
109 | void (const QString &key); |
110 | |
111 | bool warningOnly() const { return m_warningOnly; } |
112 | void setWarningOnly(bool isWarningOnly) { m_warningOnly = isWarningOnly; } |
113 | |
114 | void dump() const; |
115 | |
116 | private: |
117 | QString m_id; |
118 | QString m_context; |
119 | QString m_sourcetext; |
120 | QString m_oldsourcetext; |
121 | QString ; |
122 | QString ; |
123 | QString m_userData; |
124 | ExtraData ; // PO flags, PO plurals |
125 | QString ; |
126 | QString ; |
127 | QString m_warning; |
128 | QStringList m_translations; |
129 | QString m_fileName; |
130 | int m_lineNumber; |
131 | int m_tsLineNumber = -1; |
132 | References ; |
133 | bool m_warningOnly = false; |
134 | |
135 | Type m_type; |
136 | bool m_plural; |
137 | }; |
138 | |
139 | Q_DECLARE_TYPEINFO(TranslatorMessage, Q_RELOCATABLE_TYPE); |
140 | |
141 | QT_END_NAMESPACE |
142 | |
143 | #endif // TRANSLATORMESSAGE_H |
144 | |