1 // Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include "system_locale.hh"
9 constexpr const char DEFAULT_LOCALE[] = "No Locale";
13 namespace pkgmgr_common {
15 SystemLocale& SystemLocale::GetInst(bool is_online) {
16 static SystemLocale inst(is_online);
21 SystemLocale::SystemLocale(bool is_online) : is_online_(is_online) {
23 vconf_notify_key_changed(VCONFKEY_LANGSET, LanChangedCb, this);
25 char* lang = vconf_get_str(VCONFKEY_LANGSET);
26 lang_ = lang ? std::string(lang) : "";
31 SystemLocale::~SystemLocale() {
33 vconf_ignore_key_changed(VCONFKEY_LANGSET, LanChangedCb);
36 void SystemLocale::RegisterEvent(IEvent* listener) {
40 void SystemLocale::UnRegisterEvent() {
44 const std::string& SystemLocale::Get() const {
48 void SystemLocale::SetLocale() {
49 std::string code = lang_.substr(0, lang_.find_first_of(".@"));
51 locale_ = DEFAULT_LOCALE;
55 size_t it = code.find('_');
56 if (it == std::string::npos) {
57 locale_ = std::move(code);
60 locale_ = std::move(code);
62 for (size_t i = it + 1; i < locale_.size(); ++i)
63 locale_[i] = tolower(locale_[i]);
67 listener_->OnChanged(locale_);
70 void SystemLocale::LanChangedCb(keynode_t* node, void* user_data) {
71 char* val = vconf_keynode_get_str(node);
76 SystemLocale* sl = reinterpret_cast<SystemLocale*>(user_data);
81 } // namespace pkgmgr_common