2015-06-05 18:26:04 +08:00
|
|
|
#ifndef TRANSLATOR_H
|
|
|
|
#define TRANSLATOR_H
|
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
#include <QVector>
|
|
|
|
#include <QPair>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <functional>
|
|
|
|
|
2015-06-05 18:26:04 +08:00
|
|
|
class QTranslator;
|
|
|
|
|
|
|
|
class Translator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Loads the translations according to the settings or locale
|
|
|
|
static void translate();
|
2015-06-06 03:37:01 +08:00
|
|
|
/// Register a function to be called when the UI needs to be retranslated
|
|
|
|
static void registerHandler(std::function<void()>, void* owner);
|
|
|
|
/// Unregisters all handlers of an owner
|
|
|
|
static void unregister(void* owner);
|
2015-06-05 18:26:04 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
static QTranslator* translator;
|
2015-06-06 03:37:01 +08:00
|
|
|
static QVector<QPair<void*, std::function<void()>>> callbacks;
|
|
|
|
static QMutex lock;
|
2015-06-05 18:26:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TRANSLATOR_H
|