Display languages native names in the box.

Also don't suggest the old official languages in a popup.
This commit is contained in:
John Preston 2017-06-04 16:09:53 +03:00
parent 85e6f55536
commit f3e65d400d
5 changed files with 45 additions and 23 deletions

View file

@ -71,7 +71,7 @@ void LanguageBox::Inner::refresh() {
_buttons.reserve(_languages->size());
auto index = 0;
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();
button->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), y + st::langsButton.margin.top());
button->show();
@ -141,7 +141,7 @@ void LanguageBox::refreshLanguages() {
_languages.reserve(list.size() + 1);
auto currentId = Lang::Current().id();
auto currentIndex = -1;
_languages.push_back({ qsl("en"), qsl("English") });
_languages.push_back({ qsl("en"), qsl("English"), qsl("English") });
for (auto &language : list) {
auto isCurrent = (language.id == currentId) || (language.id == Lang::DefaultLanguageId() && currentId.isEmpty());
if (language.id != qstr("en")) {
@ -154,11 +154,11 @@ void LanguageBox::refreshLanguages() {
}
}
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;
} else if (currentIndex < 0) {
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);
}

View file

@ -73,8 +73,22 @@ void CloudManager::setSuggestedLanguage(const QString &langCode) {
_firstLanguageSuggestion.notify();
if (AuthSession::Exists() && _langpack.id().isEmpty() && !_suggestedLanguage.isEmpty()) {
_offerSwitchToId = _suggestedLanguage;
offerSwitchLangPack();
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;
offerSwitchLangPack();
}
}
}
}
@ -103,7 +117,7 @@ void CloudManager::requestLanguageList() {
for_const (auto &langData, result.v) {
t_assert(langData.type() == mtpc_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) {
_languages = languages;

View file

@ -38,6 +38,7 @@ public:
struct Language {
QString id;
QString name;
QString nativeName;
};
using Languages = QVector<Language>;

View file

@ -34,20 +34,6 @@ namespace {
constexpr auto kDefaultLanguage = str_const("en");
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 {
public:
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) {
if (legacyId == kLegacyDefaultLanguage) {
_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) {
auto absolutePath = QFileInfo(legacyPath).absoluteFilePath();
auto relativePath = QDir().relativeFilePath(absolutePath);
auto content = Lang::FileParser::ReadFile(absolutePath, relativePath);
if (!content.isEmpty()) {
_legacyId = legacyId;
loadFromCustomContent(absolutePath, relativePath, content);
}
} 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 content = Lang::FileParser::ReadFile(resourcePath, resourcePath);
if (!content.isEmpty()) {

View file

@ -29,6 +29,20 @@ constexpr auto kLegacyLanguageNone = -2;
constexpr auto kLegacyCustomLanguage = -1;
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();
class Instance;