mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Prefix client-side lang_code-s with #.
This commit is contained in:
parent
711b8cfa36
commit
3447aac940
6 changed files with 21 additions and 14 deletions
|
@ -76,7 +76,7 @@ void LanguageBox::Inner::languageChanged(int languageIndex) {
|
|||
activateCurrent();
|
||||
auto languageId = (*_languages)[languageIndex].id;
|
||||
if (Lang::Current().id() != languageId) {
|
||||
// "custom" is applied each time it is passed to switchToLanguage().
|
||||
// "#custom" is applied each time it's passed to switchToLanguage().
|
||||
// So we check that the language really has changed.
|
||||
Lang::CurrentCloudManager().switchToLanguage(languageId);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ void LanguageBox::refreshLanguages() {
|
|||
currentIndex = 0;
|
||||
}
|
||||
}
|
||||
if (currentId == qstr("custom")) {
|
||||
if (currentId == qstr("#custom")) {
|
||||
_languages.insert(_languages.begin(), { currentId, qsl("Custom LangPack"), qsl("Custom LangPack") });
|
||||
currentIndex = 0;
|
||||
} else if (currentIndex < 0) {
|
||||
|
|
|
@ -185,13 +185,15 @@ void CloudManager::applyLangPackData(const MTPDlangPackDifference &data) {
|
|||
} else if (!data.vstrings.v.isEmpty()) {
|
||||
_langpack.applyDifference(data);
|
||||
Local::writeLangPack();
|
||||
} else if (_restartAfterSwitch) {
|
||||
Local::writeLangPack();
|
||||
} else {
|
||||
LOG(("Lang Info: Up to date."));
|
||||
}
|
||||
}
|
||||
|
||||
bool CloudManager::canApplyWithoutRestart(const QString &id) const {
|
||||
if (id == qstr("TEST_X") || id == qstr("TEST_0")) {
|
||||
if (id == qstr("#TEST_X") || id == qstr("#TEST_0")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -207,12 +209,12 @@ void CloudManager::switchToLanguage(QString id) {
|
|||
if (id.isEmpty()) {
|
||||
id = DefaultLanguageId();
|
||||
}
|
||||
if (_langpack.id() == id && id != qstr("custom")) {
|
||||
if (_langpack.id() == id && id != qstr("#custom")) {
|
||||
return;
|
||||
}
|
||||
|
||||
request(_switchingToLanguageRequest).cancel();
|
||||
if (id == qstr("custom")) {
|
||||
if (id == qstr("#custom")) {
|
||||
performSwitchToCustom();
|
||||
} else if (canApplyWithoutRestart(id)) {
|
||||
performSwitch(id);
|
||||
|
@ -258,7 +260,7 @@ void CloudManager::performSwitchToCustom() {
|
|||
Lang::FileParser loader(filePath, { lng_sure_save_language });
|
||||
if (loader.errors().isEmpty()) {
|
||||
weak->request(weak->_switchingToLanguageRequest).cancel();
|
||||
if (weak->canApplyWithoutRestart(qsl("custom"))) {
|
||||
if (weak->canApplyWithoutRestart(qsl("#custom"))) {
|
||||
weak->_langpack.switchToCustomFile(filePath);
|
||||
} else {
|
||||
const auto values = loader.found();
|
||||
|
@ -292,7 +294,9 @@ void CloudManager::performSwitchToCustom() {
|
|||
}
|
||||
|
||||
void CloudManager::switchToTestLanguage() {
|
||||
auto testLanguageId = (_langpack.id() == qstr("TEST_X")) ? qsl("TEST_0") : qsl("TEST_X");
|
||||
const auto testLanguageId = (_langpack.id() == qstr("#TEST_X"))
|
||||
? qsl("#TEST_0")
|
||||
: qsl("#TEST_X");
|
||||
performSwitch(testLanguageId);
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ QString CloudLangPackName() {
|
|||
void Instance::switchToId(const QString &id) {
|
||||
reset();
|
||||
_id = id;
|
||||
if (_id == qstr("TEST_X") || _id == qstr("TEST_0")) {
|
||||
if (_id == qstr("#TEST_X") || _id == qstr("#TEST_0")) {
|
||||
for (auto &value : _values) {
|
||||
value = PrepareTestValue(value, _id[5]);
|
||||
}
|
||||
|
@ -287,6 +287,9 @@ void Instance::fillFromSerialized(const QByteArray &data) {
|
|||
}
|
||||
|
||||
if (!customFilePathAbsolute.isEmpty()) {
|
||||
if (id == qstr("custom")) {
|
||||
id = '#' + id;
|
||||
}
|
||||
auto currentCustomFileContent = Lang::FileParser::ReadFile(customFilePathAbsolute, customFilePathRelative);
|
||||
if (!currentCustomFileContent.isEmpty() && currentCustomFileContent != customFileContent) {
|
||||
loadFromCustomContent(customFilePathAbsolute, customFilePathRelative, currentCustomFileContent);
|
||||
|
@ -333,7 +336,7 @@ void Instance::loadFromContent(const QByteArray &content) {
|
|||
}
|
||||
|
||||
void Instance::loadFromCustomContent(const QString &absolutePath, const QString &relativePath, const QByteArray &content) {
|
||||
_id = qsl("custom");
|
||||
_id = qsl("#custom");
|
||||
_version = 0;
|
||||
_customFilePathAbsolute = absolutePath;
|
||||
_customFilePathRelative = relativePath;
|
||||
|
|
|
@ -60,9 +60,9 @@ public:
|
|||
return _id;
|
||||
}
|
||||
bool isCustom() const {
|
||||
return (_id == qstr("custom")
|
||||
|| _id == qstr("TEST_X")
|
||||
|| _id == qstr("TEST_0"));
|
||||
return (_id == qstr("#custom"))
|
||||
|| (_id == qstr("#TEST_X"))
|
||||
|| (_id == qstr("#TEST_0"));
|
||||
}
|
||||
int version() const {
|
||||
return _version;
|
||||
|
|
|
@ -51,7 +51,7 @@ auto GenerateCodes() {
|
|||
});
|
||||
}
|
||||
codes.emplace(qsl("loadlang"), [] {
|
||||
Lang::CurrentCloudManager().switchToLanguage(qsl("custom"));
|
||||
Lang::CurrentCloudManager().switchToLanguage(qsl("#custom"));
|
||||
});
|
||||
codes.emplace(qsl("debugfiles"), [] {
|
||||
if (!Logs::DebugEnabled()) {
|
||||
|
|
|
@ -40,7 +40,7 @@ void SetupLanguageButton(
|
|||
button->addClickHandler([=] {
|
||||
const auto m = button->clickModifiers();
|
||||
if ((m & Qt::ShiftModifier) && (m & Qt::AltModifier)) {
|
||||
Lang::CurrentCloudManager().switchToLanguage(qsl("custom"));
|
||||
Lang::CurrentCloudManager().switchToLanguage(qsl("#custom"));
|
||||
} else {
|
||||
*guard = LanguageBox::Show();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue