From ad26781fbcad99539c677feb84b851a3d4c8b35d Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 4 Sep 2018 04:29:26 +0300 Subject: [PATCH] Update language pack API. GitOrigin-RevId: 252723bc424afb8e0eb3c1647198e302b23e10db --- td/generate/scheme/td_api.tl | 47 +++++----- td/generate/scheme/td_api.tlo | Bin 133908 -> 133988 bytes td/telegram/ConfigManager.cpp | 13 +-- td/telegram/LanguagePackManager.cpp | 140 ++++++++++++++-------------- td/telegram/LanguagePackManager.h | 4 +- td/telegram/Td.cpp | 77 +++++++++------ td/telegram/Td.h | 10 +- td/telegram/cli.cpp | 24 ++--- 8 files changed, 166 insertions(+), 149 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 57561f9a..d105df8a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1703,16 +1703,16 @@ chatEvents events:vector = ChatEvents; chatEventLogFilters message_edits:Bool message_deletions:Bool message_pins:Bool member_joins:Bool member_leaves:Bool member_invites:Bool member_promotions:Bool member_restrictions:Bool info_changes:Bool setting_changes:Bool = ChatEventLogFilters; -//@class LanguagePackStringValue @description Represents a value of language pack string +//@class LanguagePackStringValue @description Represents the value of a string in a language pack //@description An ordinary language pack string @value String value languagePackStringValueOrdinary value:string = LanguagePackStringValue; -//@description A language pack string, which has different forms based on some quantity @zero_value Value for zero objects @one_value Value for one object @two_value Value for two objects +//@description A language pack string which has different forms based on the number of some object it mentions @zero_value Value for zero objects @one_value Value for one object @two_value Value for two objects //@few_value Value for few objects @many_value Value for many objects @other_value Default value languagePackStringValuePluralized zero_value:string one_value:string two_value:string few_value:string many_value:string other_value:string = LanguagePackStringValue; -//@description A deleted language pack string, the value should be taken from a built-in english language pack +//@description A deleted language pack string, the value should be taken from the built-in english language pack languagePackStringValueDeleted = LanguagePackStringValue; @@ -1722,11 +1722,11 @@ languagePackString key:string value:LanguagePackStringValue = LanguagePackString //@description Contains a list of language pack strings @strings A list of language pack strings languagePackStrings strings:vector = LanguagePackStrings; -//@description Contains information about a language @code Language code @name Language name @native_name Language native name @local_string_count Total number of locally available non-deleted strings from the language -languageInfo code:string name:string native_name:string local_string_count:int32 = LanguageInfo; +//@description Contains information about a language pack @id Unique language pack identifier @name Language name @native_name Name of the language in that language @local_string_count Total number of non-deleted strings from the language pack available locally +languagePackInfo id:string name:string native_name:string local_string_count:int32 = LanguagePackInfo; -//@description Contains information about a language pack @languages List of available languages -languagePack languages:vector = LanguagePack; +//@description Contains information about the current localization target @language_packs List of available language packs for this application +localizationTargetInfo language_packs:vector = LocalizationTargetInfo; //@class DeviceToken @description Represents a data needed to subscribe for push notifications. To use specific push notification service, you must specify the correct application platform and upload valid server authentication data at https://my.telegram.org @@ -2270,8 +2270,8 @@ updateFavoriteStickers sticker_ids:vector = Update; //@description The list of saved animations was updated @animation_ids The new list of file identifiers of saved animations updateSavedAnimations animation_ids:vector = Update; -//@description Some language pack strings was updated @language_pack Changed language pack @language_code Code of the language, which was updated @strings List of changed language pack strings -updateLanguagePackStrings language_pack:string language_code:string strings:vector = Update; +//@description Some language pack strings have been updated @localization_target Localization target to which the language pack belongs @language_pack_id Identifier of the updated language pack @strings List of changed language pack strings +updateLanguagePackStrings localization_target:string language_pack_id:string strings:vector = Update; //@description The connection state has changed @state The new connection state updateConnectionState state:ConnectionState = Update; @@ -2648,8 +2648,9 @@ getFileExtension mime_type:string = Text; //@description Removes potentially dangerous characters from the name of a file. The encoding of the file name is supposed to be UTF-8. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously @file_name File name or path to the file cleanFileName file_name:string = Text; -//@description Returns a string stored in a local database from specified language pack and language by its key. Returns a 404 error if the string is not found. This is an offline method. Can be called before authorization. Can be called synchronously @language_database_path Path to a language database in which strings are stored @language_pack Language pack of string to return @language_code Language code of string to return @key Language pack key of string to return -getLanguagePackString language_database_path:string language_pack:string language_code:string key:string = LanguagePackStringValue; +//@description Returns a string stored in the local database from the specified localization target and language pack by its key. Returns a 404 error if the string is not found. This is an offline method. Can be called before authorization. Can be called synchronously +//@language_pack_database_path Path to the language pack database in which strings are stored @localization_target Localization target to which the language pack belongs @language_pack_id Language pack identifier @key Language pack key of the string to be returned +getLanguagePackString language_pack_database_path:string localization_target:string language_pack_id:string key:string = LanguagePackStringValue; //@description Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires @bot_user_id The identifier of the target bot @@ -3130,23 +3131,23 @@ getSupportUser = User; getWallpapers = Wallpapers; -//@description Returns information about the used language pack -getLanguagePackInfo = LanguagePack; +//@description Returns information about the current localization target +getLocalizationTargetInfo = LocalizationTargetInfo; -//@description Returns strings from a language in the used language pack by their keys @language_code Language code of strings to return @keys Language pack keys of strings to return; may be empty to get all available strings -getLanguagePackStrings language_code:string keys:vector = LanguagePackStrings; +//@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 = LanguagePackStrings; -//@description Adds or changes a custom language to the used language pack @info Information about the language. Language code must start with 'X', consist only of English letters, digits and hyphens and be not longer than 64 characters @strings New language pack strings -setCustomLanguage info:languageInfo strings:vector = Ok; +//@description Adds or changes a custom language pack to the current localization target @info Information about the language pack. Language pack ID must start with 'X', consist only of English letters, digits and hyphens, and must not exceed 64 characters @strings Strings of the new language pack +setCustomLanguagePack info:languagePackInfo strings:vector = Ok; -//@description Edits informatioan about a custom language @info New information about the custom language -editCustomLanguageInfo info:languageInfo = Ok; +//@description Edits information about a custom language pack in the current localization target @info New information about the custom language pack +editCustomLanguagePackInfo info:languagePackInfo = Ok; -//@description Sets new value for a string in a custom language in the used language pack @language_code The code of previously added custom language, must start with 'X' @new_string New language pack string -setCustomLanguageString language_code:string new_string:languagePackString = Ok; +//@description Adds, edits or deletes a string in a custom language pack @language_pack_id Identifier of a previously added custom language pack in the current localization target @new_string New language pack string +setCustomLanguagePackString language_pack_id:string new_string:languagePackString = Ok; -//@description Deletes all information about a language in the used language pack. Currently used language can't be deleted @language_code Language code of a language to delete -deleteLanguage language_code:string = Ok; +//@description Deletes all information about a language pack in the current localization target. The language pack that is currently in use can't be deleted @language_pack_id Identifier of the language pack to delete +deleteLanguagePack language_pack_id:string = Ok; //@description Registers the currently used device for receiving push notifications @device_token Device token @other_user_ids List of at most 100 user identifiers of other users currently using the client diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 7f0b6bc7f7caf5494174bf9e24485f719588a87b..1945a205c93bdd8da8c9ce6bb85bb4836a90c046 100644 GIT binary patch delta 2216 zcmb7FUr1YL6wit2xR%k~{@IL6HZzDUV}XW|F{d#mCfaCXa@C|YtuAIws$rRi=SGp)E;6gtXO3UL9J<5?;!_hd@rfiCzxa;upru7%+3lv~Z-4vXxxnmF6`zl0$1U6 z(w|aWbzA3zTprArR4p-sr@@RD#nND%R+;#scOU((7wKI+(54iUgy!4rg6R!q96LQ& zi|xfjT}b~kChC{Uu4%yQjtWvLO5HW5LkAHp;b5{m2cT2TS z4dF*LIfS{3L#S3ajDxlfLygwZh4J3H{>I#V7;{&`kWsWm5aS}MmI(4yBao(Xma}!Q z0+0t0@KDE+=%CidSqPkZ@-Vaa8t)S8IWU^>Nof$zT6*P9*1v`^UVdmv;SXqL_dS2H zR6=m~8ieX?B{WPuL5vPVvnPSWu)yY!qWNE(@`Z!5ob(k12x{3ODq`6oocoe@jU!#!#*` zhK%Eg39DE1WUB#KV!8@OQbWA57X$vaH=Uco_fI5}=_H@5UtyZm*MI(4zeEm9kzD%- zPFHHz;g-(u8T(c6`D7x+duDR{^t<&$WPw1dyts&K7EH_c2^e&_U-lTHFM-8q*nc?U zM;d=So=b|Gik}pA=bHcDsgkvl*neTd*H0da?8gs^j+@09^pxRD+xT+B)6L>CKDeIg z=EW`gOJotFIYDl|2!t5*2(b{FAhfpzO!XM=`AvxoU? jYH9+fuT?JhA&qKKe?Tst@WZ(JWao@1N`TU0$l*?Hqxew((>NM2p`{11N_Ddzo zMo!|J+#A`#d-f~F$m}Z(PV|sl2~%DU}(< zkAsa%<`Yn{hh@t+cVSsIypEe+gB9mbfR&p((Ilq>M3nAZASD>|?AhX&t-I(+$MC z+(2xp78x6fLvExdOg4g-^Ck!jZxJ-nL}p7(gyl68r_@Z?yoSY^=|JUEV9|y`z_0E> zAI{wbJw81JZ9Jm2g{WBWINbscu86gyi&7-J4J&2HQGMkgB0S{!TOliZd z1X)_s5PCIiTEkWdQ^SaucbeMf(4@^Tp%NEP6G>cC7~5ckXEM=7Zn0%BDQo3MW${N7 zdTW5+fUuKtHajV2w=?6y2w3*Fde6Rf!snc^%9Wu7rhOBGA{Z*z4Dvgz)3LSiG!|*w zJ02YJh5UA3AfQXl=&FmNJl7<#od$feow8kOrwU9R+fM3ogBma14pwDF5^%8t0z55~ zo34=LCc5ixqBA~%U^@Ly!bUo2-sU^$q+^}LCv_1P=z=EhyR2b}E|5!h7Tj=q>P!(Y zSaBH-n02X=QyWX|3)_M()0P|vvQ>QMa50(()vX#F(BrKn9OGexZVGMfrfv;s*i1Kd z=7ok?J>bO6JCyrIPsS1H(dB`oDEGoFr{C<==yyXQTKnJuSG?$>Xeu9Jp0u&DWGzIg zA7;4idVji&ig(n4&K|HRvkzPG(|#yW79V-GFDCNdi-o@Z2V2nP$1`9&LXx-{ezJKU!$UZ(6 zy6_Qs;CBeG3GB&1^IuRF)!%@BitAkBRPw;EKSWmS*0meg^q`w&KV1QP(s0!dS@W Sm9>u5LA5a~x{;MNVfYuhD2-GA diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 94c98975..1ab3eafb 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -804,16 +804,16 @@ void ConfigManager::process_config(tl_object_ptr config) { if (is_from_main_dc) { shared_config.set_option_integer("webfile_dc_id", config->webfile_dc_id_); if ((config->flags_ & telegram_api::config::TMP_SESSIONS_MASK) != 0) { - G()->shared_config().set_option_integer("session_count", config->tmp_sessions_); + shared_config.set_option_integer("session_count", config->tmp_sessions_); } else { - G()->shared_config().set_option_empty("session_count"); + shared_config.set_option_empty("session_count"); } if ((config->flags_ & telegram_api::config::SUGGESTED_LANG_CODE_MASK) != 0) { - G()->shared_config().set_option_string("suggested_language_code", config->suggested_lang_code_); - G()->shared_config().set_option_integer("language_pack_version", config->lang_pack_version_); + shared_config.set_option_string("suggested_language_pack_id", config->suggested_lang_code_); + shared_config.set_option_integer("language_pack_version", config->lang_pack_version_); } else { - G()->shared_config().set_option_empty("suggested_language_code"); - G()->shared_config().set_option_empty("language_pack_version"); + shared_config.set_option_empty("suggested_language_pack_id"); + shared_config.set_option_empty("language_pack_version"); } } @@ -853,6 +853,7 @@ void ConfigManager::process_config(tl_object_ptr config) { } // delete outdated options + shared_config.set_option_empty("suggested_language_code"); shared_config.set_option_empty("chat_big_size"); shared_config.set_option_empty("group_size_max"); shared_config.set_option_empty("saved_gifs_limit"); diff --git a/td/telegram/LanguagePackManager.cpp b/td/telegram/LanguagePackManager.cpp index 86273367..15e97d8e 100644 --- a/td/telegram/LanguagePackManager.cpp +++ b/td/telegram/LanguagePackManager.cpp @@ -130,7 +130,7 @@ static int32 load_database_language_key_count(SqliteKeyValue *kv) { for (auto &str : kv->get_all()) { key_count += str.first[0] != '!' && (str.second[0] == '1' || str.second[0] == '2'); } - LOG(INFO) << "Set language key count in database to " << key_count; + LOG(INFO) << "Set language pack key count in database to " << key_count; kv->set("!key_count", to_string(key_count)); return key_count; } @@ -148,7 +148,7 @@ LanguagePackManager::LanguageDatabase *LanguagePackManager::add_language_databas if (!path.empty()) { auto r_database = open_database(path); if (r_database.is_error()) { - LOG(ERROR) << "Can't open language database " << path << ": " << r_database.error(); + LOG(ERROR) << "Can't open language pack database " << path << ": " << r_database.error(); return add_language_database(string()); } @@ -164,20 +164,20 @@ LanguagePackManager::LanguageDatabase *LanguagePackManager::add_language_databas void LanguagePackManager::start_up() { std::lock_guard lock(language_database_mutex_); manager_count_++; - language_pack_ = G()->shared_config().get_option_string("language_pack"); - language_code_ = G()->shared_config().get_option_string("language_code"); + language_pack_ = G()->shared_config().get_option_string("localization_target"); + language_code_ = G()->shared_config().get_option_string("language_pack_id"); CHECK(check_language_pack_name(language_pack_)); CHECK(check_language_code_name(language_code_)); - database_ = add_language_database(G()->shared_config().get_option_string("language_database_path")); + database_ = add_language_database(G()->shared_config().get_option_string("language_pack_database_path")); if (!language_pack_.empty() && !language_code_.empty()) { auto language = add_language(database_, language_pack_, language_code_); if (!is_custom_language_code(language_code_) && language->version_ == -1) { get_language_pack_strings(language_code_, vector(), Auto()); } - LOG(INFO) << "Use language pack \"" << language_pack_ << "\" with language \"" << language_code_ << "\" of version " - << language->version_.load() << " with database \"" << database_->path_ << '"'; + LOG(INFO) << "Use localization target \"" << language_pack_ << "\" with language pack \"" << language_code_ + << "\" of version " << language->version_.load() << " with database \"" << database_->path_ << '"'; } } @@ -185,14 +185,14 @@ void LanguagePackManager::tear_down() { std::lock_guard lock(language_database_mutex_); manager_count_--; if (manager_count_ == 0) { - // can't clear language packs, because the may be accessed later using synchronous requests + // can't clear language packs, because they may be accessed later using synchronous requests // LOG(INFO) << "Clear language packs"; // language_databases_.clear(); } } void LanguagePackManager::on_language_pack_changed() { - auto new_language_pack = G()->shared_config().get_option_string("language_pack"); + auto new_language_pack = G()->shared_config().get_option_string("localization_target"); if (new_language_pack == language_pack_) { return; } @@ -203,7 +203,7 @@ void LanguagePackManager::on_language_pack_changed() { } void LanguagePackManager::on_language_code_changed() { - auto new_language_code = G()->shared_config().get_option_string("language_code"); + auto new_language_code = G()->shared_config().get_option_string("language_pack_id"); if (new_language_code == language_code_) { return; } @@ -248,7 +248,7 @@ void LanguagePackManager::on_language_pack_version_changed(int32 new_version) { } auto result = r_result.move_as_ok(); - LOG(INFO) << "Receive language pack difference for language " << result->lang_code_ << " from version " + LOG(INFO) << "Receive language pack difference for language pack " << result->lang_code_ << " from version " << result->from_version_ << " with version " << result->version_ << " of size " << result->strings_.size(); LOG_IF(ERROR, result->lang_code_ != language_code) @@ -264,30 +264,31 @@ void LanguagePackManager::on_language_pack_version_changed(int32 new_version) { } void LanguagePackManager::on_update_language_pack(tl_object_ptr difference) { - LOG(INFO) << "Receive update language pack difference for language " << difference->lang_code_ << " from version " - << difference->from_version_ << " with version " << difference->version_ << " of size " + LOG(INFO) << "Receive update language pack difference for language pack " << difference->lang_code_ + << " from version " << difference->from_version_ << " with version " << difference->version_ << " of size " << difference->strings_.size(); if (language_pack_.empty()) { - LOG(WARNING) << "Ignore difference for language " << difference->lang_code_ << ", because language pack was unset"; + LOG(WARNING) << "Ignore difference for language pack " << difference->lang_code_ + << ", because used language pack was unset"; return; } if (difference->lang_code_ != language_code_) { - LOG(WARNING) << "Ignore difference for language " << difference->lang_code_; + LOG(WARNING) << "Ignore difference for language pack " << difference->lang_code_; return; } if (is_custom_language_code(difference->lang_code_) || difference->lang_code_.empty()) { - LOG(ERROR) << "Ignore difference for language " << difference->lang_code_; + LOG(ERROR) << "Ignore difference for language pack " << difference->lang_code_; return; } Language *language = get_language(database_, language_pack_, language_code_); int32 version = language == nullptr ? static_cast(-1) : language->version_.load(); if (difference->version_ <= version) { - LOG(INFO) << "Skip applying already applied updates"; + LOG(INFO) << "Skip applying already applied language pack updates"; return; } if (version == -1 || version < difference->from_version_) { - LOG(INFO) << "Can't apply difference"; + LOG(INFO) << "Can't apply language pack difference"; return on_language_pack_version_changed(difference->version_); } @@ -421,17 +422,17 @@ bool LanguagePackManager::load_language_strings(LanguageDatabase *database, Lang std::lock_guard database_lock(database->mutex_); std::lock_guard language_lock(language->mutex_); if (language->is_full_) { - LOG(DEBUG) << "The language is full in memory"; + LOG(DEBUG) << "The language pack is already full in memory"; return true; } if (language->kv_.empty()) { - LOG(DEBUG) << "The language has no database"; + LOG(DEBUG) << "The language pack has no database"; return false; } - LOG(DEBUG) << "Begin to load a language from database"; + LOG(DEBUG) << "Begin to load a language pack from database"; if (keys.empty()) { if (language->version_ == -1 && language->was_loaded_full_) { - LOG(DEBUG) << "The language has already been loaded"; + LOG(DEBUG) << "The language pack has already been loaded"; return false; } @@ -548,9 +549,9 @@ td_api::object_ptr LanguagePackManager::get_languag return td_api::make_object(std::move(strings)); } -void LanguagePackManager::get_languages(Promise> promise) { +void LanguagePackManager::get_languages(Promise> promise) { if (language_pack_.empty()) { - return promise.set_error(Status::Error(400, "Option \"language_pack\" needs to be set first")); + return promise.set_error(Status::Error(400, "Option \"localization_target\" needs to be set first")); } auto request_promise = PromiseCreator::lambda([actor_id = actor_id(this), language_pack = language_pack_, @@ -569,8 +570,8 @@ void LanguagePackManager::get_languages(Promise> languages, string language_pack, - Promise> promise) { - auto results = make_tl_object(); + Promise> promise) { + auto results = td_api::make_object(); { std::lock_guard packs_lock(database_->mutex_); @@ -578,24 +579,24 @@ void LanguagePackManager::on_get_languages(vectorlanguage_packs_.end()) { LanguagePack *pack = pack_it->second.get(); for (auto &info : pack->language_infos_) { - results->languages_.push_back( - make_tl_object(info.first, info.second.name, info.second.native_name, 0)); + results->language_packs_.push_back( + make_tl_object(info.first, info.second.name, info.second.native_name, 0)); } } } for (auto &language : languages) { - results->languages_.push_back( - make_tl_object(language->lang_code_, language->name_, language->native_name_, 0)); + results->language_packs_.push_back( + make_tl_object(language->lang_code_, language->name_, language->native_name_, 0)); } - for (auto &language_info : results->languages_) { - if (!check_language_code_name(language_info->code_)) { - LOG(ERROR) << "Receive unsupported language code " << language_info->code_ << " from server"; + for (auto &language_info : results->language_packs_) { + if (!check_language_code_name(language_info->id_)) { + LOG(ERROR) << "Receive unsupported language pack ID " << language_info->id_ << " from server"; continue; } - auto language = add_language(database_, language_pack, language_info->code_); + auto language = add_language(database_, language_pack, language_info->id_); language_info->local_string_count_ = language->key_count_; } @@ -605,10 +606,10 @@ void LanguagePackManager::on_get_languages(vector keys, Promise> promise) { if (!check_language_code_name(language_code) || language_code.empty()) { - return promise.set_error(Status::Error(400, "Language code is invalid")); + return promise.set_error(Status::Error(400, "Language pack ID is invalid")); } if (language_pack_.empty()) { - return promise.set_error(Status::Error(400, "Option \"language_pack\" needs to be set first")); + return promise.set_error(Status::Error(400, "Option \"localization_target\" needs to be set first")); } for (auto &key : keys) { if (!is_valid_key(key)) { @@ -651,12 +652,11 @@ void LanguagePackManager::get_language_pack_strings(string language_code, vector } auto result = r_result.move_as_ok(); - LOG(INFO) << "Receive language pack for language " << result->lang_code_ << " from version " - << result->from_version_ << " with version " << result->version_ << " of size " - << result->strings_.size(); + LOG(INFO) << "Receive language pack " << result->lang_code_ << " from version " << result->from_version_ + << " with version " << result->version_ << " of size " << result->strings_.size(); LOG_IF(ERROR, result->lang_code_ != language_code) << "Receive strings for " << result->lang_code_ << " instead of " << language_code; - LOG_IF(ERROR, result->from_version_ != 0) << "Receive lang pack from version " << result->from_version_; + LOG_IF(ERROR, result->from_version_ != 0) << "Receive language pack from version " << result->from_version_; send_closure(actor_id, &LanguagePackManager::on_get_language_pack_strings, std::move(language_pack), std::move(language_code), result->version_, false, vector(), std::move(result->strings_), std::move(promise)); @@ -731,10 +731,10 @@ void LanguagePackManager::on_get_all_language_pack_strings( for (auto &promise : promises) { if (promise) { if (left_non_empty_promise_count == 1) { - LOG(INFO) << "Set last non-empty promise"; + LOG(DEBUG) << "Set last non-empty promise"; promise.set_value(std::move(strings)); } else { - LOG(INFO) << "Set non-empty promise"; + LOG(DEBUG) << "Set non-empty promise"; vector> strings_copy; for (auto &result : strings->strings_) { CHECK(result != nullptr); @@ -745,7 +745,7 @@ void LanguagePackManager::on_get_all_language_pack_strings( } left_non_empty_promise_count--; } else { - LOG(INFO) << "Set empty promise"; + LOG(DEBUG) << "Set empty promise"; promise.set_value(nullptr); } } @@ -757,10 +757,10 @@ td_api::object_ptr LanguagePackManager::get_language_pack_string const string &language_code, const string &key) { if (!check_language_pack_name(language_pack) || language_pack.empty()) { - return td_api::make_object(400, "Language pack is invalid"); + return td_api::make_object(400, "Localization target is invalid"); } if (!check_language_code_name(language_code) || language_code.empty()) { - return td_api::make_object(400, "Language code is invalid"); + return td_api::make_object(400, "Language pack ID is invalid"); } if (!is_valid_key(key)) { return td_api::make_object(400, "Key is invalid"); @@ -795,7 +795,7 @@ bool LanguagePackManager::is_valid_key(Slice key) { void LanguagePackManager::save_strings_to_database(SqliteKeyValue *kv, int32 new_version, bool new_is_full, int32 new_key_count, vector> strings) { - LOG(DEBUG) << "Save to database a language with new version " << new_version << " and " << strings.size() + LOG(DEBUG) << "Save to database a language pack with new version " << new_version << " and " << strings.size() << " new strings"; if (new_version == -1 && strings.empty()) { return; @@ -809,7 +809,7 @@ void LanguagePackManager::save_strings_to_database(SqliteKeyValue *kv, int32 new } auto old_version = load_database_language_version(kv); if (old_version > new_version || (old_version == new_version && strings.empty())) { - LOG(DEBUG) << "Language version doesn't increased from " << old_version; + LOG(DEBUG) << "Language pack version doesn't increased from " << old_version; return; } @@ -825,14 +825,14 @@ void LanguagePackManager::save_strings_to_database(SqliteKeyValue *kv, int32 new } else { kv->set(str.first, str.second); } - LOG(DEBUG) << "Save language string with key " << str.first << " to database"; + LOG(DEBUG) << "Save language pack string with key " << str.first << " to database"; } if (old_version != new_version) { - LOG(DEBUG) << "Set language version in database to " << new_version; + LOG(DEBUG) << "Set language pack version in database to " << new_version; kv->set("!version", to_string(new_version)); } if (new_key_count != -1) { - LOG(DEBUG) << "Set language key count in database to " << new_key_count; + LOG(DEBUG) << "Set language pack key count in database to " << new_key_count; kv->set("!key_count", to_string(new_key_count)); } kv->commit_transaction().ensure(); @@ -860,7 +860,7 @@ void LanguagePackManager::on_get_language_pack_strings( if (language->version_ < version || !keys.empty()) { vector> strings; if (language->version_ < version && !(is_diff && language->version_ == -1)) { - LOG(INFO) << "Set language " << language_code << " version to " << version; + LOG(INFO) << "Set language pack " << language_code << " version to " << version; language->version_ = version; new_database_version = version; is_version_changed = true; @@ -996,7 +996,7 @@ void LanguagePackManager::on_failed_get_difference(string language_pack, string Result> LanguagePackManager::convert_to_telegram_api( tl_object_ptr &&str) { if (str == nullptr) { - return Status::Error(400, "Language strings must not be null"); + return Status::Error(400, "Language pack strings must not be null"); } string key = std::move(str->key_); @@ -1011,7 +1011,7 @@ Result> LanguagePackManager::convert case td_api::languagePackStringValueOrdinary::ID: { auto value = static_cast(str->value_.get()); if (!clean_input_string(value->value_)) { - return Status::Error(400, "Strings must be encoded in UTF-8"); + return Status::Error(400, "Language pack string value must be encoded in UTF-8"); } return make_tl_object(std::move(key), std::move(value->value_)); } @@ -1020,7 +1020,7 @@ Result> LanguagePackManager::convert if (!clean_input_string(value->zero_value_) || !clean_input_string(value->one_value_) || !clean_input_string(value->two_value_) || !clean_input_string(value->few_value_) || !clean_input_string(value->many_value_) || !clean_input_string(value->other_value_)) { - return Status::Error(400, "Strings must be encoded in UTF-8"); + return Status::Error(400, "Language pack string value must be encoded in UTF-8"); } return make_tl_object( 31, std::move(key), std::move(value->zero_value_), std::move(value->one_value_), std::move(value->two_value_), @@ -1039,13 +1039,13 @@ void LanguagePackManager::set_custom_language(string language_code, string langu vector> strings, Promise &&promise) { if (language_pack_.empty()) { - return promise.set_error(Status::Error(400, "Option \"language_pack\" needs to be set first")); + return promise.set_error(Status::Error(400, "Option \"localization_target\" needs to be set first")); } if (!check_language_code_name(language_code)) { - return promise.set_error(Status::Error(400, "Language code name must contain only letters and hyphen")); + return promise.set_error(Status::Error(400, "Language pack ID must contain only letters, digits and hyphen")); } if (!is_custom_language_code(language_code)) { - return promise.set_error(Status::Error(400, "Custom language code must begin with 'X'")); + return promise.set_error(Status::Error(400, "Custom language pack ID must begin with 'X'")); } vector> server_strings; @@ -1078,13 +1078,13 @@ void LanguagePackManager::set_custom_language(string language_code, string langu void LanguagePackManager::edit_custom_language_info(string language_code, string language_name, string language_native_name, Promise &&promise) { if (language_pack_.empty()) { - return promise.set_error(Status::Error(400, "Option \"language_pack\" needs to be set first")); + return promise.set_error(Status::Error(400, "Option \"localization_target\" needs to be set first")); } if (!check_language_code_name(language_code)) { - return promise.set_error(Status::Error(400, "Language code name must contain only letters and hyphen")); + return promise.set_error(Status::Error(400, "Language pack ID must contain only letters, digits and hyphen")); } if (!is_custom_language_code(language_code)) { - return promise.set_error(Status::Error(400, "Custom language code must begin with 'X'")); + return promise.set_error(Status::Error(400, "Custom language pack ID must begin with 'X'")); } std::lock_guard packs_lock(database_->mutex_); @@ -1109,20 +1109,20 @@ void LanguagePackManager::set_custom_language_string(string language_code, tl_object_ptr str, Promise &&promise) { if (language_pack_.empty()) { - return promise.set_error(Status::Error(400, "Option \"language_pack\" needs to be set first")); + return promise.set_error(Status::Error(400, "Option \"localization_target\" needs to be set first")); } if (!check_language_code_name(language_code)) { - return promise.set_error(Status::Error(400, "Language code name must contain only letters and hyphen")); + return promise.set_error(Status::Error(400, "Language pack ID must contain only letters, digits and hyphen")); } if (!is_custom_language_code(language_code)) { - return promise.set_error(Status::Error(400, "Custom language code must begin with 'X'")); + return promise.set_error(Status::Error(400, "Custom language pack ID must begin with 'X'")); } if (get_language(database_, language_pack_, language_code) == nullptr) { - return promise.set_error(Status::Error(400, "Custom language not found")); + return promise.set_error(Status::Error(400, "Custom language pack not found")); } if (str == nullptr) { - return promise.set_error(Status::Error(400, "Language strings must not be null")); + return promise.set_error(Status::Error(400, "Language pack strings must not be null")); } vector keys{str->key_}; @@ -1142,16 +1142,16 @@ void LanguagePackManager::set_custom_language_string(string language_code, void LanguagePackManager::delete_language(string language_code, Promise &&promise) { if (language_pack_.empty()) { - return promise.set_error(Status::Error(400, "Option \"language_pack\" needs to be set first")); + return promise.set_error(Status::Error(400, "Option \"localization_target\" needs to be set first")); } if (!check_language_code_name(language_code)) { - return promise.set_error(Status::Error(400, "Language code name is invalid")); + return promise.set_error(Status::Error(400, "Language pack ID is invalid")); } if (language_code.empty()) { - return promise.set_error(Status::Error(400, "Language code name is empty")); + return promise.set_error(Status::Error(400, "Language pack ID is empty")); } if (language_code_ == language_code) { - return promise.set_error(Status::Error(400, "Currently used language can't be deleted")); + return promise.set_error(Status::Error(400, "Currently used language pack can't be deleted")); } auto status = do_delete_language(language_code); @@ -1175,7 +1175,7 @@ Status LanguagePackManager::do_delete_language(string language_code) { CHECK(code_it != pack->languages_.end()); auto language = code_it->second.get(); if (language->has_get_difference_query_) { - return Status::Error(400, "Language can't be deleted now, try again later"); + return Status::Error(400, "Language pack can't be deleted now, try again later"); } if (!language->kv_.empty()) { language->kv_.drop().ignore(); diff --git a/td/telegram/LanguagePackManager.h b/td/telegram/LanguagePackManager.h index 2cf23fff..bf470890 100644 --- a/td/telegram/LanguagePackManager.h +++ b/td/telegram/LanguagePackManager.h @@ -48,7 +48,7 @@ class LanguagePackManager : public NetQueryCallback { void on_language_pack_version_changed(int32 new_version); - void get_languages(Promise> promise); + void get_languages(Promise> promise); void get_language_pack_strings(string language_code, vector keys, Promise> promise); @@ -147,7 +147,7 @@ class LanguagePackManager : public NetQueryCallback { void on_failed_get_difference(string language_pack, string language_code); void on_get_languages(vector> languages, string language_pack, - Promise> promise); + Promise> promise); Status do_delete_language(string language_code); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 5edef61e..d2d3b6e1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3265,12 +3265,12 @@ bool Td::is_preinitialization_request(int32 id) { bool Td::is_preauthentication_request(int32 id) { switch (id) { case td_api::processDcUpdate::ID: - case td_api::getLanguagePackInfo::ID: + case td_api::getLocalizationTargetInfo::ID: case td_api::getLanguagePackStrings::ID: - case td_api::setCustomLanguage::ID: - case td_api::editCustomLanguageInfo::ID: - case td_api::setCustomLanguageString::ID: - case td_api::deleteLanguage::ID: + case td_api::setCustomLanguagePack::ID: + case td_api::editCustomLanguagePackInfo::ID: + case td_api::setCustomLanguagePackString::ID: + case td_api::deleteLanguagePack::ID: case td_api::getOption::ID: case td_api::setOption::ID: case td_api::setNetworkType::ID: @@ -3541,12 +3541,12 @@ void Td::on_config_option_updated(const string &name) { if (G()->mtproto_header().set_is_emulator(G()->shared_config().get_option_boolean(name))) { G()->net_query_dispatcher().update_mtproto_header(); } - } else if (name == "language_pack") { + } else if (name == "localization_target") { 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") { + } else if (name == "language_pack_id") { 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(); @@ -4020,6 +4020,21 @@ Status Td::init(DbKey key) { config_manager_ = create_actor("ConfigManager", create_reference()); G()->set_config_manager(config_manager_.get()); + if (G()->shared_config().have_option("language_database_path")) { + G()->shared_config().set_option_string("language_pack_database_path", + G()->shared_config().get_option_string("language_database_path")); + G()->shared_config().set_option_empty("language_database_path"); + } + if (G()->shared_config().have_option("language_pack")) { + G()->shared_config().set_option_string("localization_target", + G()->shared_config().get_option_string("language_pack")); + G()->shared_config().set_option_empty("language_pack"); + } + if (G()->shared_config().have_option("language_code")) { + G()->shared_config().set_option_string("language_pack_id", G()->shared_config().get_option_string("language_code")); + G()->shared_config().set_option_empty("language_code"); + } + complete_pending_preauthentication_requests([](int32 id) { switch (id) { case td_api::getOption::ID: @@ -4030,8 +4045,8 @@ Status Td::init(DbKey key) { } }); - options_.language_pack = G()->shared_config().get_option_string("language_pack"); - options_.language_code = G()->shared_config().get_option_string("language_code"); + options_.language_pack = G()->shared_config().get_option_string("localization_target"); + options_.language_code = G()->shared_config().get_option_string("language_pack_id"); options_.is_emulator = G()->shared_config().get_option_boolean("is_emulator"); // options_.proxy = Proxy(); G()->set_mtproto_header(std::make_unique(options_)); @@ -6024,7 +6039,7 @@ void Td::on_request(uint64 id, const td_api::getMapThumbnailFile &request) { } } -void Td::on_request(uint64 id, const td_api::getLanguagePackInfo &request) { +void Td::on_request(uint64 id, const td_api::getLocalizationTargetInfo &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); send_closure(language_pack_manager_, &LanguagePackManager::get_languages, std::move(promise)); @@ -6032,55 +6047,55 @@ void Td::on_request(uint64 id, const td_api::getLanguagePackInfo &request) { void Td::on_request(uint64 id, td_api::getLanguagePackStrings &request) { CHECK_IS_USER(); - CLEAN_INPUT_STRING(request.language_code_); + CLEAN_INPUT_STRING(request.language_pack_id_); for (auto &key : request.keys_) { CLEAN_INPUT_STRING(key); } CREATE_REQUEST_PROMISE(); send_closure(language_pack_manager_, &LanguagePackManager::get_language_pack_strings, - std::move(request.language_code_), 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::setCustomLanguage &request) { +void Td::on_request(uint64 id, td_api::setCustomLanguagePack &request) { CHECK_IS_USER(); if (request.info_ == nullptr) { - return send_error_raw(id, 400, "Language info must not be empty"); + return send_error_raw(id, 400, "Language pack info must not be empty"); } - CLEAN_INPUT_STRING(request.info_->code_); + CLEAN_INPUT_STRING(request.info_->id_); CLEAN_INPUT_STRING(request.info_->name_); CLEAN_INPUT_STRING(request.info_->native_name_); CREATE_OK_REQUEST_PROMISE(); - send_closure(language_pack_manager_, &LanguagePackManager::set_custom_language, std::move(request.info_->code_), + send_closure(language_pack_manager_, &LanguagePackManager::set_custom_language, std::move(request.info_->id_), std::move(request.info_->name_), std::move(request.info_->native_name_), std::move(request.strings_), std::move(promise)); } -void Td::on_request(uint64 id, td_api::editCustomLanguageInfo &request) { +void Td::on_request(uint64 id, td_api::editCustomLanguagePackInfo &request) { CHECK_IS_USER(); if (request.info_ == nullptr) { - return send_error_raw(id, 400, "Language info must not be empty"); + return send_error_raw(id, 400, "Language pack info must not be empty"); } - CLEAN_INPUT_STRING(request.info_->code_); + CLEAN_INPUT_STRING(request.info_->id_); CLEAN_INPUT_STRING(request.info_->name_); CLEAN_INPUT_STRING(request.info_->native_name_); CREATE_OK_REQUEST_PROMISE(); - send_closure(language_pack_manager_, &LanguagePackManager::edit_custom_language_info, std::move(request.info_->code_), + send_closure(language_pack_manager_, &LanguagePackManager::edit_custom_language_info, std::move(request.info_->id_), std::move(request.info_->name_), std::move(request.info_->native_name_), std::move(promise)); } -void Td::on_request(uint64 id, td_api::setCustomLanguageString &request) { +void Td::on_request(uint64 id, td_api::setCustomLanguagePackString &request) { CHECK_IS_USER(); - CLEAN_INPUT_STRING(request.language_code_); + CLEAN_INPUT_STRING(request.language_pack_id_); CREATE_OK_REQUEST_PROMISE(); send_closure(language_pack_manager_, &LanguagePackManager::set_custom_language_string, - std::move(request.language_code_), std::move(request.new_string_), std::move(promise)); + std::move(request.language_pack_id_), std::move(request.new_string_), std::move(promise)); } -void Td::on_request(uint64 id, td_api::deleteLanguage &request) { +void Td::on_request(uint64 id, td_api::deleteLanguagePack &request) { CHECK_IS_USER(); - CLEAN_INPUT_STRING(request.language_code_); + CLEAN_INPUT_STRING(request.language_pack_id_); CREATE_OK_REQUEST_PROMISE(); - send_closure(language_pack_manager_, &LanguagePackManager::delete_language, std::move(request.language_code_), + send_closure(language_pack_manager_, &LanguagePackManager::delete_language, std::move(request.language_pack_id_), std::move(promise)); } @@ -6200,13 +6215,13 @@ void Td::on_request(uint64 id, td_api::setOption &request) { } break; case 'l': - if (set_string_option("language_database_path", [](Slice value) { return true; })) { + if (set_string_option("language_pack_database_path", [](Slice value) { return true; })) { return; } - if (set_string_option("language_pack", LanguagePackManager::check_language_pack_name)) { + if (set_string_option("localization_target", LanguagePackManager::check_language_pack_name)) { return; } - if (set_string_option("language_code", LanguagePackManager::check_language_code_name)) { + if (set_string_option("language_pack_id", LanguagePackManager::check_language_code_name)) { return; } break; @@ -6778,8 +6793,8 @@ td_api::object_ptr Td::do_static_request(const td_api::cleanFile } td_api::object_ptr Td::do_static_request(const td_api::getLanguagePackString &request) { - return LanguagePackManager::get_language_pack_string(request.language_database_path_, request.language_pack_, - request.language_code_, request.key_); + return LanguagePackManager::get_language_pack_string( + request.language_pack_database_path_, request.localization_target_, request.language_pack_id_, request.key_); } // test diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 3eb800f8..f93f7b9d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -763,17 +763,17 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::getMapThumbnailFile &request); - void on_request(uint64 id, const td_api::getLanguagePackInfo &request); + void on_request(uint64 id, const td_api::getLocalizationTargetInfo &request); void on_request(uint64 id, td_api::getLanguagePackStrings &request); - void on_request(uint64 id, td_api::setCustomLanguage &request); + void on_request(uint64 id, td_api::setCustomLanguagePack &request); - void on_request(uint64 id, td_api::editCustomLanguageInfo &request); + void on_request(uint64 id, td_api::editCustomLanguagePackInfo &request); - void on_request(uint64 id, td_api::setCustomLanguageString &request); + void on_request(uint64 id, td_api::setCustomLanguagePackString &request); - void on_request(uint64 id, td_api::deleteLanguage &request); + void on_request(uint64 id, td_api::deleteLanguagePack &request); void on_request(uint64 id, td_api::getOption &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index ef491a51..fe5d9ed1 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1750,8 +1750,8 @@ class CliClient final : public Actor { std::tie(chat_id, message_id) = split(args); send_request(make_tl_object(as_chat_id(chat_id), as_message_id(message_id))); - } else if (op == "glpi") { - send_request(make_tl_object()); + } else if (op == "glti") { + send_request(make_tl_object()); } else if (op == "glps") { string language_code; string keys; @@ -1769,7 +1769,7 @@ class CliClient final : public Actor { std::tie(language_code, key) = split(args); send_request( make_tl_object(language_database_path, language_pack, language_code, key)); - } else if (op == "scl") { + } else if (op == "sclp") { string language_code; string name; string native_name; @@ -1788,9 +1788,9 @@ class CliClient final : public Actor { strings.push_back(make_tl_object( "DELETED", make_tl_object())); - send_request(make_tl_object( - make_tl_object(language_code, name, native_name, 3), std::move(strings))); - } else if (op == "ecli") { + send_request(make_tl_object( + make_tl_object(language_code, name, native_name, 3), std::move(strings))); + } else if (op == "eclpi") { string language_code; string name; string native_name; @@ -1798,9 +1798,9 @@ class CliClient final : public Actor { std::tie(language_code, args) = split(args); std::tie(name, native_name) = split(args); - send_request(make_tl_object( - make_tl_object(language_code, name, native_name, 3))); - } else if (op == "sclsv" || op == "sclsp" || op == "sclsd") { + send_request(make_tl_object( + make_tl_object(language_code, name, native_name, 3))); + } else if (op == "sclpsv" || op == "sclpsp" || op == "sclpsd") { string language_code; string key; string value; @@ -1818,9 +1818,9 @@ class CliClient final : public Actor { str->value_ = make_tl_object(); } - send_request(make_tl_object(language_code, std::move(str))); - } else if (op == "dl") { - send_request(make_tl_object(args)); + send_request(make_tl_object(language_code, std::move(str))); + } else if (op == "dlp") { + send_request(make_tl_object(args)); } else if (op == "go") { send_request(make_tl_object(args)); } else if (op == "sob") {