CuteHMI - CuteHMI (CuteHMI.2)
Internationalizer.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_2_INCLUDE_CUTEHMI_INTERNATIONALIZER_HPP
2#define H_EXTENSIONS_CUTEHMI_2_INCLUDE_CUTEHMI_INTERNATIONALIZER_HPP
3
4#include "internal/common.hpp"
5#include "Singleton.hpp"
6
7#include <QObject>
8#include <QMap>
9#include <QTranslator>
10
11namespace cutehmi {
12
16class CUTEHMI_API Internationalizer:
17 public QObject,
18 public Singleton<Internationalizer>
19{
20 Q_OBJECT
21 //<CuteHMI.Workarounds.Qt5Compatibility-4.workaround target="Qt" cause="Qt5.15-QML_SINGLETON">
22#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
23 QML_NAMED_ELEMENT(Internationalizer)
24 QML_UNCREATABLE("Internationalizer is a singleton")
25 QML_SINGLETON
26#endif
27 //</CuteHMI.Workarounds.Qt5Compatibility-4.workaround>
28
29 friend class Singleton<Internationalizer>;
30 friend class test_Internationalizer;
31
32 public:
36 Q_PROPERTY(QString uiLanguage READ uiLanguage WRITE setUILanguage NOTIFY uiLanguageChanged)
37
38
46 static Internationalizer * create(QQmlEngine * qmlEngine, QJSEngine * jsEngine);
47
52 QString uiLanguage() const;
53
58 void setUILanguage(const QString & uiLanguage);
59
63 Q_INVOKABLE void loadQtTranslation();
64
68 Q_INVOKABLE void unloadQtTranslation();
69
89 Q_INVOKABLE void loadTranslation(const QString & product, bool dependencies = true);
90
95 Q_INVOKABLE void unloadTranslation(const QString & product);
96
102 Q_INVOKABLE void unloadTranslations(bool qt = true);
103
121 Q_INVOKABLE QStringList standardTranslationDirectories() const;
122
129 Q_INVOKABLE QStringList additionalTranslationDirectories() const;
130
137 Q_INVOKABLE void setAdditionalTranslationDirectories(const QStringList & additionalDirectories);
138
139 signals:
144
145 private:
147
152 explicit Internationalizer(QObject * parent = nullptr);
153
154 void loadTranslation(QStringList & skippedProducts, const QString & product, bool dependencies);
155
156 void updateTranslation(QTranslator & translator, const QString & product, const QStringList & directories);
157
158 void updateQtTranslation(QTranslator & translator);
159
160 QString translationFileStem(const QString & product);
161
162 QStringList translationDirectories() const;
163
164 struct Members
165 {
166 QLocale uiLanguage;
167 TranslatorsContainer translators;
168 QTranslator * qtTranslator = nullptr;
169 QStringList additionalTranslationDirectories;
170 };
171
173};
174
175}
176
177#endif
178
179//(c)C: Copyright © 2020-2022, Michał Policht <michal@policht.pl>. All rights reserved.
180//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
181//(c)C: This file is a part of CuteHMI.
182//(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
183//(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
184//(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
185//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
186//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
187//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
188//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Internationalization singleton.
Definition: Internationalizer.hpp:19
void uiLanguageChanged()
User interface language has changed.
Singleton template.
Definition: Singleton.hpp:32
Definition: constants.hpp:6