mirror of https://github.com/procxx/kepka.git
Display languages native names in the box.
Also don't suggest the old official languages in a popup.
This commit is contained in:
parent
85e6f55536
commit
f3e65d400d
|
@ -71,7 +71,7 @@ void LanguageBox::Inner::refresh() {
|
||||||
_buttons.reserve(_languages->size());
|
_buttons.reserve(_languages->size());
|
||||||
auto index = 0;
|
auto index = 0;
|
||||||
for_const (auto &language, *_languages) {
|
for_const (auto &language, *_languages) {
|
||||||
_buttons.emplace_back(this, _group, index++, language.name, st::langsButton);
|
_buttons.emplace_back(this, _group, index++, language.nativeName, st::langsButton);
|
||||||
auto button = _buttons.back().data();
|
auto button = _buttons.back().data();
|
||||||
button->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), y + st::langsButton.margin.top());
|
button->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), y + st::langsButton.margin.top());
|
||||||
button->show();
|
button->show();
|
||||||
|
@ -141,7 +141,7 @@ void LanguageBox::refreshLanguages() {
|
||||||
_languages.reserve(list.size() + 1);
|
_languages.reserve(list.size() + 1);
|
||||||
auto currentId = Lang::Current().id();
|
auto currentId = Lang::Current().id();
|
||||||
auto currentIndex = -1;
|
auto currentIndex = -1;
|
||||||
_languages.push_back({ qsl("en"), qsl("English") });
|
_languages.push_back({ qsl("en"), qsl("English"), qsl("English") });
|
||||||
for (auto &language : list) {
|
for (auto &language : list) {
|
||||||
auto isCurrent = (language.id == currentId) || (language.id == Lang::DefaultLanguageId() && currentId.isEmpty());
|
auto isCurrent = (language.id == currentId) || (language.id == Lang::DefaultLanguageId() && currentId.isEmpty());
|
||||||
if (language.id != qstr("en")) {
|
if (language.id != qstr("en")) {
|
||||||
|
@ -154,11 +154,11 @@ void LanguageBox::refreshLanguages() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentId == qstr("custom")) {
|
if (currentId == qstr("custom")) {
|
||||||
_languages.insert(_languages.begin(), { currentId, qsl("Custom LangPack") });
|
_languages.insert(_languages.begin(), { currentId, qsl("Custom LangPack"), qsl("Custom LangPack") });
|
||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
} else if (currentIndex < 0) {
|
} else if (currentIndex < 0) {
|
||||||
currentIndex = _languages.size();
|
currentIndex = _languages.size();
|
||||||
_languages.push_back({ currentId, lang(lng_language_name) });
|
_languages.push_back({ currentId, lang(lng_language_name), lang(lng_language_name) });
|
||||||
}
|
}
|
||||||
_inner->setSelected(currentIndex);
|
_inner->setSelected(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,11 +73,25 @@ void CloudManager::setSuggestedLanguage(const QString &langCode) {
|
||||||
_firstLanguageSuggestion.notify();
|
_firstLanguageSuggestion.notify();
|
||||||
|
|
||||||
if (AuthSession::Exists() && _langpack.id().isEmpty() && !_suggestedLanguage.isEmpty()) {
|
if (AuthSession::Exists() && _langpack.id().isEmpty() && !_suggestedLanguage.isEmpty()) {
|
||||||
|
auto isLegacy = [](const QString &languageId) {
|
||||||
|
for (auto &legacyString : kLegacyLanguages) {
|
||||||
|
auto legacyId = str_const_toString(legacyString);
|
||||||
|
if (ConvertLegacyLanguageId(legacyId) == languageId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// The old available languages (de/it/nl/ko/es/pt_BR) won't be
|
||||||
|
// suggested anyway, because everyone saw the suggestion in intro.
|
||||||
|
if (!isLegacy(_suggestedLanguage)) {
|
||||||
_offerSwitchToId = _suggestedLanguage;
|
_offerSwitchToId = _suggestedLanguage;
|
||||||
offerSwitchLangPack();
|
offerSwitchLangPack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CloudManager::applyLangPackDifference(const MTPLangPackDifference &difference) {
|
void CloudManager::applyLangPackDifference(const MTPLangPackDifference &difference) {
|
||||||
Expects(difference.type() == mtpc_langPackDifference);
|
Expects(difference.type() == mtpc_langPackDifference);
|
||||||
|
@ -103,7 +117,7 @@ void CloudManager::requestLanguageList() {
|
||||||
for_const (auto &langData, result.v) {
|
for_const (auto &langData, result.v) {
|
||||||
t_assert(langData.type() == mtpc_langPackLanguage);
|
t_assert(langData.type() == mtpc_langPackLanguage);
|
||||||
auto &language = langData.c_langPackLanguage();
|
auto &language = langData.c_langPackLanguage();
|
||||||
languages.push_back({ qs(language.vlang_code), qs(language.vname) });
|
languages.push_back({ qs(language.vlang_code), qs(language.vname), qs(language.vnative_name) });
|
||||||
}
|
}
|
||||||
if (_languages != languages) {
|
if (_languages != languages) {
|
||||||
_languages = languages;
|
_languages = languages;
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
struct Language {
|
struct Language {
|
||||||
QString id;
|
QString id;
|
||||||
QString name;
|
QString name;
|
||||||
|
QString nativeName;
|
||||||
};
|
};
|
||||||
using Languages = QVector<Language>;
|
using Languages = QVector<Language>;
|
||||||
|
|
||||||
|
|
|
@ -34,20 +34,6 @@ namespace {
|
||||||
constexpr auto kDefaultLanguage = str_const("en");
|
constexpr auto kDefaultLanguage = str_const("en");
|
||||||
constexpr auto kLangValuesLimit = 20000;
|
constexpr auto kLangValuesLimit = 20000;
|
||||||
|
|
||||||
constexpr str_const kLegacyLanguages[] = {
|
|
||||||
"en",
|
|
||||||
"it",
|
|
||||||
"es",
|
|
||||||
"de",
|
|
||||||
"nl",
|
|
||||||
"pt_BR",
|
|
||||||
"ko",
|
|
||||||
};
|
|
||||||
|
|
||||||
QString ConvertLegacyLanguageId(const QString &languageId) {
|
|
||||||
return languageId.toLower().replace('_', '-');
|
|
||||||
}
|
|
||||||
|
|
||||||
class ValueParser {
|
class ValueParser {
|
||||||
public:
|
public:
|
||||||
ValueParser(const QByteArray &key, LangKey keyIndex, const QByteArray &value);
|
ValueParser(const QByteArray &key, LangKey keyIndex, const QByteArray &value);
|
||||||
|
@ -365,16 +351,23 @@ void Instance::fillFromCustomFile(const QString &filePath) {
|
||||||
void Instance::fillFromLegacy(int legacyId, const QString &legacyPath) {
|
void Instance::fillFromLegacy(int legacyId, const QString &legacyPath) {
|
||||||
if (legacyId == kLegacyDefaultLanguage) {
|
if (legacyId == kLegacyDefaultLanguage) {
|
||||||
_legacyId = legacyId;
|
_legacyId = legacyId;
|
||||||
_id = str_const_toString(kLegacyLanguages[legacyId]);
|
|
||||||
|
// We suppose that user didn't switch to the default language,
|
||||||
|
// so we will suggest him to switch to his language if we get it.
|
||||||
|
//
|
||||||
|
// The old available languages (de/it/nl/ko/es/pt_BR) won't be
|
||||||
|
// suggested anyway, because everyone saw the suggestion in intro.
|
||||||
|
_id = QString();// str_const_toString(kLegacyLanguages[legacyId]);
|
||||||
} else if (legacyId == kLegacyCustomLanguage) {
|
} else if (legacyId == kLegacyCustomLanguage) {
|
||||||
auto absolutePath = QFileInfo(legacyPath).absoluteFilePath();
|
auto absolutePath = QFileInfo(legacyPath).absoluteFilePath();
|
||||||
auto relativePath = QDir().relativeFilePath(absolutePath);
|
auto relativePath = QDir().relativeFilePath(absolutePath);
|
||||||
auto content = Lang::FileParser::ReadFile(absolutePath, relativePath);
|
auto content = Lang::FileParser::ReadFile(absolutePath, relativePath);
|
||||||
if (!content.isEmpty()) {
|
if (!content.isEmpty()) {
|
||||||
|
_legacyId = legacyId;
|
||||||
loadFromCustomContent(absolutePath, relativePath, content);
|
loadFromCustomContent(absolutePath, relativePath, content);
|
||||||
}
|
}
|
||||||
} else if (legacyId > kLegacyDefaultLanguage && legacyId < base::array_size(kLegacyLanguages)) {
|
} else if (legacyId > kLegacyDefaultLanguage && legacyId < base::array_size(kLegacyLanguages)) {
|
||||||
auto languageId = str_const_toString(kLegacyLanguages[_legacyId]);
|
auto languageId = str_const_toString(kLegacyLanguages[legacyId]);
|
||||||
auto resourcePath = qsl(":/langs/lang_") + languageId + qsl(".strings");
|
auto resourcePath = qsl(":/langs/lang_") + languageId + qsl(".strings");
|
||||||
auto content = Lang::FileParser::ReadFile(resourcePath, resourcePath);
|
auto content = Lang::FileParser::ReadFile(resourcePath, resourcePath);
|
||||||
if (!content.isEmpty()) {
|
if (!content.isEmpty()) {
|
||||||
|
|
|
@ -29,6 +29,20 @@ constexpr auto kLegacyLanguageNone = -2;
|
||||||
constexpr auto kLegacyCustomLanguage = -1;
|
constexpr auto kLegacyCustomLanguage = -1;
|
||||||
constexpr auto kLegacyDefaultLanguage = 0;
|
constexpr auto kLegacyDefaultLanguage = 0;
|
||||||
|
|
||||||
|
constexpr str_const kLegacyLanguages[] = {
|
||||||
|
"en",
|
||||||
|
"it",
|
||||||
|
"es",
|
||||||
|
"de",
|
||||||
|
"nl",
|
||||||
|
"pt_BR",
|
||||||
|
"ko",
|
||||||
|
};
|
||||||
|
|
||||||
|
inline QString ConvertLegacyLanguageId(const QString &languageId) {
|
||||||
|
return languageId.toLower().replace('_', '-');
|
||||||
|
}
|
||||||
|
|
||||||
QString DefaultLanguageId();
|
QString DefaultLanguageId();
|
||||||
|
|
||||||
class Instance;
|
class Instance;
|
||||||
|
|
Loading…
Reference in New Issue