• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_GLOBAL_I18N_INTL_LOCALE_H
16 #define OHOS_GLOBAL_I18N_INTL_LOCALE_H
17 
18 #include <unordered_map>
19 #include <string>
20 #include "unicode/locid.h"
21 #include "unicode/localebuilder.h"
22 
23 namespace OHOS {
24 namespace Global {
25 namespace I18n {
26 class IntlLocale {
27 public:
28     IntlLocale(const std::string &localeTag, const std::unordered_map<std::string, std::string>& configs,
29         std::string& errMessage);
30     virtual ~IntlLocale();
31 
32     std::string GetLanguage();
33     std::string GetBaseName();
34     std::string GetRegion();
35     std::string GetScript();
36     std::string GetCalendar();
37     std::string GetCollation();
38     std::string GetHourCycle();
39     std::string GetNumberingSystem();
40     std::string GetNumeric();
41     std::string GetCaseFirst();
42     std::string Maximize();
43     std::string Minimize();
44     std::string ToString(std::string& errMessage);
45 
46     static const std::string languageTag;
47     static const std::string baseNameTag;
48     static const std::string regionTag;
49     static const std::string scriptTag;
50     static const std::string calendarTag;
51     static const std::string collationTag;
52     static const std::string hourCycleTag;
53     static const std::string numberingSystemTag;
54     static const std::string numericTag;
55     static const std::string caseFirstTag;
56 
57 private:
58     bool CheckLocaleParam(const std::string& localeTag, const std::unordered_map<std::string, std::string>& configs);
59     bool SetLocaleParam(const std::string& localeTag, const std::unordered_map<std::string, std::string>& configs,
60         icu::LocaleBuilder* builder);
61     bool CheckConfigsExtParam(const std::unordered_map<std::string, std::string>& configs);
62     bool SetConfigsExtParam(const std::unordered_map<std::string, std::string>& configs, icu::LocaleBuilder* builder);
63     bool SetExtParam(const std::unordered_map<std::string, std::string>& configs, const std::string paramTag,
64         const std::string paramExtTag, icu::LocaleBuilder* builder);
65 
66     bool initSuccess = false;
67     icu::Locale icuLocale;
68 
69     static bool icuInitialized;
70     static bool Init();
71 };
72 } // namespace I18n
73 } // namespace Global
74 } // namespace OHOS
75 #endif