• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "i18n_hilog.h"
17 #include "taboo_utils.h"
18 
19 namespace OHOS {
20 namespace Global {
21 namespace I18n {
22 std::string TabooUtils::SYSTEM_TABOO_DATA_PATH = "/system/etc/taboo_res/";
23 
GetInstance()24 TabooUtils* TabooUtils::GetInstance()
25 {
26     static TabooUtils tabooUtils;
27     return &tabooUtils;
28 }
29 
TabooUtils()30 TabooUtils::TabooUtils()
31 {
32     systemTaboo = std::make_shared<Taboo>(SYSTEM_TABOO_DATA_PATH);
33 }
34 
ReplaceCountryName(const std::string & region,const std::string & displayLanguage,const std::string & name)35 std::string TabooUtils::ReplaceCountryName(const std::string& region, const std::string& displayLanguage,
36     const std::string& name)
37 {
38     if (systemTaboo == nullptr) {
39         HILOG_ERROR_I18N("TabooUtils::ReplaceCountryName: systemTaboo is nullptr.");
40         return name;
41     }
42     return systemTaboo->ReplaceCountryName(region, displayLanguage, name);
43 }
44 
ReplaceLanguageName(const std::string & language,const std::string & displayLanguage,const std::string & name)45 std::string TabooUtils::ReplaceLanguageName(const std::string& language, const std::string& displayLanguage,
46     const std::string& name)
47 {
48     if (systemTaboo == nullptr) {
49         HILOG_ERROR_I18N("TabooUtils::ReplaceLanguageName: systemTaboo is nullptr.");
50         return name;
51     }
52     return systemTaboo->ReplaceLanguageName(language, displayLanguage, name);
53 }
54 
ReplaceTimeZoneName(const std::string & tzId,const std::string & displayLanguage,const std::string & name)55 std::string TabooUtils::ReplaceTimeZoneName(const std::string& tzId, const std::string& displayLanguage,
56     const std::string& name)
57 {
58     if (systemTaboo == nullptr) {
59         HILOG_ERROR_I18N("TabooUtils::ReplaceTimeZoneName: systemTaboo is nullptr.");
60         return name;
61     }
62     return systemTaboo->ReplaceTimeZoneName(tzId, displayLanguage, name);
63 }
64 
ReplaceCityName(const std::string & cityId,const std::string & displayLanguage,const std::string & name)65 std::string TabooUtils::ReplaceCityName(const std::string& cityId, const std::string& displayLanguage,
66     const std::string& name)
67 {
68     if (systemTaboo == nullptr) {
69         HILOG_ERROR_I18N("TabooUtils::ReplaceCityName: systemTaboo is nullptr.");
70         return name;
71     }
72     return systemTaboo->ReplaceCityName(cityId, displayLanguage, name);
73 }
74 
ReplacePhoneLocationName(const std::string & phoneNumber,const std::string & displayLanguage,const std::string & name)75 std::string TabooUtils::ReplacePhoneLocationName(const std::string& phoneNumber, const std::string& displayLanguage,
76     const std::string& name)
77 {
78     if (systemTaboo == nullptr) {
79         HILOG_ERROR_I18N("TabooUtils::ReplacePhoneLocationName: systemTaboo is nullptr.");
80         return name;
81     }
82     return systemTaboo->ReplacePhoneLocationName(phoneNumber, displayLanguage, name);
83 }
84 
GetBlockedLanguages() const85 std::unordered_set<std::string> TabooUtils::GetBlockedLanguages() const
86 {
87     if (systemTaboo == nullptr) {
88         HILOG_ERROR_I18N("TabooUtils::GetBlockedLanguages: systemTaboo is nullptr.");
89         return {};
90     }
91     return systemTaboo->GetBlockedLanguages();
92 }
93 
GetBlockedRegions(const std::string & language) const94 std::unordered_set<std::string> TabooUtils::GetBlockedRegions(const std::string& language) const
95 {
96     if (systemTaboo == nullptr) {
97         HILOG_ERROR_I18N("TabooUtils::GetBlockedRegions: systemTaboo is nullptr.");
98         return {};
99     }
100     return systemTaboo->GetBlockedRegions(language);
101 }
102 
GetBlockedCities() const103 std::unordered_set<std::string> TabooUtils::GetBlockedCities() const
104 {
105     if (systemTaboo == nullptr) {
106         HILOG_ERROR_I18N("TabooUtils::GetBlockedCities: systemTaboo is nullptr.");
107         return {};
108     }
109     return systemTaboo->GetBlockedCities();
110 }
111 
GetBlockedPhoneNumbers() const112 std::unordered_set<std::string> TabooUtils::GetBlockedPhoneNumbers() const
113 {
114     if (systemTaboo == nullptr) {
115         HILOG_ERROR_I18N("TabooUtils::GetBlockedPhoneNumbers: systemTaboo is nullptr.");
116         return {};
117     }
118     return systemTaboo->GetBlockedPhoneNumbers();
119 }
120 } // namespace I18n
121 } // namespace Global
122 } // namespace OHOS