1 /* 2 * Copyright (c) 2025 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 GLOBAL_I18N_DISPLAYNAMES_H 16 #define GLOBAL_I18N_DISPLAYNAMES_H 17 18 #include <memory> 19 #include <unordered_set> 20 #include "unicode/locdspnm.h" 21 #include "unicode/locid.h" 22 #include "unicode/dtptngen.h" 23 #include "unicode/udisplaycontext.h" 24 #include "i18n_types.h" 25 #include "locale_info.h" 26 27 namespace OHOS { 28 namespace Global { 29 namespace I18n { 30 class DisplayNames { 31 public: 32 static std::vector<std::string> SupportedLocalesOf(const std::vector<std::string> &requestLocales, 33 const std::map<std::string, std::string> &configs, 34 I18nErrorCode &status); 35 36 DisplayNames(const std::vector<std::string> &localeTags, const std::map<std::string, std::string> &options); 37 std::string Display(const std::string &code); 38 std::map<std::string, std::string> ResolvedOptions(); 39 I18nErrorCode GetError() const; 40 std::string GetErrorMessage() const; 41 42 private: 43 static std::set<std::string> LookupSupportedLocales(const std::vector<std::string> &availableLocales, 44 const std::vector<std::string> &requestLocales); 45 46 void ParseAllOptions(const std::map<std::string, std::string> &options); 47 void InitDisplayNames(const std::string &curLocale, const std::map<std::string, std::string> &options); 48 std::string DisplayLanguage(const std::string &code); 49 std::string DisplayRegion(const std::string &code); 50 std::string DisplayScript(const std::string &code); 51 std::string DisplayCurrency(const std::string &code); 52 std::string DisplayCalendar(const std::string &code); 53 std::string DisplayDatetimefield(const std::string &code); 54 55 static const int32_t MIN_CALENDAR_LENGTH; 56 static const int32_t MAX_CALENDAR_LENGTH; 57 static const int32_t CURRENCY_LENGTH; 58 static const std::unordered_map<std::string, UDisplayContext> ICU_STYLE_OPTIONS; 59 static const std::unordered_map<std::string, UDisplayContext> ICU_LANGUAGE_DISPLAY_OPTIONS; 60 static const std::unordered_map<std::string, UDateTimePatternField> ICU_DATE_PATTERN_FIELD; 61 static const std::unordered_map<std::string, UDateTimePGDisplayWidth> ICU_DATE_DISPLAY_WIDTH; 62 63 std::unique_ptr<icu::LocaleDisplayNames> icuLocaldisplaynames; 64 std::string localeStr; 65 std::string localeMatcher; 66 std::string style; 67 std::string fallback; 68 std::string type; 69 std::string languageDisplay; 70 icu::Locale locale; 71 std::unique_ptr<LocaleInfo> localeInfo = nullptr; 72 std::unique_ptr<icu::LocaleDisplayNames> icuDisplaynames = nullptr; 73 I18nErrorCode status = I18nErrorCode::SUCCESS; 74 std::string errorMessage = ""; 75 bool createSuccess = false; 76 }; 77 } // namespace I18n 78 } // namespace Global 79 } // namespace OHOS 80 #endif