locale stuff
This commit is contained in:
parent
95cf62b990
commit
da1a42e2ee
|
@ -175,28 +175,26 @@ void DlgGeneralImp::loadSettings()
|
|||
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");
|
||||
QString lang = QLocale::languageToString(QLocale::system().language());
|
||||
QByteArray language = hGrp->GetASCII("Language", (const char*)lang.toAscii()).c_str();
|
||||
Languages->addItem(Gui::Translator::tr("English"), QByteArray("English"));
|
||||
int index = 1;
|
||||
Languages->addItem(QString::fromAscii("English"), QByteArray("English"));
|
||||
TStringMap list = Translator::instance()->supportedLocales();
|
||||
for (TStringMap::iterator it = list.begin(); it != list.end(); ++it, index++) {
|
||||
QLocale locale(QString::fromAscii(it->second.c_str()));
|
||||
QByteArray lang = it->first.c_str();
|
||||
QString langname = QString::fromAscii(lang.constData());
|
||||
#if QT_VERSION >= 0x040800
|
||||
TStringList list = Translator::instance()->supportedLocales();
|
||||
for (TStringList::iterator it = list.begin(); it != list.end(); ++it, index++) {
|
||||
QLocale locale(QString::fromAscii(it->c_str()));
|
||||
QByteArray lang = QLocale::languageToString(locale.language()).toAscii();
|
||||
Languages->addItem(locale.nativeLanguageName(), lang);
|
||||
if (language == lang) {
|
||||
Languages->setCurrentIndex(index);
|
||||
QString native = locale.nativeLanguageName();
|
||||
if (!native.isEmpty()) {
|
||||
if (native[0].isLetter())
|
||||
native[0] = native[0].toUpper();
|
||||
langname = native;
|
||||
}
|
||||
}
|
||||
#else
|
||||
TStringList list = Translator::instance()->supportedLanguages();
|
||||
for (TStringList::iterator it = list.begin(); it != list.end(); ++it, index++) {
|
||||
QByteArray lang = it->c_str();
|
||||
Languages->addItem(Gui::Translator::tr(lang.constData()), lang);
|
||||
if (language == lang) {
|
||||
Languages->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Languages->addItem(langname, lang);
|
||||
if (language == lang) {
|
||||
Languages->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
int size = QApplication::style()->pixelMetric(QStyle::PM_ToolBarIconSize);
|
||||
int current = getMainWindow()->iconSize().width();
|
||||
|
|
|
@ -174,17 +174,17 @@ TStringList Translator::supportedLanguages() const
|
|||
return languages;
|
||||
}
|
||||
|
||||
TStringList Translator::supportedLocales() const
|
||||
TStringMap Translator::supportedLocales() const
|
||||
{
|
||||
// List all .qm files
|
||||
TStringList languages;
|
||||
TStringMap languages;
|
||||
QDir dir(QLatin1String(":/translations"));
|
||||
for (std::map<std::string,std::string>::const_iterator it = d->mapLanguageTopLevelDomain.begin();
|
||||
it != d->mapLanguageTopLevelDomain.end(); ++it) {
|
||||
QString filter = QString::fromAscii("*_%1.qm").arg(QLatin1String(it->second.c_str()));
|
||||
QStringList fileNames = dir.entryList(QStringList(filter), QDir::Files, QDir::Name);
|
||||
if (!fileNames.isEmpty())
|
||||
languages.push_back(it->second);
|
||||
languages[it->first] = it->second;
|
||||
}
|
||||
|
||||
return languages;
|
||||
|
|
|
@ -34,6 +34,7 @@ class QDir;
|
|||
namespace Gui {
|
||||
|
||||
typedef std::list<std::string> TStringList;
|
||||
typedef std::map<std::string, std::string> TStringMap;
|
||||
|
||||
/**
|
||||
* The Translator class uses Qt's QTranslator objects to change the language of the application
|
||||
|
@ -65,8 +66,8 @@ public:
|
|||
std::string activeLanguage() const;
|
||||
/** Returns a list of supported languages. */
|
||||
TStringList supportedLanguages() const;
|
||||
/** Returns a list of supported locales. */
|
||||
TStringList supportedLocales() const;
|
||||
/** Returns a map of supported languages/locales. */
|
||||
TStringMap supportedLocales() const;
|
||||
/** Adds a path where localization files can be found */
|
||||
void addPath(const QString& path);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user