• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <json/json.h>
24 #include "nocopyable.h"
25 
26 namespace OHOS {
27 namespace PowerMgr {
28 class NotificationLocale : public NoCopyable {
29 public:
30     static NotificationLocale& GetInstance();
31 
32     void ParseLocaleCfg();
33 
34     void UpdateStringMap();
35 
36     std::string GetStringByKey(const std::string& key);
37 private:
38     bool ParseJsonfile(const std::string& targetPath, std::unordered_map<std::string, std::string>& container);
39     std::unordered_map<std::string, std::string> languageMap_;
40     std::unordered_map<std::string, std::string> stringMap_;
41     std::string localeBaseName_;
42     bool islanguageMapInit_ { false };
43     static std::mutex mutex_;
44     static std::shared_ptr<NotificationLocale> instance_;
45 };
46 }   // namespace PowerMgr
47 }   // namespace OHOS
48 
49 #endif // BATTERY_NOTIFICATION_LOCALE_H