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 
11 namespace cutehmi {
12 
16 class CUTEHMI_API Internationalizer:
17  public QObject,
18  public Singleton<Internationalizer>
19 {
20  Q_OBJECT
21 
23  friend class test_Internationalizer;
24 
25  public:
29  Q_PROPERTY(QString uiLanguage READ uiLanguage WRITE setUILanguage NOTIFY uiLanguageChanged)
30 
31 
35  QString uiLanguage() const;
36 
41  void setUILanguage(const QString & uiLanguage);
42 
46  Q_INVOKABLE void loadQtTranslation();
47 
51  Q_INVOKABLE void unloadQtTranslation();
52 
72  Q_INVOKABLE void loadTranslation(const QString & product, bool dependencies = true);
73 
78  Q_INVOKABLE void unloadTranslation(const QString & product);
79 
85  Q_INVOKABLE void unloadTranslations(bool qt = true);
86 
104  Q_INVOKABLE QStringList standardTranslationDirectories() const;
105 
112  Q_INVOKABLE QStringList additionalTranslationDirectories() const;
113 
120  Q_INVOKABLE void setAdditionalTranslationDirectories(const QStringList & additionalDirectories);
121 
122  signals:
126  void uiLanguageChanged();
127 
128  private:
130 
135  explicit Internationalizer(QObject * parent = nullptr);
136 
137  void loadTranslation(QStringList & skippedProducts, const QString & product, bool dependencies);
138 
139  void updateTranslation(QTranslator & translator, const QString & product, const QStringList & directories);
140 
141  void updateQtTranslation(QTranslator & translator);
142 
143  QString translationFileStem(const QString & product);
144 
145  QStringList translationDirectories() const;
146 
147  struct Members
148  {
149  QLocale uiLanguage;
150  TranslatorsContainer translators;
151  QTranslator * qtTranslator = nullptr;
152  QStringList additionalTranslationDirectories;
153  };
154 
155  MPtr<Members> m;
156 };
157 
158 }
159 
160 #endif
161 
162 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved.
163 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
164 //(c)C: This file is a part of CuteHMI.
165 //(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.
166 //(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.
167 //(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/>.
168 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
169 //(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:
170 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
171 //(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.
QLocale
cutehmi::MPtr< Members >
QObject
cutehmi
Definition: constants.hpp:6
QString
cutehmi::Internationalizer
Internationalization singleton.
Definition: Internationalizer.hpp:16
QMap< QString, QTranslator * >
QTranslator
cutehmi::Singleton
Singleton template.
Definition: Singleton.hpp:29
QStringList