Init base LanguagePackManager fields in constuctor.
This commit is contained in:
parent
e897298527
commit
12abea736f
@ -281,7 +281,7 @@ std::unordered_map<string, string> Global::get_options() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Global::get_option_boolean(Slice name, bool default_value) const {
|
bool Global::get_option_boolean(Slice name, bool default_value) const {
|
||||||
return shared_config_->get_option_integer(name, default_value);
|
return shared_config_->get_option_boolean(name, default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 Global::get_option_integer(Slice name, int64 default_value) const {
|
int64 Global::get_option_integer(Slice name, int64 default_value) const {
|
||||||
|
@ -63,7 +63,7 @@ struct LanguagePackManager::Language {
|
|||||||
FlatHashMap<string, string> ordinary_strings_;
|
FlatHashMap<string, string> ordinary_strings_;
|
||||||
FlatHashMap<string, unique_ptr<PluralizedString>> pluralized_strings_;
|
FlatHashMap<string, unique_ptr<PluralizedString>> pluralized_strings_;
|
||||||
FlatHashSet<string> deleted_strings_;
|
FlatHashSet<string> deleted_strings_;
|
||||||
SqliteKeyValue kv_; // usages should be guarded by database_->mutex_
|
SqliteKeyValue kv_; // usages must be guarded by database_->mutex_
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LanguagePackManager::LanguageInfo {
|
struct LanguagePackManager::LanguageInfo {
|
||||||
@ -90,7 +90,7 @@ struct LanguagePackManager::LanguageInfo {
|
|||||||
|
|
||||||
struct LanguagePackManager::LanguagePack {
|
struct LanguagePackManager::LanguagePack {
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
SqliteKeyValue pack_kv_; // usages should be guarded by database_->mutex_
|
SqliteKeyValue pack_kv_; // usages must be guarded by database_->mutex_
|
||||||
std::map<string, LanguageInfo> custom_language_pack_infos_; // sorted by language_code
|
std::map<string, LanguageInfo> custom_language_pack_infos_; // sorted by language_code
|
||||||
vector<std::pair<string, LanguageInfo>> server_language_pack_infos_; // sorted by server
|
vector<std::pair<string, LanguageInfo>> server_language_pack_infos_; // sorted by server
|
||||||
FlatHashMap<string, unique_ptr<LanguageInfo>> all_server_language_pack_infos_;
|
FlatHashMap<string, unique_ptr<LanguageInfo>> all_server_language_pack_infos_;
|
||||||
@ -198,7 +198,7 @@ LanguagePackManager::LanguageDatabase *LanguagePackManager::add_language_databas
|
|||||||
return it->second.get();
|
return it->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanguagePackManager::start_up() {
|
LanguagePackManager::LanguagePackManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
||||||
std::lock_guard<std::mutex> database_lock(language_database_mutex_);
|
std::lock_guard<std::mutex> database_lock(language_database_mutex_);
|
||||||
manager_count_++;
|
manager_count_++;
|
||||||
language_pack_ = G()->get_option_string("localization_target");
|
language_pack_ = G()->get_option_string("localization_target");
|
||||||
@ -209,10 +209,6 @@ void LanguagePackManager::start_up() {
|
|||||||
database_ = add_language_database(G()->get_option_string("language_pack_database_path"));
|
database_ = add_language_database(G()->get_option_string("language_pack_database_path"));
|
||||||
if (!language_pack_.empty() && !language_code_.empty()) {
|
if (!language_pack_.empty() && !language_code_.empty()) {
|
||||||
auto language = add_language(database_, language_pack_, language_code_);
|
auto language = add_language(database_, language_pack_, language_code_);
|
||||||
if (language->version_ == -1) {
|
|
||||||
load_empty_language_pack(language_code_);
|
|
||||||
}
|
|
||||||
repair_chosen_language_info();
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> language_lock(language->mutex_);
|
std::lock_guard<std::mutex> language_lock(language->mutex_);
|
||||||
base_language_code_ = language->base_language_code_;
|
base_language_code_ = language->base_language_code_;
|
||||||
@ -221,10 +217,7 @@ void LanguagePackManager::start_up() {
|
|||||||
base_language_code_.clear();
|
base_language_code_.clear();
|
||||||
}
|
}
|
||||||
if (!base_language_code_.empty()) {
|
if (!base_language_code_.empty()) {
|
||||||
auto base_language = add_language(database_, language_pack_, base_language_code_);
|
add_language(database_, language_pack_, base_language_code_);
|
||||||
if (base_language->version_ == -1) {
|
|
||||||
load_empty_language_pack(base_language_code_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Use localization target \"" << language_pack_ << "\" with language pack \"" << language_code_
|
LOG(INFO) << "Use localization target \"" << language_pack_ << "\" with language pack \"" << language_code_
|
||||||
@ -233,6 +226,27 @@ void LanguagePackManager::start_up() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LanguagePackManager::start_up() {
|
||||||
|
if (language_pack_.empty() || language_code_.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto language = get_language(database_, language_pack_, language_code_);
|
||||||
|
CHECK(language != nullptr);
|
||||||
|
if (language->version_ == -1) {
|
||||||
|
load_empty_language_pack(language_code_);
|
||||||
|
}
|
||||||
|
repair_chosen_language_info();
|
||||||
|
|
||||||
|
if (!base_language_code_.empty()) {
|
||||||
|
auto base_language = get_language(database_, language_pack_, base_language_code_);
|
||||||
|
CHECK(base_language != nullptr);
|
||||||
|
if (base_language->version_ == -1) {
|
||||||
|
load_empty_language_pack(base_language_code_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LanguagePackManager::tear_down() {
|
void LanguagePackManager::tear_down() {
|
||||||
if (ExitGuard::is_exited()) {
|
if (ExitGuard::is_exited()) {
|
||||||
return;
|
return;
|
||||||
@ -240,7 +254,7 @@ void LanguagePackManager::tear_down() {
|
|||||||
std::lock_guard<std::mutex> lock(language_database_mutex_);
|
std::lock_guard<std::mutex> lock(language_database_mutex_);
|
||||||
manager_count_--;
|
manager_count_--;
|
||||||
if (manager_count_ == 0) {
|
if (manager_count_ == 0) {
|
||||||
// can't clear language packs, because they may be accessed later using synchronous requests
|
// can't clear language packs, because they can be accessed later using synchronous requests
|
||||||
// LOG(INFO) << "Clear language packs";
|
// LOG(INFO) << "Clear language packs";
|
||||||
// language_databases_.clear();
|
// language_databases_.clear();
|
||||||
}
|
}
|
||||||
@ -364,9 +378,10 @@ void LanguagePackManager::on_language_pack_version_changed(bool is_base, int32 n
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << (is_base ? "Base" : "Main") << " language pack vesrion has changed to " << new_version;
|
|
||||||
Language *language = get_language(database_, language_pack_, language_code_);
|
Language *language = get_language(database_, language_pack_, language_code_);
|
||||||
int32 version = language == nullptr ? static_cast<int32>(-1) : language->version_.load();
|
int32 version = language == nullptr ? static_cast<int32>(-1) : language->version_.load();
|
||||||
|
LOG(INFO) << (is_base ? "Base" : "Main") << " language pack vesrion has changed from " << version << " to "
|
||||||
|
<< new_version;
|
||||||
if (version == -1) {
|
if (version == -1) {
|
||||||
return load_empty_language_pack(language_code_);
|
return load_empty_language_pack(language_code_);
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,7 @@ class SqliteKeyValue;
|
|||||||
|
|
||||||
class LanguagePackManager final : public NetQueryCallback {
|
class LanguagePackManager final : public NetQueryCallback {
|
||||||
public:
|
public:
|
||||||
explicit LanguagePackManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
explicit LanguagePackManager(ActorShared<> parent);
|
||||||
}
|
|
||||||
LanguagePackManager(const LanguagePackManager &) = delete;
|
LanguagePackManager(const LanguagePackManager &) = delete;
|
||||||
LanguagePackManager &operator=(const LanguagePackManager &) = delete;
|
LanguagePackManager &operator=(const LanguagePackManager &) = delete;
|
||||||
LanguagePackManager(LanguagePackManager &&) = delete;
|
LanguagePackManager(LanguagePackManager &&) = delete;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user