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_SYSTEM_LOCALE_MANAGER_H 17 #define OHOS_GLOBAL_SYSTEM_LOCALE_MANAGER_H 18 19 #include <string> 20 #include <vector> 21 #include "collator.h" 22 #include "taboo_utils.h" 23 24 namespace OHOS { 25 namespace Global { 26 namespace I18n { 27 enum SuggestionType { 28 // language or region is not suggested with system region or system language. 29 SUGGESTION_TYPE_NONE = 0, 30 31 // language is suggested with system region or region is suggested with system language. 32 SUGGESTION_TYPE_RELATED = 1, 33 34 // language is suggested with sim card region. 35 SUGGESTION_TYPE_SIM = 2, 36 }; 37 38 struct LocaleItem { 39 // language or region code. 40 std::string id; 41 42 // the suggestion type of language or region. 43 SuggestionType suggestionType; 44 45 // the name of language or region in specified language. 46 std::string displayName; 47 48 // the name of language or region in local language. 49 std::string localName; 50 }; 51 52 struct SortOptions { 53 // locale use to sort language or region. 54 std::string localeTag; 55 56 // whether to use local name to sort language or region. 57 bool isUseLocalName; 58 59 // whether to put the suggested item at the top 60 bool isSuggestedFirst; 61 }; 62 63 struct TimeZoneCityItem { 64 // time zone code 65 std::string zoneId; 66 67 //city code 68 std::string cityId; 69 70 //the display name of city 71 std::string cityDisplayName; 72 73 //the timezone offset for the city 74 int32_t offset; 75 76 //the display name of the timezone of the city 77 std::string zoneDisplayName; 78 79 //the timezone raw offset for the city 80 int32_t rawOffset; 81 }; 82 83 class SystemLocaleManager { 84 public: 85 SystemLocaleManager(); 86 ~SystemLocaleManager(); 87 88 /** 89 * @brief sort input languages according to SortOptions and obtain sorted result. 90 * 91 * @param languages input language array to be sorted. 92 * @param options sort options. 93 * @return std::vector<LocaleItem> sort result. 94 */ 95 std::vector<LocaleItem> GetLanguageInfoArray(const std::vector<std::string> &languages, 96 const SortOptions &options); 97 98 /** 99 * @brief sort input countries according to SortOptions and obtain sorted result. 100 * 101 * @param regions input country array to be sorted. 102 * @param options sort options. 103 * @return std::vector<LocaleItem> sort result. 104 */ 105 std::vector<LocaleItem> GetCountryInfoArray(const std::vector<std::string> &countries, const SortOptions &options); 106 107 /** 108 * @brief obtains sorted time zone city array. 109 * 110 * @return std::vector<TimeZoneCityItem> sort result. 111 */ 112 static std::vector<TimeZoneCityItem> GetTimezoneCityInfoArray(); 113 114 private: 115 void SortLocaleItemList(std::vector<LocaleItem> &localeItemList, const SortOptions &options); 116 static void SortTimezoneCityItemList(const std::string &locale, 117 std::vector<TimeZoneCityItem> &timezoneCityItemList); 118 std::unique_ptr<TabooUtils> tabooUtils; 119 static const char* SIM_COUNTRY_CODE_KEY; 120 static constexpr int CONFIG_LEN = 128; 121 }; 122 } // namespace I18n 123 } // namespace Global 124 } // namespace OHOS 125 #endif