2009-07-02 20:28:05 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-02-05 11:45:17 +01:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2009-07-02 20:28:05 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-07-02 20:28:05 +02:00
|
|
|
*/
|
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
#ifndef TRANSLATIONHANDLER_H
|
|
|
|
#define TRANSLATIONHANDLER_H
|
|
|
|
|
2011-02-06 21:00:16 +01:00
|
|
|
#include <QList>
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QObject>
|
2016-01-03 10:32:55 +01:00
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
class QTranslator;
|
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @addtogroup GUI
|
|
|
|
/// @{
|
|
|
|
|
2011-02-07 11:56:32 +01:00
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Information for one translation.
|
|
|
|
*
|
|
|
|
*/
|
2011-10-13 20:53:06 +02:00
|
|
|
struct TranslationInfo {
|
2011-02-07 11:56:32 +01:00
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Readable name for the translation (e.g. "English").
|
|
|
|
*
|
|
|
|
*/
|
2011-02-06 21:00:16 +01:00
|
|
|
QString mName;
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Filename for the translation.
|
|
|
|
*
|
|
|
|
*/
|
2011-02-06 21:00:16 +01:00
|
|
|
QString mFilename;
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief ISO 639 language code for the translation (e.g. "en").
|
|
|
|
*
|
|
|
|
*/
|
2011-02-07 11:30:13 +01:00
|
|
|
QString mCode;
|
2011-02-06 21:00:16 +01:00
|
|
|
};
|
|
|
|
|
2011-02-07 11:56:32 +01:00
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief A class handling the available translations.
|
|
|
|
*
|
|
|
|
* This class contains a list of available translations. The class also keeps
|
|
|
|
* track which translation is the currently active translation.
|
|
|
|
*
|
|
|
|
*/
|
2011-10-13 20:53:06 +02:00
|
|
|
class TranslationHandler : QObject {
|
2009-07-02 10:32:29 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-06-30 21:39:22 +02:00
|
|
|
explicit TranslationHandler(QObject *parent = nullptr);
|
2022-03-13 20:07:58 +01:00
|
|
|
~TranslationHandler() override;
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Get a list of available translations.
|
|
|
|
* @return List of available translations.
|
|
|
|
*
|
|
|
|
*/
|
2017-07-28 13:43:49 +02:00
|
|
|
QList<TranslationInfo> getTranslations() const {
|
2011-02-07 11:30:13 +01:00
|
|
|
return mTranslations;
|
|
|
|
}
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Set active translation.
|
|
|
|
* @param code ISO 639 language code for new selected translation.
|
|
|
|
* @return true if succeeds, false otherwise.
|
|
|
|
*
|
|
|
|
*/
|
2017-07-28 13:43:49 +02:00
|
|
|
bool setLanguage(const QString &code);
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Get currently selected translation.
|
|
|
|
* @return ISO 639 language code for current translation.
|
|
|
|
*
|
|
|
|
*/
|
2017-07-28 13:43:49 +02:00
|
|
|
QString getCurrentLanguage() const;
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Get translation suggestion for the system.
|
|
|
|
* This function checks the current system locale and determines which of
|
|
|
|
* the available translations is best as current translation. If none of
|
|
|
|
* the available translations is good then it returns English ("en").
|
|
|
|
* @return Suggested translation ISO 639 language code.
|
|
|
|
*
|
|
|
|
*/
|
2017-07-28 13:43:49 +02:00
|
|
|
QString suggestLanguage() const;
|
2011-02-07 11:56:32 +01:00
|
|
|
|
2009-07-02 10:32:29 +02:00
|
|
|
protected:
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Add new translation to list of available translations.
|
|
|
|
* @param name Name of the translation ("English").
|
|
|
|
* @param filename Filename of the translation.
|
|
|
|
*
|
|
|
|
*/
|
2017-07-28 13:43:49 +02:00
|
|
|
void addTranslation(const char *name, const char *filename);
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Find language in the list and return its index.
|
|
|
|
* @param code ISO 639 language code.
|
|
|
|
* @return Index at list, or -1 if not found.
|
|
|
|
*
|
|
|
|
*/
|
2017-07-28 13:43:49 +02:00
|
|
|
int getLanguageIndexByCode(const QString &code) const;
|
2011-02-06 21:00:16 +01:00
|
|
|
|
2011-02-07 11:56:32 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief ISO 639 language code of the currently selected translation.
|
|
|
|
*
|
|
|
|
*/
|
2011-02-07 11:30:13 +01:00
|
|
|
QString mCurrentLanguage;
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief List of available translations.
|
|
|
|
*
|
|
|
|
*/
|
2011-02-06 21:00:16 +01:00
|
|
|
QList<TranslationInfo> mTranslations;
|
2011-02-07 11:56:32 +01:00
|
|
|
|
|
|
|
/**
|
2021-08-07 20:51:18 +02:00
|
|
|
* @brief Translator class instance.
|
|
|
|
*
|
|
|
|
*/
|
2009-07-02 10:32:29 +02:00
|
|
|
QTranslator *mTranslator;
|
|
|
|
};
|
2011-02-07 11:56:32 +01:00
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @}
|
2009-07-02 10:32:29 +02:00
|
|
|
#endif // TRANSLATIONHANDLER_H
|