2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2014-2015 Teo Mrnjavac <teo@kde.org>
|
2014-11-11 12:42:37 +01:00
|
|
|
*
|
|
|
|
* Calamares 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.
|
|
|
|
*
|
|
|
|
* Calamares 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
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
* License-Filename: LICENSE
|
|
|
|
*
|
2014-11-11 12:42:37 +01:00
|
|
|
*/
|
|
|
|
|
2019-04-29 12:12:18 +02:00
|
|
|
#ifndef UTILS_RETRANSLATOR_H
|
|
|
|
#define UTILS_RETRANSLATOR_H
|
2014-11-11 12:42:37 +01:00
|
|
|
|
2019-04-29 12:33:55 +02:00
|
|
|
#include "DllMacro.h"
|
|
|
|
|
2014-11-11 15:12:17 +01:00
|
|
|
#include <QList>
|
2014-11-11 12:42:37 +01:00
|
|
|
#include <QObject>
|
2019-04-29 12:33:55 +02:00
|
|
|
#include <QString>
|
2014-11-11 12:42:37 +01:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
class QEvent;
|
2019-04-29 12:33:55 +02:00
|
|
|
class QLocale;
|
2014-11-11 12:42:37 +01:00
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
2019-08-04 21:22:54 +02:00
|
|
|
/**
|
|
|
|
* @brief installTranslator changes the application language.
|
|
|
|
* @param locale the new locale.
|
|
|
|
* @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding.
|
|
|
|
*/
|
2020-03-25 12:08:27 +01:00
|
|
|
DLLEXPORT void installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix );
|
2019-08-04 21:22:54 +02:00
|
|
|
|
|
|
|
DLLEXPORT QString translatorLocaleName();
|
2014-11-11 12:42:37 +01:00
|
|
|
|
2020-02-05 17:48:39 +01:00
|
|
|
/** @brief Set @p allow to true to load translations from current dir.
|
|
|
|
*
|
|
|
|
* If false, (or never called) the translations are loaded only from
|
|
|
|
* system locations (the AppData dir) and from QRC (compiled in).
|
|
|
|
* Enable local translations to test translations stored in the
|
|
|
|
* current directory.
|
|
|
|
*/
|
|
|
|
DLLEXPORT void setAllowLocalTranslation( bool allow );
|
|
|
|
|
2014-11-11 12:42:37 +01:00
|
|
|
class Retranslator : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-08-29 14:53:03 +02:00
|
|
|
/// @brief Call @p retranslateFunc when the language changes
|
2019-08-04 21:22:54 +02:00
|
|
|
static void attachRetranslator( QObject* parent, std::function< void( void ) > retranslateFunc );
|
2019-08-29 14:53:03 +02:00
|
|
|
/// @brief What retranslator belongs to @p parent (may create one)
|
|
|
|
static Retranslator* retranslatorFor( QObject* parent );
|
2014-11-11 15:12:17 +01:00
|
|
|
|
2019-08-29 14:53:03 +02:00
|
|
|
/// @brief Call @p retranslateFunc when the language changes
|
2014-11-11 15:12:17 +01:00
|
|
|
void addRetranslateFunc( std::function< void( void ) > retranslateFunc );
|
2014-11-11 12:42:37 +01:00
|
|
|
|
2019-08-29 14:53:03 +02:00
|
|
|
signals:
|
|
|
|
void languageChange();
|
|
|
|
|
2014-11-11 12:42:37 +01:00
|
|
|
protected:
|
|
|
|
bool eventFilter( QObject* obj, QEvent* e ) override;
|
|
|
|
|
|
|
|
private:
|
2014-11-11 15:12:17 +01:00
|
|
|
explicit Retranslator( QObject* parent );
|
|
|
|
|
|
|
|
QList< std::function< void( void ) > > m_retranslateFuncList;
|
2014-11-11 12:42:37 +01:00
|
|
|
};
|
|
|
|
|
2014-11-11 15:11:06 +01:00
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
} // namespace CalamaresUtils
|
2014-11-11 12:42:37 +01:00
|
|
|
|
2019-08-04 21:22:54 +02:00
|
|
|
#define CALAMARES_RETRANSLATE( body ) CalamaresUtils::Retranslator::attachRetranslator( this, [=] { body } );
|
|
|
|
#define CALAMARES_RETRANSLATE_WIDGET( widget, body ) \
|
2015-05-07 15:30:58 +02:00
|
|
|
CalamaresUtils::Retranslator::attachRetranslator( widget, [=] { body } );
|
2019-08-29 14:53:03 +02:00
|
|
|
#define CALAMARES_RETRANSLATE_SLOT( slotfunc ) \
|
|
|
|
{ \
|
|
|
|
this->connect( CalamaresUtils::Retranslator::retranslatorFor( this ), \
|
|
|
|
&CalamaresUtils::Retranslator::languageChange, \
|
|
|
|
this, \
|
|
|
|
slotfunc ); \
|
|
|
|
}
|
2014-11-11 15:11:06 +01:00
|
|
|
|
2019-04-29 12:12:18 +02:00
|
|
|
#endif
|