• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef OHOS_GLOBAL_I18N_LOCALE_CONFIG_H
16 #define OHOS_GLOBAL_I18N_LOCALE_CONFIG_H
17 
18 #include <map>
19 #include <vector>
20 #include <set>
21 #include <string>
22 #include <unordered_map>
23 #include <unordered_set>
24 
25 namespace OHOS {
26 namespace Global {
27 namespace I18n {
28 class LocaleConfig {
29 public:
30     LocaleConfig() = default;
31     virtual ~LocaleConfig() = default;
32     static bool SetSystemLanguage(const std::string &language);
33     static bool SetSystemRegion(const std::string &region);
34     static bool SetSystemLocale(const std::string &locale);
35     static std::string GetSystemLanguage();
36     static std::string GetSystemRegion();
37     static std::string GetSystemLocale();
38     static void GetSystemLanguages(std::vector<std::string> &ret);
39     static void GetSystemCountries(std::vector<std::string> &ret);
40     static bool IsSuggested(const std::string &language);
41     static bool IsSuggested(const std::string &language, const std::string &region);
42     static std::string GetDisplayLanguage(const std::string &language, const std::string &displayLocale,
43         bool sentenceCase);
44     static std::string GetDisplayRegion(const std::string &region, const std::string &displayLocale,
45         bool sentenceCase);
46     static bool IsRTL(const std::string &locale);
47     static std::string GetValidLocale(const std::string &localeTag);
48     static bool Is24HourClock();
49     static bool Set24HourClock(bool option);
50     static bool CheckPermission();
51     static bool SetUsingLocalDigit(bool flag);
52     static bool GetUsingLocalDigit();
53 
54 private:
55     static bool IsValidLanguage(const std::string &language);
56     static bool IsValidScript(const std::string &script);
57     static bool IsValidRegion(const std::string &region);
58     static bool IsValidTag(const std::string &tag);
59     static void Split(const std::string &src, const std::string &sep, std::vector<std::string> &dest);
60     static constexpr uint32_t LANGUAGE_LEN = 2;
61     static constexpr uint32_t LOCALE_ITEM_COUNT = 3;
62     static constexpr uint32_t SCRIPT_OFFSET = 2;
63     static const char *LANGUAGE_KEY;
64     static const char *LOCALE_KEY;
65     static const char *HOUR_KEY;
66     static const char *DEFAULT_LOCALE_KEY;
67     static const char *DEFAULT_LANGUAGE_KEY;
68     static const char *DEFAULT_REGION_KEY;
69     static const char *SIM_COUNTRY_CODE_KEY;
70     static const char *SUPPORTED_LOCALES_PATH;
71     static const char *SUPPORTED_REGIONS_PATH;
72     static constexpr int CONFIG_LEN = 128;
73     static const char *SUPPORTED_LOCALES_NAME;
74     static const char *SUPPORTED_REGIONS_NAME;
75     static const char *WHITE_LANGUAGES_NAME;
76     static const char *WHITE_LANGUAGES_PATH;
77     static const char *FORBIDDEN_REGIONS_PATH;
78     static const char *FORBIDDEN_REGIONS_NAME;
79     static const char *FORBIDDEN_LANGUAGES_PATH;
80     static const char *FORBIDDEN_LANGUAGES_NAME;
81     static const char *SUPPORT_LOCALES_PATH;
82     static const char *DEFAULT_LOCALE;
83     static const char *supportLocalesTag;
84     static const char *LANG_PATH;
85     static const char *rootTag;
86     static const char *secondRootTag;
87     static const uint32_t ELEMENT_NUM = 2;
88 
89     static const std::unordered_set<std::string>& GetSupportedLocales();
90     static const std::unordered_set<std::string>& GetForbiddenRegions();
91     static const std::unordered_set<std::string>& GetSupportedRegions();
92     static void GetCountriesFromSim(std::vector<std::string> &simCountries);
93     static void GetRelatedLocales(std::unordered_set<std::string> &relatedLocales,
94         const std::vector<std::string> countries);
95     static std::string GetRegionChangeLocale(const std::string &languageTag, const std::string &region);
96     static void GetListFromFile(const char *path, const char *resourceName, std::unordered_set<std::string> &ret);
97     static void Expunge(std::unordered_set<std::string> &src, const std::unordered_set<std::string> &another);
98     static std::string GetMainLanguage(const std::string &language);
99     static std::string GetDsiplayLanguageWithDialect(const std::string &language, const std::string &displayLocale);
100     static std::string ComputeLocale(const std::string &displayLocale);
101     static void ReadLangData(const char *xmlPath);
102     static std::unordered_set<std::string> supportedLocales;
103     static std::unordered_set<std::string> supportedRegions;
104     static std::unordered_set<std::string> whiteLanguages;
105     static std::map<std::string, std::string> supportedDialectLocales;
106     static std::unordered_map<std::string, std::string> dialectMap;
107     static std::unordered_map<std::string, std::string> localDigitMap;
108     static std::map<std::string, std::string> locale2DisplayName;
109     static std::string currentDialectLocale;
110     static std::set<std::string> validCaTag;
111     static std::set<std::string> validCoTag;
112     static std::set<std::string> validKnTag;
113     static std::set<std::string> validKfTag;
114     static std::set<std::string> validNuTag;
115     static std::set<std::string> validHcTag;
116     static std::set<std::string> dialectLang;
117     static bool listsInitialized;
118     static bool InitializeLists();
119 };
120 } // namespace I18n
121 } // namespace Global
122 } // namespace OHOS
123 #endif
124