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