• 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 
51 private:
52     static bool IsValidLanguage(const std::string &language);
53     static bool IsValidScript(const std::string &script);
54     static bool IsValidRegion(const std::string &region);
55     static bool IsValidTag(const std::string &tag);
56     static void Split(const std::string &src, const std::string &sep, std::vector<std::string> &dest);
57     static constexpr uint32_t LANGUAGE_LEN = 2;
58     static constexpr uint32_t LOCALE_ITEM_COUNT = 3;
59     static constexpr uint32_t SCRIPT_OFFSET = 2;
60     static const char *LANGUAGE_KEY;
61     static const char *LOCALE_KEY;
62     static const char *HOUR_KEY;
63     static const char *DEFAULT_LOCALE_KEY;
64     static const char *DEFAULT_LANGUAGE_KEY;
65     static const char *DEFAULT_REGION_KEY;
66     static const char *SUPPORTED_LOCALES_PATH;
67     static const char *SUPPORTED_REGIONS_PATH;
68     static constexpr int CONFIG_LEN = 128;
69     static const char *SUPPORTED_LOCALES_NAME;
70     static const char *SUPPORTED_REGIONS_NAME;
71     static const char *WHITE_LANGUAGES_NAME;
72     static const char *WHITE_LANGUAGES_PATH;
73     static const char *FORBIDDEN_REGIONS_PATH;
74     static const char *FORBIDDEN_REGIONS_NAME;
75     static const char *FORBIDDEN_LANGUAGES_PATH;
76     static const char *FORBIDDEN_LANGUAGES_NAME;
77     static const char *SUPPORT_LOCALES_PATH;
78     static const char *DEFAULT_LOCALE;
79     static const char *supportLocalesTag;
80     static const char *LANG_PATH;
81     static const char *rootTag;
82     static const char *secondRootTag;
83     static const uint32_t ELEMENT_NUM = 2;
84 
85     static const std::unordered_set<std::string>& GetSupportedLocales();
86     static const std::unordered_set<std::string>& GetForbiddenRegions();
87     static const std::unordered_set<std::string>& GetSupportedRegions();
88     static void GetCountriesFromSim(std::vector<std::string> &simCountries);
89     static void GetRelatedLocales(std::unordered_set<std::string> &relatedLocales,
90         const std::vector<std::string> countries);
91     static std::string GetRegionChangeLocale(const std::string &languageTag, const std::string &region);
92     static void GetListFromFile(const char *path, const char *resourceName, std::unordered_set<std::string> &ret);
93     static void Expunge(std::unordered_set<std::string> &src, const std::unordered_set<std::string> &another);
94     static std::string GetMainLanguage(const std::string &language);
95     static std::string GetDsiplayLanguageWithDialect(const std::string &language, const std::string &displayLocale);
96     static std::string ComputeLocale(const std::string &displayLocale);
97     static void ReadLangData(const char *xmlPath);
98     static std::unordered_set<std::string> supportedLocales;
99     static std::unordered_set<std::string> supportedRegions;
100     static std::unordered_set<std::string> whiteLanguages;
101     static std::map<std::string, std::string> supportedDialectLocales;
102     static std::unordered_map<std::string, std::string> dialectMap;
103     static std::map<std::string, std::string> locale2DisplayName;
104     static std::string currentDialectLocale;
105     static std::set<std::string> validCaTag;
106     static std::set<std::string> validCoTag;
107     static std::set<std::string> validKnTag;
108     static std::set<std::string> validKfTag;
109     static std::set<std::string> validNuTag;
110     static std::set<std::string> validHcTag;
111     static std::set<std::string> dialectLang;
112     static bool listsInitialized;
113     static bool InitializeLists();
114     static bool CheckPermission();
115 };
116 } // namespace I18n
117 } // namespace Global
118 } // namespace OHOS
119 #endif
120