• 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 #ifndef OHOS_GLOBAL_I18N_TABOO_H
17 #define OHOS_GLOBAL_I18N_TABOO_H
18 
19 #include <map>
20 #include <set>
21 #include <string>
22 #include <vector>
23 
24 namespace OHOS {
25 namespace Global {
26 namespace I18n {
27 enum DataFileType {
28     CONFIG_FILE,
29     DATA_FILE
30 };
31 
32 class Taboo {
33 public:
34     Taboo();
35     Taboo(const std::string& path);
36     ~Taboo();
37     std::string ReplaceCountryName(const std::string& region, const std::string& displayLanguage,
38         const std::string& name);
39     std::string ReplaceLanguageName(const std::string& language, const std::string& displayLanguage,
40         const std::string& name);
41 
42 private:
43     void ParseTabooData(const std::string& path, DataFileType fileType, const std::string& Locale = "");
44     void ProcessTabooConfigData(const std::string& name, const std::string& value);
45     void ProcessTabooLocaleData(const std::string& locale, const std::string& name, const std::string& value);
46     void SplitValue(const std::string& value, std::set<std::string>& collation);
47     std::vector<std::string> QueryKeyFallBack(const std::string& key);
48     std::tuple<std::string, std::string> LanguageFallBack(const std::string& language);
49     void ReadResourceList();
50     std::string GetLanguageFromFileName(const std::string& fileName);
51 
52     std::set<std::string> supportedRegions; // Indicates which regions support name replacement using taboo data.
53     std::set<std::string> supportedLanguages; // Indicates which languages support name replacement using taboo data.
54     // cache the name replacement taboo data of different locale.
55     std::map<std::string, std::map<std::string, std::string>> localeTabooData;
56     std::map<std::string, std::string> resources; // Indicates which locales are supported to find taboo data.
57 
58     std::string tabooDataPath = "";
59     std::string tabooConfigFileName = "taboo-config.xml";
60     std::string tabooLocaleDataFileName = "taboo-data.xml";
61     std::string filePathSplitor = "/";
62     std::string supportedRegionsTag = "regions"; // supported regions key in taboo-config.xml
63     std::string supportedLanguagesTag = "languages"; // supported languages key in taboo-config.xml
64     std::string regionKey = "region_"; // start part of region name replacement data key.
65     std::string languageKey = "language_"; // start part of language name replacement data key.
66     bool isTabooDataExist = false;
67 
68     static const char* ROOT_TAG;
69     static const char* ITEM_TAG;
70     static const char* NAME_TAG;
71     static const char* VALUE_TAG;
72     char tabooDataSplitor = ',';
73     static const int LANGUAGE_START_INDEX = 2; // language start index in locale string
74     static const size_t DIR_XML_LENGTH = 3; // resource directory xml's length
75 };
76 } // namespace I18n
77 } // namespace Global
78 } // namespace OHOS
79 #endif