1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BATTERY_NOTIFICATION_LOCALE_H 17 #define BATTERY_NOTIFICATION_LOCALE_H 18 19 #include <fstream> 20 #include <unordered_map> 21 #include <mutex> 22 #include <string> 23 #include <unistd.h> 24 25 #include "nocopyable.h" 26 27 namespace OHOS { 28 namespace PowerMgr { 29 class NotificationLocale : public NoCopyable { 30 public: 31 static NotificationLocale& GetInstance(); 32 33 void ParseLocaleCfg(); 34 35 void UpdateStringMap(); 36 37 std::string GetStringByKey(const std::string& key); 38 private: 39 bool ParseJsonfile(const std::string& targetPath, std::unordered_map<std::string, std::string>& container); 40 bool SaveJsonToMap(const std::string& fileStr, const std::string& targetPath, 41 std::unordered_map<std::string, std::string>& container); 42 std::unordered_map<std::string, std::string> languageMap_; 43 std::unordered_map<std::string, std::string> stringMap_; 44 std::string localeBaseName_; 45 bool islanguageMapInit_ { false }; 46 static std::mutex mutex_; 47 static std::shared_ptr<NotificationLocale> instance_; 48 }; 49 } // namespace PowerMgr 50 } // namespace OHOS 51 52 #endif // BATTERY_NOTIFICATION_LOCALE_H