1 /* 2 * \brief Loads translation files for different languages. 3 * 4 * \copyright Copyright (c) 2014-2021 Governikus GmbH & Co. KG, Germany 5 */ 6 7 #pragma once 8 9 #include <QLocale> 10 #include <QPointer> 11 #include <QSharedPointer> 12 #include <QTranslator> 13 #include <QVector> 14 15 class test_LanguageLoader; 16 class test_ProviderParser; 17 class test_ProviderConfigurationParser; 18 19 namespace governikus 20 { 21 22 class LanguageLoader 23 { 24 private: 25 friend class ::test_LanguageLoader; 26 friend class ::test_ProviderConfigurationParser; 27 static const QLocale::Language mFallbackLanguage; 28 static QLocale mDefaultLanguage; 29 30 QString mPath; 31 QVector<QSharedPointer<QTranslator>> mTranslatorList; 32 const QStringList mComponentList; 33 QLocale mUsedLocale; 34 35 Q_DISABLE_COPY(LanguageLoader) 36 37 bool loadTranslationFiles(const QLocale& pLocale); 38 QSharedPointer<QTranslator> createTranslator(const QLocale& pLocale, const QString& pComponent); 39 40 protected: 41 LanguageLoader(); 42 ~LanguageLoader(); 43 44 public: 45 static const QLocale& getDefaultLanguage(); 46 static void setDefaultLanguage(const QLocale& pLocale); 47 static LanguageLoader& getInstance(); 48 static QString getLocalCode(const QLocale& pLocale = getInstance().getUsedLocale()); 49 50 #ifndef QT_NO_DEBUG 51 [[nodiscard]] const QString& getPath() const; 52 void setPath(const QString& pPath); 53 #endif 54 55 void load(const QLocale& pLocale = getDefaultLanguage()); 56 void unload(); 57 [[nodiscard]] bool isLoaded() const; 58 [[nodiscard]] const QLocale& getUsedLocale() const; 59 [[nodiscard]] QLocale::Language getFallbackLanguage() const; 60 [[nodiscard]] QList<QLocale> getAvailableLocales() const; 61 }; 62 63 } // namespace governikus 64