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