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 LUPDATE_H
30#define LUPDATE_H
31
32#include "qglobal.h"
33
34#include <QtCore/QList>
35#include <QtCore/QHash>
36#include <QtCore/QCoreApplication>
37#include <QtCore/QString>
38#include <QtCore/QStringList>
39#include <QtCore/QTranslator>
40
41QT_BEGIN_NAMESPACE
42
43class ConversionData;
44class QStringList;
45class Translator;
46class TranslatorMessage;
47
48enum UpdateOption {
49 Verbose = 1,
50 NoObsolete = 2,
51 PluralOnly = 4,
52 NoSort = 8,
53 HeuristicSameText = 16,
54 HeuristicSimilarText = 32,
55 HeuristicNumber = 64,
56 AbsoluteLocations = 256,
57 RelativeLocations = 512,
58 NoLocations = 1024,
59 NoUiLines = 2048,
60 SourceIsUtf16 = 4096
61};
62
63Q_DECLARE_FLAGS(UpdateOptions, UpdateOption)
64Q_DECLARE_OPERATORS_FOR_FLAGS(UpdateOptions)
65
66Translator merge(
67 const Translator &tor, const Translator &virginTor, const QList<Translator> &aliens,
68 UpdateOptions options, QString &err);
69
70void loadCPP(Translator &translator, const QStringList &filenames, ConversionData &cd);
71bool loadJava(Translator &translator, const QString &filename, ConversionData &cd);
72bool loadUI(Translator &translator, const QString &filename, ConversionData &cd);
73
74#ifndef QT_NO_QML
75bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd);
76bool loadQml(Translator &translator, const QString &filename, ConversionData &cd);
77#endif
78
79#define LUPDATE_FOR_EACH_TR_FUNCTION(UNARY_MACRO) \
80 /* from cpp.cpp */ \
81 UNARY_MACRO(Q_DECLARE_TR_FUNCTIONS) \
82 UNARY_MACRO(QT_TR_N_NOOP) \
83 UNARY_MACRO(QT_TRID_N_NOOP) \
84 UNARY_MACRO(QT_TRANSLATE_N_NOOP) \
85 UNARY_MACRO(QT_TRANSLATE_N_NOOP3) \
86 UNARY_MACRO(QT_TR_NOOP) \
87 UNARY_MACRO(QT_TRID_NOOP) \
88 UNARY_MACRO(QT_TRANSLATE_NOOP) \
89 UNARY_MACRO(QT_TRANSLATE_NOOP3) \
90 UNARY_MACRO(QT_TR_NOOP_UTF8) \
91 UNARY_MACRO(QT_TRANSLATE_NOOP_UTF8) \
92 UNARY_MACRO(QT_TRANSLATE_NOOP3_UTF8) \
93 UNARY_MACRO(findMessage) /* QTranslator::findMessage() has the same parameters as QApplication::translate() */ \
94 UNARY_MACRO(qtTrId) \
95 UNARY_MACRO(tr) \
96 UNARY_MACRO(trUtf8) \
97 UNARY_MACRO(translate) \
98 /* from qdeclarative.cpp: */ \
99 UNARY_MACRO(qsTr) \
100 UNARY_MACRO(qsTrId) \
101 UNARY_MACRO(qsTranslate) \
102 /*end*/
103
104class ParserTool
105{
106public:
107 static QString transcode(const QString &str);
108};
109
110class TrFunctionAliasManager {
111public:
112 TrFunctionAliasManager();
113 ~TrFunctionAliasManager();
114
115 enum TrFunction {
116 // need to uglify names b/c most of the names are themselves macros:
117#define MAKE_ENTRY(F) Function_##F,
118 LUPDATE_FOR_EACH_TR_FUNCTION(MAKE_ENTRY)
119#undef MAKE_ENTRY
120 NumTrFunctions
121 };
122
123 enum Operation { AddAlias, SetAlias };
124
125 int trFunctionByName(const QString &trFunctionName) const;
126
127 void modifyAlias(int trFunction, const QString &alias, Operation op);
128
129 bool isAliasFor(const QString &identifier, TrFunction trFunction) const
130 { return m_trFunctionAliases[trFunction].contains(str: identifier); }
131
132 QStringList availableFunctionsWithAliases() const;
133
134private:
135 void ensureTrFunctionHashUpdated() const;
136
137private:
138 QStringList m_trFunctionAliases[NumTrFunctions];
139 mutable QHash<QString,TrFunction> m_nameToTrFunctionMap;
140};
141
142class LU {
143 Q_DECLARE_TR_FUNCTIONS(LUpdate)
144};
145
146QT_END_NAMESPACE
147
148extern QT_PREPEND_NAMESPACE(TrFunctionAliasManager) trFunctionAliasManager;
149
150#endif
151

source code of qttools/src/linguist/lupdate/lupdate.h