Add td_api::synchronizeLanguagePack method.
GitOrigin-RevId: a5ebac7c658c30c0e760f0176cddf6424348c6e9
This commit is contained in:
parent
f32ed5c405
commit
0e045bda6e
@ -3411,6 +3411,9 @@ getLanguagePackInfo language_pack_id:string = LanguagePackInfo;
|
|||||||
//@description Returns strings from a language pack in the current localization target by their keys @language_pack_id Language pack identifier of the strings to be returned @keys Language pack keys of the strings to be returned; leave empty to request all available strings
|
//@description Returns strings from a language pack in the current localization target by their keys @language_pack_id Language pack identifier of the strings to be returned @keys Language pack keys of the strings to be returned; leave empty to request all available strings
|
||||||
getLanguagePackStrings language_pack_id:string keys:vector<string> = LanguagePackStrings;
|
getLanguagePackStrings language_pack_id:string keys:vector<string> = LanguagePackStrings;
|
||||||
|
|
||||||
|
//@description Fetches latest versions of all strings from a language pack in the current localization target from the server. This method doesn't need to be called explicitly for the current used/base language packs @language_pack_id Language pack identifier
|
||||||
|
synchronizeLanguagePack language_pack_id:string = Ok;
|
||||||
|
|
||||||
//@description Adds a custom server language pack to the list of installed language packs in current localization target @language_pack_id Identifier of a language pack to be added; may be different from a name that is used in an "https://t.me/setlanguage/" link
|
//@description Adds a custom server language pack to the list of installed language packs in current localization target @language_pack_id Identifier of a language pack to be added; may be different from a name that is used in an "https://t.me/setlanguage/" link
|
||||||
addCustomServerLanguagePack language_pack_id:string = Ok;
|
addCustomServerLanguagePack language_pack_id:string = Ok;
|
||||||
|
|
||||||
@ -3423,7 +3426,7 @@ editCustomLanguagePackInfo info:languagePackInfo = Ok;
|
|||||||
//@description Adds, edits or deletes a string in a custom local language pack @language_pack_id Identifier of a previously added custom local language pack in the current localization target @new_string New language pack string
|
//@description Adds, edits or deletes a string in a custom local language pack @language_pack_id Identifier of a previously added custom local language pack in the current localization target @new_string New language pack string
|
||||||
setCustomLanguagePackString language_pack_id:string new_string:languagePackString = Ok;
|
setCustomLanguagePackString language_pack_id:string new_string:languagePackString = Ok;
|
||||||
|
|
||||||
//@description Deletes all information about a language pack in the current localization target. The language pack that is currently in use (including base language pack) can't be deleted @language_pack_id Identifier of the language pack to delete
|
//@description Deletes all information about a language pack in the current localization target. The language pack which is currently in use (including base language pack) or is being synchronized can't be deleted @language_pack_id Identifier of the language pack to delete
|
||||||
deleteLanguagePack language_pack_id:string = Ok;
|
deleteLanguagePack language_pack_id:string = Ok;
|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
@ -51,6 +51,7 @@ struct LanguagePackManager::Language {
|
|||||||
bool is_full_ = false;
|
bool is_full_ = false;
|
||||||
bool was_loaded_full_ = false;
|
bool was_loaded_full_ = false;
|
||||||
bool has_get_difference_query_ = false;
|
bool has_get_difference_query_ = false;
|
||||||
|
vector<Promise<Unit>> get_difference_queries_;
|
||||||
std::unordered_map<string, string> ordinary_strings_;
|
std::unordered_map<string, string> ordinary_strings_;
|
||||||
std::unordered_map<string, PluralizedString> pluralized_strings_;
|
std::unordered_map<string, PluralizedString> pluralized_strings_;
|
||||||
std::unordered_set<string> deleted_strings_;
|
std::unordered_set<string> deleted_strings_;
|
||||||
@ -299,11 +300,18 @@ void LanguagePackManager::on_language_pack_version_changed(bool is_base, int32 n
|
|||||||
|
|
||||||
LOG(INFO) << (is_base ? "Base" : "Main") << " language pack " << language_code << " vesrion has changed to "
|
LOG(INFO) << (is_base ? "Base" : "Main") << " language pack " << language_code << " vesrion has changed to "
|
||||||
<< new_version;
|
<< new_version;
|
||||||
|
send_language_get_difference_query(language, language_code, version, Auto());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LanguagePackManager::send_language_get_difference_query(Language *language, const string &language_code,
|
||||||
|
int32 version, Promise<Unit> &&promise) {
|
||||||
std::lock_guard<std::mutex> lock(language->mutex_);
|
std::lock_guard<std::mutex> lock(language->mutex_);
|
||||||
|
language->get_difference_queries_.push_back(std::move(promise));
|
||||||
if (language->has_get_difference_query_) {
|
if (language->has_get_difference_query_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK(language->get_difference_queries_.size() == 1);
|
||||||
language->has_get_difference_query_ = true;
|
language->has_get_difference_query_ = true;
|
||||||
auto request_promise =
|
auto request_promise =
|
||||||
PromiseCreator::lambda([actor_id = actor_id(this), language_pack = language_pack_, language_code,
|
PromiseCreator::lambda([actor_id = actor_id(this), language_pack = language_pack_, language_code,
|
||||||
@ -311,7 +319,7 @@ void LanguagePackManager::on_language_pack_version_changed(bool is_base, int32 n
|
|||||||
auto r_result = fetch_result<telegram_api::langpack_getDifference>(std::move(r_query));
|
auto r_result = fetch_result<telegram_api::langpack_getDifference>(std::move(r_query));
|
||||||
if (r_result.is_error()) {
|
if (r_result.is_error()) {
|
||||||
send_closure(actor_id, &LanguagePackManager::on_failed_get_difference, std::move(language_pack),
|
send_closure(actor_id, &LanguagePackManager::on_failed_get_difference, std::move(language_pack),
|
||||||
std::move(language_code));
|
std::move(language_code), r_result.move_as_error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,6 +1036,27 @@ void LanguagePackManager::load_empty_language_pack(const string &language_code)
|
|||||||
get_language_pack_strings(language_code, vector<string>(), Auto());
|
get_language_pack_strings(language_code, vector<string>(), Auto());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LanguagePackManager::synchronize_language_pack(string language_code, Promise<Unit> promise) {
|
||||||
|
if (!check_language_code_name(language_code) || language_code.empty()) {
|
||||||
|
return promise.set_error(Status::Error(400, "Language pack ID is invalid"));
|
||||||
|
}
|
||||||
|
if (language_pack_.empty()) {
|
||||||
|
return promise.set_error(Status::Error(400, "Option \"localization_target\" needs to be set first"));
|
||||||
|
}
|
||||||
|
if (is_custom_language_code(language_code)) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
Language *language = add_language(database_, language_pack_, language_code);
|
||||||
|
load_language_strings(database_, language, vector<string>());
|
||||||
|
|
||||||
|
int32 version = language->version_.load();
|
||||||
|
if (version == -1) {
|
||||||
|
version = 0;
|
||||||
|
}
|
||||||
|
send_language_get_difference_query(language, language_code, version, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
static td_api::object_ptr<td_api::LanguagePackStringValue> copy_language_pack_string_value(
|
static td_api::object_ptr<td_api::LanguagePackStringValue> copy_language_pack_string_value(
|
||||||
const td_api::LanguagePackStringValue *value) {
|
const td_api::LanguagePackStringValue *value) {
|
||||||
switch (value->get_id()) {
|
switch (value->get_id()) {
|
||||||
@ -1205,7 +1234,7 @@ void LanguagePackManager::on_get_language_pack_strings(
|
|||||||
int32 key_count_delta = 0;
|
int32 key_count_delta = 0;
|
||||||
if (language->version_ < version || !keys.empty()) {
|
if (language->version_ < version || !keys.empty()) {
|
||||||
vector<td_api::object_ptr<td_api::languagePackString>> strings;
|
vector<td_api::object_ptr<td_api::languagePackString>> strings;
|
||||||
if (language->version_ < version && !(is_diff && language->version_ == -1)) {
|
if (language->version_ < version) {
|
||||||
LOG(INFO) << "Set language pack " << language_code << " version to " << version;
|
LOG(INFO) << "Set language pack " << language_code << " version to " << version;
|
||||||
language->version_ = version;
|
language->version_ = version;
|
||||||
new_database_version = version;
|
new_database_version = version;
|
||||||
@ -1312,10 +1341,18 @@ void LanguagePackManager::on_get_language_pack_strings(
|
|||||||
|
|
||||||
if (is_diff) {
|
if (is_diff) {
|
||||||
CHECK(language != nullptr);
|
CHECK(language != nullptr);
|
||||||
std::lock_guard<std::mutex> lock(language->mutex_);
|
vector<Promise<Unit>> get_difference_queries;
|
||||||
if (language->has_get_difference_query_) {
|
{
|
||||||
language->has_get_difference_query_ = false;
|
std::lock_guard<std::mutex> lock(language->mutex_);
|
||||||
is_version_changed = true;
|
if (language->has_get_difference_query_) {
|
||||||
|
language->has_get_difference_query_ = false;
|
||||||
|
get_difference_queries = std::move(language->get_difference_queries_);
|
||||||
|
reset_to_empty(language->get_difference_queries_);
|
||||||
|
is_version_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto &query : get_difference_queries) {
|
||||||
|
query.set_value(Unit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_version_changed && language_pack == language_pack_ &&
|
if (is_version_changed && language_pack == language_pack_ &&
|
||||||
@ -1329,15 +1366,26 @@ void LanguagePackManager::on_get_language_pack_strings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanguagePackManager::on_failed_get_difference(string language_pack, string language_code) {
|
void LanguagePackManager::on_failed_get_difference(string language_pack, string language_code, Status error) {
|
||||||
Language *language = get_language(database_, language_pack, language_code);
|
Language *language = get_language(database_, language_pack, language_code);
|
||||||
CHECK(language != nullptr);
|
CHECK(language != nullptr);
|
||||||
std::lock_guard<std::mutex> lock(language->mutex_);
|
vector<Promise<Unit>> get_difference_queries;
|
||||||
if (language->has_get_difference_query_) {
|
{
|
||||||
language->has_get_difference_query_ = false;
|
std::lock_guard<std::mutex> lock(language->mutex_);
|
||||||
if (language_pack == language_pack_ && (language_code == language_code_ || language_code == base_language_code_)) {
|
if (language->has_get_difference_query_) {
|
||||||
send_closure_later(actor_id(this), &LanguagePackManager::on_language_pack_version_changed,
|
language->has_get_difference_query_ = false;
|
||||||
language_code != language_code_, -1);
|
if (language_pack == language_pack_ &&
|
||||||
|
(language_code == language_code_ || language_code == base_language_code_)) {
|
||||||
|
send_closure_later(actor_id(this), &LanguagePackManager::on_language_pack_version_changed,
|
||||||
|
language_code != language_code_, -1);
|
||||||
|
}
|
||||||
|
get_difference_queries = std::move(language->get_difference_queries_);
|
||||||
|
reset_to_empty(language->get_difference_queries_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto &query : get_difference_queries) {
|
||||||
|
if (query) {
|
||||||
|
query.set_error(error.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ class LanguagePackManager : public NetQueryCallback {
|
|||||||
const string &language_pack,
|
const string &language_pack,
|
||||||
const string &language_code, const string &key);
|
const string &language_code, const string &key);
|
||||||
|
|
||||||
|
void synchronize_language_pack(string language_code, Promise<Unit> promise);
|
||||||
|
|
||||||
void on_update_language_pack(tl_object_ptr<telegram_api::langPackDifference> difference);
|
void on_update_language_pack(tl_object_ptr<telegram_api::langPackDifference> difference);
|
||||||
|
|
||||||
void add_custom_server_language(string language_code, Promise<Unit> &&promise);
|
void add_custom_server_language(string language_code, Promise<Unit> &&promise);
|
||||||
@ -163,7 +165,10 @@ class LanguagePackManager : public NetQueryCallback {
|
|||||||
void on_get_all_language_pack_strings(string language_pack, string language_code,
|
void on_get_all_language_pack_strings(string language_pack, string language_code,
|
||||||
Result<td_api::object_ptr<td_api::languagePackStrings>> r_strings);
|
Result<td_api::object_ptr<td_api::languagePackStrings>> r_strings);
|
||||||
|
|
||||||
void on_failed_get_difference(string language_pack, string language_code);
|
void send_language_get_difference_query(Language *language, const string &language_code, int32 version,
|
||||||
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void on_failed_get_difference(string language_pack, string language_code, Status error);
|
||||||
|
|
||||||
void on_get_language_info(const string &language_pack, td_api::languagePackInfo *language_pack_info);
|
void on_get_language_info(const string &language_pack, td_api::languagePackInfo *language_pack_info);
|
||||||
|
|
||||||
|
@ -3189,6 +3189,7 @@ bool Td::is_preauthentication_request(int32 id) {
|
|||||||
case td_api::processPushNotification::ID:
|
case td_api::processPushNotification::ID:
|
||||||
case td_api::getLocalizationTargetInfo::ID:
|
case td_api::getLocalizationTargetInfo::ID:
|
||||||
case td_api::getLanguagePackStrings::ID:
|
case td_api::getLanguagePackStrings::ID:
|
||||||
|
case td_api::synchronizeLanguagePack::ID:
|
||||||
case td_api::setCustomLanguagePack::ID:
|
case td_api::setCustomLanguagePack::ID:
|
||||||
case td_api::editCustomLanguagePackInfo::ID:
|
case td_api::editCustomLanguagePackInfo::ID:
|
||||||
case td_api::setCustomLanguagePackString::ID:
|
case td_api::setCustomLanguagePackString::ID:
|
||||||
@ -6263,6 +6264,14 @@ void Td::on_request(uint64 id, td_api::getLanguagePackStrings &request) {
|
|||||||
std::move(request.language_pack_id_), std::move(request.keys_), std::move(promise));
|
std::move(request.language_pack_id_), std::move(request.keys_), std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, td_api::synchronizeLanguagePack &request) {
|
||||||
|
CHECK_IS_USER();
|
||||||
|
CLEAN_INPUT_STRING(request.language_pack_id_);
|
||||||
|
CREATE_OK_REQUEST_PROMISE();
|
||||||
|
send_closure(language_pack_manager_, &LanguagePackManager::synchronize_language_pack,
|
||||||
|
std::move(request.language_pack_id_), std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::addCustomServerLanguagePack &request) {
|
void Td::on_request(uint64 id, td_api::addCustomServerLanguagePack &request) {
|
||||||
CHECK_IS_USER();
|
CHECK_IS_USER();
|
||||||
CLEAN_INPUT_STRING(request.language_pack_id_);
|
CLEAN_INPUT_STRING(request.language_pack_id_);
|
||||||
|
@ -816,6 +816,8 @@ class Td final : public NetQueryCallback {
|
|||||||
|
|
||||||
void on_request(uint64 id, td_api::getLanguagePackStrings &request);
|
void on_request(uint64 id, td_api::getLanguagePackStrings &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, td_api::synchronizeLanguagePack &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::addCustomServerLanguagePack &request);
|
void on_request(uint64 id, td_api::addCustomServerLanguagePack &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::setCustomLanguagePack &request);
|
void on_request(uint64 id, td_api::setCustomLanguagePack &request);
|
||||||
|
@ -1861,6 +1861,9 @@ class CliClient final : public Actor {
|
|||||||
std::tie(language_code, key) = split(args);
|
std::tie(language_code, key) = split(args);
|
||||||
send_request(td_api::make_object<td_api::getLanguagePackString>(language_database_path, language_pack,
|
send_request(td_api::make_object<td_api::getLanguagePackString>(language_database_path, language_pack,
|
||||||
language_code, key));
|
language_code, key));
|
||||||
|
} else if (op == "synclp") {
|
||||||
|
string language_code = args;
|
||||||
|
send_request(td_api::make_object<td_api::synchronizeLanguagePack>(language_code));
|
||||||
} else if (op == "acslp") {
|
} else if (op == "acslp") {
|
||||||
string language_code = args;
|
string language_code = args;
|
||||||
send_request(td_api::make_object<td_api::addCustomServerLanguagePack>(language_code));
|
send_request(td_api::make_object<td_api::addCustomServerLanguagePack>(language_code));
|
||||||
|
Loading…
Reference in New Issue
Block a user