137 lines
3.7 KiB
C++
137 lines
3.7 KiB
C++
#include "rm_language.h"
|
|
#if(LIVE_LANGUAGE_CHANGE)
|
|
#include <QDebug>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
#include "../rm_settings.h"
|
|
#include "../rm_include.h"
|
|
#include "fm_strings.h"
|
|
#include <QLocale>
|
|
#if (INITIAL_LANGUAGE_AUTO)
|
|
bool RMLanguage::isAuto = true;
|
|
#else
|
|
bool RMLanguage::isAuto = false;
|
|
#endif
|
|
|
|
RMLanguage::RMLanguage(QObject *parent) : QObject(parent)
|
|
{
|
|
#if (FIXED_ENGLISH)
|
|
RMLanguage::isAuto = false;
|
|
_currentLanguage = LANGUAGE_EN;
|
|
#else
|
|
RMLanguage::isAuto = RMSettings::instance()->autoLanguage();
|
|
_currentLanguage = (LANGUAGE_TYPE)RMSettings::instance()->language();
|
|
#endif
|
|
_list = new QHash<qint64,QHash<int,QString>*>();
|
|
}
|
|
RMLanguage::LANGUAGE_TYPE RMLanguage::systemLanguage()
|
|
{
|
|
QString lan = QLocale::system().name();
|
|
#if (LIVE_LANGUAGE2)
|
|
if(lan.contains("JP",Qt::CaseInsensitive))
|
|
{
|
|
return RMLanguage::LANGUAGE_JP;
|
|
}
|
|
else if (lan.contains("KR",Qt::CaseInsensitive)) {
|
|
return RMLanguage::LANGUAGE_KR;
|
|
}
|
|
return RMLanguage::LANGUAGE_EN;
|
|
#else // #if (LIVE_LANGUAGE2)
|
|
#if (LANGUAGE_REMOVE_ENG) // WATEX
|
|
return RMLanguage::LANGUAGE_JP;
|
|
#else
|
|
if(lan.contains("JP",Qt::CaseInsensitive))
|
|
{
|
|
return RMLanguage::LANGUAGE_JP;
|
|
}
|
|
return RMLanguage::LANGUAGE_EN;
|
|
#endif
|
|
#endif // #if (LIVE_LANGUAGE2)
|
|
}
|
|
|
|
|
|
#if (LIVE_LANGUAGE2)
|
|
void RMLanguage::append(const char* key,RMLanguage::TEXT_TYPE type,QObject* control)
|
|
{
|
|
qint64 object_key = (qint64)control;
|
|
//qInfo() << control << "key:" << key;
|
|
QHash<int,QString>* info = _list->value(object_key);
|
|
if(info == NULL)
|
|
{
|
|
info = new QHash<int,QString>();
|
|
_list->insert(object_key,info);
|
|
}
|
|
info->insert((LANGUAGE_JP | type),FMS::txt(key,LANGUAGE_JP));
|
|
info->insert((LANGUAGE_EN | type),FMS::txt(key,LANGUAGE_EN));
|
|
info->insert((LANGUAGE_KR | type),FMS::txt(key,LANGUAGE_KR));
|
|
}
|
|
#else // LIVE_LANGUAGE2
|
|
void RMLanguage::append(RMLanguage::LANGUAGE_TYPE language,RMLanguage::TEXT_TYPE type, QObject* control,QString str)
|
|
{
|
|
//QMutableHashIterator itr = _list->iterator;
|
|
//_controls->append(control);
|
|
qint64 key = (qint64)control;
|
|
//qInfo() << control << "key:" << key;
|
|
QHash<int,QString>* info = _list->value(key);
|
|
if(info == NULL)
|
|
{
|
|
info = new QHash<int,QString>();
|
|
_list->insert(key,info);
|
|
}
|
|
info->insert((language | type),str);
|
|
//info->insert((LANGUAGE_EN | type),"TEST");
|
|
//qInfo()<< "insert:" << str;
|
|
}
|
|
#endif // LIVE_LANGUAGE2
|
|
|
|
void RMLanguage::setLanguage(RMLanguage::LANGUAGE_TYPE language)
|
|
{
|
|
#if (FIXED_ENGLISH)
|
|
Q_UNUSED(language);
|
|
#else
|
|
_currentLanguage = language;
|
|
refresh();
|
|
RMSettings::instance()->setLanguage(_currentLanguage);
|
|
emit languageChange(_currentLanguage);
|
|
#endif
|
|
}
|
|
void RMLanguage::remove(QObject* control)
|
|
{
|
|
qint64 key = (qint64)control;
|
|
_list->remove(key);
|
|
}
|
|
void RMLanguage::refresh()
|
|
{
|
|
RMLanguage::LANGUAGE_TYPE language = _currentLanguage;
|
|
foreach (qint64 key, _list->keys()) {
|
|
|
|
QHash<int,QString>* info = _list->value(key);
|
|
// qInfo() << control;
|
|
|
|
QObject* control = (QObject*)key;
|
|
if(control->inherits("QPushButton"))
|
|
{
|
|
QString str = info->value(language | TOOLTIP_TEXT);
|
|
QPushButton* btn = (QPushButton*)control;
|
|
if(str.length() > 0)
|
|
{
|
|
btn->setToolTip(str);
|
|
}
|
|
str = info->value(language | TITLE_TEXT);
|
|
if(str.length() > 0)
|
|
{
|
|
btn->setText(str);
|
|
}
|
|
}
|
|
else if (control->inherits("QLabel"))
|
|
{
|
|
QLabel* lb = (QLabel*)control;
|
|
QString str = info->value(language | TITLE_TEXT);
|
|
//qInfo() << info->values();
|
|
lb->setText(str);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|