1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef PROXYTRANSLATOR_H
5#define PROXYTRANSLATOR_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qqmldebugserviceinterfaces_p.h>
19#include <private/qqmlglobal_p.h>
20
21#include <QtCore/qstring.h>
22#include <QtCore/qurl.h>
23#include <QtCore/qtranslator.h>
24
25#include <memory>
26
27QT_BEGIN_NAMESPACE
28
29class ProxyTranslator : public QTranslator
30{
31 Q_OBJECT
32public:
33 QString translate(const char *context, const char *sourceText, const char *disambiguation, int n) const override;
34 bool isEmpty() const override;
35
36 QString currentUILanguages() const;
37 void setLanguage(const QUrl &context, const QLocale &locale);
38 void addEngine(QQmlEngine *engine);
39 void removeEngine(QQmlEngine *engine);
40
41 bool hasTranslation(const TranslationBindingInformation &translationBindingInformation) const;
42 static QString
43 translationFromInformation(const TranslationBindingInformation &translationBindingInformation);
44 static QQmlSourceLocation sourceLocationFromInformation(const TranslationBindingInformation &translationBindingInformation);
45Q_SIGNALS:
46 void languageChanged(const QLocale &locale);
47
48private:
49 void resetTranslationFound() const;
50 bool translationFound() const;
51 QList<QQmlEngine *> m_engines;
52 std::unique_ptr<QTranslator> m_qtTranslator;
53 std::unique_ptr<QTranslator> m_qmlTranslator;
54 bool m_enable = false;
55 QString m_currentUILanguages;
56 mutable bool m_translationFound = false;
57};
58
59QT_END_NAMESPACE
60
61#endif // PROXYTRANSLATOR_H
62

source code of qtdeclarative/src/plugins/qmltooling/qmldbg_preview/proxytranslator.h