/*************************************************************************** * Copyright (C) 2014 Evgeniy Alekseev * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 3.0 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library. * ***************************************************************************/ #include "language.h" #include #include #include #include "config.h" Language::Language() { } QString Language::checkLanguage(const QString language) { QStringList availableLanguages = getAvailableLanguages(); if (availableLanguages.count() == 0) return QString(""); for (int i=0; i optionsDict = parseOptions(options); if (optionsDict.contains(QString(LANGUAGE_KEY))) if (getAvailableLanguages().contains(optionsDict[QString(LANGUAGE_KEY)])) return optionsDict[QString(LANGUAGE_KEY)]; QString language; language = defineLanguageFromFile(configPath); if (language.isEmpty()) language = defineLanguageFromLocale(); language = checkLanguage(language); return language; } QString Language::defineLanguageFromFile(const QString configPath) { QSettings settings(configPath, QSettings::IniFormat); settings.beginGroup("Common"); QString language = settings.value(QString(LANGUAGE_KEY), QString()).toString(); settings.endGroup(); return language; } QString Language::defineLanguageFromLocale() { return QLocale::system().name(); } QStringList Language::getAvailableLanguages() { return QString(LANGUAGES).split(QChar(',')); } QMap Language::parseOptions(const QString options) { QMap optionsDict; for (int i=0; i