Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
translatormessage.h
Go to the documentation of this file.
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
12QT_BEGIN_NAMESPACE
13
14enum TranslatorSaveMode { SaveEverything, SaveStripped };
15
17{
18public:
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 };
33
35 TranslatorMessage(const QString &context, const QString &sourceText,
36 const QString &comment, 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 comment() const { return m_comment; }
55 void setComment(const QString &comment) { m_comment = comment; }
56 QString oldComment() const { return m_oldcomment; }
57 void setOldComment(const QString &oldcomment) { 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(0); }
62 void setTranslation(const QString &translation) { m_translations = QStringList(translation); }
63 void appendTranslation(const QString &translation) { m_translations.append(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(ref.fileName(), ref.lineNumber()); }
82 void addReferenceUniq(const QString &fileName, int lineNumber);
83 References extraReferences() const { return m_extraRefs; }
85 QString userData() const { return m_userData; }
86 void setUserData(const QString &userData) { m_userData = userData; }
87 QString extraComment() const { return m_extraComment; }
88 void setExtraComment(const QString &extraComment) { m_extraComment = extraComment; }
89 QString translatorComment() const { return m_translatorComment; }
90 void setTranslatorComment(const QString &translatorComment) { 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 extra(const QString &ba) const;
105 void setExtra(const QString &ba, const QString &var);
106 bool hasExtra(const QString &ba) const;
107 const ExtraData &extras() const { return m_extra; }
108 void setExtras(const ExtraData &extras) { m_extra = extras; }
109 void unsetExtra(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
116private:
117 QString m_id;
118 QString m_context;
119 QString m_sourcetext;
120 QString m_oldsourcetext;
121 QString m_comment;
122 QString m_oldcomment;
123 QString m_userData;
124 ExtraData m_extra; // PO flags, PO plurals
125 QString m_extraComment;
126 QString m_translatorComment;
127 QString m_warning;
128 QStringList m_translations;
129 QString m_fileName;
130 int m_lineNumber;
131 int m_tsLineNumber = -1;
132 References m_extraRefs;
133 bool m_warningOnly = false;
134
135 Type m_type;
136 bool m_plural;
137};
138
140
141QT_END_NAMESPACE
142
143#endif // TRANSLATORMESSAGE_H
int main(int argc, char *argv[])
[2]
Definition buffer.cpp:77
QString m_defaultContext
Definition translator.h:51
void clearErrors()
Definition translator.h:48
QString m_unTrPrefix
Definition translator.h:53
QString m_targetFileName
Definition translator.h:55
bool sortContexts() const
Definition translator.h:43
QVector< QRegularExpression > m_excludes
Definition translator.h:57
const QDir & targetDir() const
Definition translator.h:40
QStringList m_dropTags
Definition translator.h:63
QString m_sourceFileName
Definition translator.h:54
QString error() const
Definition translator.h:46
const QStringList & dropTags() const
Definition translator.h:38
QStringList m_rootDirs
Definition translator.h:71
bool isVerbose() const
Definition translator.h:41
QSet< QString > m_projectRoots
Definition translator.h:60
QStringList & dropTags()
Definition translator.h:39
TranslatorSaveMode m_saveMode
Definition translator.h:70
QMultiHash< QString, QString > m_allCSources
Definition translator.h:61
bool m_sortContexts
Definition translator.h:67
QStringList errors() const
Definition translator.h:47
bool ignoreUnfinished() const
Definition translator.h:42
void appendError(const QString &error)
Definition translator.h:45
bool m_ignoreUnfinished
Definition translator.h:66
QStringList m_includePath
Definition translator.h:62
bool m_sourceIsUtf16
Definition translator.h:52
QString m_compilationDatabaseDir
Definition translator.h:56
QStringList m_errors
Definition translator.h:64
QString source
Definition translator.h:80
bool operator==(const TMMKey &o) const
Definition translator.h:78
TMMKey(const TranslatorMessage &msg)
Definition translator.h:76
QString comment
Definition translator.h:80
QString context
Definition translator.h:80
bool operator==(const Reference &other) const
Reference(const QString &n, int l)
void setTranslations(const QStringList &translations)
void setTranslation(const QString &translation)
void setSourceText(const QString &sourcetext)
QList< Reference > References
QString comment() const
void addReference(const QString &fileName, int lineNumber)
QString extraComment() const
TranslatorMessage(const QString &context, const QString &sourceText, const QString &comment, const QString &userData, const QString &fileName, int lineNumber, const QStringList &translations=QStringList(), Type type=Unfinished, bool plural=false)
void setContext(const QString &context)
References extraReferences() const
bool isTranslated() const
void setWarningOnly(bool isWarningOnly)
void setOldSourceText(const QString &oldsourcetext)
void setFileName(const QString &fileName)
QString translatorComment() const
void addReference(const Reference &ref)
void setId(const QString &id)
void setPlural(bool isplural)
void setUserData(const QString &userData)
void addReferenceUniq(const QString &fileName, int lineNumber)
void setTsLineNumber(int lineNumber)
QString sourceText() const
void setWarning(const QString &warning)
References allReferences() const
QString id() const
void setTranslatorComment(const QString &translatorComment)
QStringList translations() const
void setOldComment(const QString &oldcomment)
QString translation() const
void appendTranslation(const QString &translation)
void setReferences(const References &refs)
QHash< QString, QString > ExtraData
QString userData() const
QString extra(const QString &ba) const
void setExtra(const QString &ba, const QString &var)
void setExtras(const ExtraData &extras)
void unsetExtra(const QString &key)
QString context() const
QString warning() const
QString oldComment() const
void setLineNumber(int lineNumber)
const ExtraData & extras() const
QString fileName() const
QString oldSourceText() const
bool hasExtra(const QString &ba) const
void setComment(const QString &comment)
uint hash() const
void setExtraComment(const QString &extraComment)
void setDependencies(const QStringList &dependencies)
Definition translator.h:152
bool(*) LoadFunction(Translator &, QIODevice &in, ConversionData &data)
Definition translator.h:167
static QString makeLanguageCode(QLocale::Language language, QLocale::Territory territory)
void stripObsoleteMessages()
QStringList normalizedTranslations(const TranslatorMessage &m, ConversionData &cd, bool *ok) const
void dropTranslations()
bool save(const QString &filename, ConversionData &err, const QString &format) const
bool load(const QString &filename, ConversionData &err, const QString &format)
static QStringList normalizedTranslations(const TranslatorMessage &m, int numPlurals)
void dropUiLines()
void dump() const
void stripEmptyContexts()
void stripUntranslatedMessages()
void stripFinishedMessages()
void replaceSorted(const TranslatorMessage &msg)
static void languageAndTerritory(QStringView languageCode, QLocale::Language *langPtr, QLocale::Territory *territoryPtr)
void stripNonPluralForms()
void setExtra(const QString &ba, const QString &var)
LocationsType locationsType() const
Definition translator.h:133
void setExtras(const ExtraData &extras)
Definition translator.h:163
bool(*) SaveFunction(const Translator &, QIODevice &out, ConversionData &data)
Definition translator.h:166
const TranslatorMessage & message(int i) const
Definition translator.h:148
int find(const QString &context) const
QString extra(const QString &ba) const
QString languageCode() const
Definition translator.h:128
static void registerFileFormat(const FileFormat &format)
void append(const TranslatorMessage &msg)
static constexpr QChar TextVariantSeparator
Definition translator.h:182
static QString guessLanguageCodeFromFileName(const QString &fileName)
void setLocationsType(LocationsType lt)
Definition translator.h:132
@ RelativeLocations
Definition translator.h:131
@ AbsoluteLocations
Definition translator.h:131
void stripIdenticalSourceTranslations()
static QList< FileFormat > & registeredFileFormats()
int messageCount() const
Definition translator.h:146
void makeFileNamesAbsolute(const QDir &originalPath)
QStringList dependencies() const
Definition translator.h:153
bool translationsExist() const
void setLanguageCode(const QString &languageCode)
Definition translator.h:138
const TranslatorMessage & constMessage(int i) const
Definition translator.h:149
Duplicates resolveDuplicates()
bool hasExtra(const QString &ba) const
void setSourceLanguageCode(const QString &languageCode)
Definition translator.h:139
int find(const QString &context, const QString &comment, const TranslatorMessage::References &refs) const
void normalizeTranslations(ConversionData &cd)
TranslatorMessage & message(int i)
Definition translator.h:147
void appendSorted(const TranslatorMessage &msg)
void reportDuplicatesLines(const TranslatorMessage &msg, const DuplicateEntries::value_type &dups) const
int find(const TranslatorMessage &msg) const
void reportDuplicates(const Duplicates &dupes, const QString &fileName, bool verbose)
const ExtraData & extras() const
Definition translator.h:162
const QList< TranslatorMessage > & messages() const
void extend(const TranslatorMessage &msg, ConversionData &cd)
QString sourceLanguageCode() const
Definition translator.h:129
static constexpr QChar BinaryVariantSeparator
Definition translator.h:183
Combined button and popup list for selecting options.
static QT_USE_NAMESPACE int usage(const QStringList &args)
Definition main.cpp:17
Definition main.cpp:91
QString format
Definition main.cpp:93
QString name
Definition main.cpp:92
DuplicateEntries byContents
Definition translator.h:121
DuplicateEntries byId
Definition translator.h:121
const char * untranslatedDescription
Definition translator.h:171
QString description() const
Definition translator.h:173
size_t qHash(const TMMKey &key)
Definition translator.h:83
bool saveQM(const Translator &translator, QIODevice &dev, ConversionData &cd)
Definition qm.cpp:619
QString getNumerusInfoString()
Definition numerus.cpp:361
Q_DECLARE_TYPEINFO(TMMKey, Q_RELOCATABLE_TYPE)
bool getNumerusInfo(QLocale::Language language, QLocale::Territory territory, QByteArray *rules, QStringList *forms, const char **gettextRules)
Definition numerus.cpp:328
Q_DECLARE_TYPEINFO(TranslatorMessage, Q_RELOCATABLE_TYPE)
TranslatorSaveMode
@ SaveEverything