Pass language_pack, language_code and language_pack_version to LanguagePackManager.
GitOrigin-RevId: ba4be396d4da14a3169544d25ccb9850dbb9077a
This commit is contained in:
parent
f3f26b0783
commit
f3aaff1e1a
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/LanguagePackManager.h"
|
||||
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/logevent/LogEvent.h"
|
||||
#include "td/telegram/net/NetQueryDispatcher.h"
|
||||
@ -18,6 +19,53 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
void LanguagePackManager::start_up() {
|
||||
language_pack_ = G()->shared_config().get_option_string("language_pack");
|
||||
language_code_ = G()->shared_config().get_option_string("language_code");
|
||||
language_pack_version_ = G()->shared_config().get_option_integer("language_pack_version", -1);
|
||||
LOG(INFO) << "Use language pack " << language_pack_ << " with language " << language_code_ << " of version "
|
||||
<< language_pack_version_;
|
||||
}
|
||||
|
||||
void LanguagePackManager::on_language_pack_changed() {
|
||||
auto new_language_pack = G()->shared_config().get_option_string("language_pack");
|
||||
if (new_language_pack == language_pack_) {
|
||||
return;
|
||||
}
|
||||
|
||||
language_pack_ = std::move(new_language_pack);
|
||||
inc_generation();
|
||||
}
|
||||
|
||||
void LanguagePackManager::on_language_code_changed() {
|
||||
auto new_language_code = G()->shared_config().get_option_string("language_code");
|
||||
if (new_language_code == language_code_) {
|
||||
return;
|
||||
}
|
||||
|
||||
language_code_ = std::move(new_language_code);
|
||||
inc_generation();
|
||||
}
|
||||
|
||||
void LanguagePackManager::on_language_pack_version_changed() {
|
||||
auto new_language_pack_version = G()->shared_config().get_option_integer("language_pack_version");
|
||||
if (new_language_pack_version == language_pack_version_) {
|
||||
return;
|
||||
}
|
||||
if (language_pack_version_ == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO update language pack
|
||||
language_pack_version_ = new_language_pack_version;
|
||||
}
|
||||
|
||||
void LanguagePackManager::inc_generation() {
|
||||
generation_++;
|
||||
G()->shared_config().set_option_empty("language_pack_version");
|
||||
language_pack_version_ = -1;
|
||||
}
|
||||
|
||||
void LanguagePackManager::get_languages(Promise<td_api::object_ptr<td_api::languagePack>> promise) {
|
||||
auto request_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<NetQueryPtr> r_query) mutable {
|
||||
auto r_result = fetch_result<telegram_api::langpack_getLanguages>(std::move(r_query));
|
||||
|
@ -24,6 +24,12 @@ class LanguagePackManager : public NetQueryCallback {
|
||||
explicit LanguagePackManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
||||
}
|
||||
|
||||
void on_language_pack_changed();
|
||||
|
||||
void on_language_code_changed();
|
||||
|
||||
void on_language_pack_version_changed();
|
||||
|
||||
void get_languages(Promise<td_api::object_ptr<td_api::languagePack>> promise);
|
||||
|
||||
void get_language_pack_strings(string language_code, vector<string> keys,
|
||||
@ -34,12 +40,18 @@ class LanguagePackManager : public NetQueryCallback {
|
||||
|
||||
string language_pack_;
|
||||
string language_code_;
|
||||
uint32 generation_ = 0;
|
||||
|
||||
int32 language_pack_version_ = -1;
|
||||
|
||||
void inc_generation();
|
||||
|
||||
void on_get_language_pack_strings(Result<vector<tl_object_ptr<telegram_api::LangPackString>>> r_result, bool ia_all,
|
||||
Promise<td_api::object_ptr<td_api::languagePackStrings>> promise);
|
||||
|
||||
void on_result(NetQueryPtr query) override;
|
||||
|
||||
void start_up() override;
|
||||
void hangup() override;
|
||||
|
||||
Container<Promise<NetQueryPtr>> container_;
|
||||
|
@ -3502,15 +3502,17 @@ void Td::on_config_option_updated(const string &name) {
|
||||
G()->net_query_dispatcher().update_mtproto_header();
|
||||
}
|
||||
} else if (name == "language_pack") {
|
||||
send_closure(language_pack_manager_, &LanguagePackManager::on_language_pack_changed);
|
||||
if (G()->mtproto_header().set_language_pack(G()->shared_config().get_option_string(name))) {
|
||||
G()->net_query_dispatcher().update_mtproto_header();
|
||||
}
|
||||
} else if (name == "language_code") {
|
||||
send_closure(language_pack_manager_, &LanguagePackManager::on_language_code_changed);
|
||||
if (G()->mtproto_header().set_language_code(G()->shared_config().get_option_string(name))) {
|
||||
G()->net_query_dispatcher().update_mtproto_header();
|
||||
}
|
||||
} else if (name == "language_pack_version") {
|
||||
// TODO update language_pack
|
||||
send_closure(language_pack_manager_, &LanguagePackManager::on_language_pack_version_changed);
|
||||
return;
|
||||
} else if (is_internal_config_option(name)) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user