1 /* 2 SPDX-FileCopyrightText: 2010-2013 Graeme Gott <graeme@gottcode.org> 3 4 SPDX-License-Identifier: GPL-3.0-or-later 5 */ 6 7 #ifndef TANGLET_LOCALE_DIALOG_H 8 #define TANGLET_LOCALE_DIALOG_H 9 10 #include <QDialog> 11 class QComboBox; 12 13 /** 14 * @brief Dialog to set application language. 15 * 16 * This class handles setting the application language when the application is 17 * launched, as well as allowing the user to choose a different language for 18 * future launches. 19 */ 20 class LocaleDialog : public QDialog 21 { 22 Q_OBJECT 23 24 public: 25 /** 26 * Construct a dialog to choose application language. 27 * @param parent the parent widget of the dialog 28 */ 29 explicit LocaleDialog(QWidget* parent = nullptr); 30 31 /** 32 * Load the stored language into the application; defaults to system language. 33 * @param appname application name to prepend to translation filenames 34 * @param datadirs locations to search for directory containing translations 35 */ 36 static void loadTranslator(const QString& appname, const QStringList& datadirs = QStringList()); 37 38 /** 39 * Fetch native language name for QLocale name. 40 * @param language QLocale name to look up 41 * @return translated language name 42 */ 43 static QString languageName(const QString& language); 44 45 public slots: 46 /** Override parent function to store application language. */ 47 void accept() override; 48 49 private: 50 /** 51 * Fetch list of application translations. 52 * @return list of QLocale names 53 */ 54 static QStringList findTranslations(); 55 56 private: 57 QComboBox* m_translations; /**< list of found translations */ 58 59 static QString m_current; /**< stored application language */ 60 static QString m_path; /**< location of translations; found in loadTranslator() */ 61 static QString m_appname; /**< application name passed to loadTranslator() */ 62 }; 63 64 #endif // TANGLET_LOCALE_DIALOG_H 65