• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_I18N_I18N_SERVICE_ABILITY_CLIENT_H
17 #define OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_CLIENT_H
18 
19 #include <string>
20 #include "i18n_types.h"
21 
22 namespace OHOS {
23 template <typename T>
24 class sptr;
25 
26 namespace Global {
27 namespace I18n {
28 class II18nServiceAbility;
29 
30 /**
31  * @brief I18nServiceAbilityClient is i18n service entry class, provides i18n service entry function,
32  * such as SetSystemLanguage.
33  */
34 class I18nServiceAbilityClient {
35 public:
36     /**
37      * @brief I18n service entry for setting system language.
38      *
39      * @param language language tag to set.
40      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
41      */
42     static I18nErrorCode SetSystemLanguage(const std::string &language);
43 
44     /**
45      * @brief I18n service entry for setting system region.
46      *
47      * @param region region tag to set.
48      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
49      */
50     static I18nErrorCode SetSystemRegion(const std::string &region);
51 
52     /**
53      * @brief I18n service entry for setting system locale.
54      *
55      * @param locale locale tag to set.
56      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
57      */
58     static I18nErrorCode SetSystemLocale(const std::string &locale);
59 
60     /**
61      * @brief I18n service entry for setting the system to use 12 or 24-hour clock.
62      *
63      * @param flag When flag is true, the system adopts 24-hour clock;
64      * When flag is false, the system adopts 12-hour clock; When flag is empty string, the system adopts
65      * system locale default behavior.
66      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
67      */
68     static I18nErrorCode Set24HourClock(const std::string &flag);
69 
70     /**
71      * @brief I18n service entry for setting whether the system uses local numbers.
72      *
73      * @param flag When flag is True, the system adopts local digit;
74      * When flag is False, the system doesn't adopt local digit;
75      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
76      */
77     static I18nErrorCode SetUsingLocalDigit(bool flag);
78 
79     /**
80      * @brief I18n service entry for add system preferred language.
81      *
82      * @param language preferred language tag to add.
83      * @param index preferred language'index to add.
84      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
85      */
86     static I18nErrorCode AddPreferredLanguage(const std::string &language, int32_t index);
87 
88     /**
89      * @brief I18n service entry for remove system preferred language.
90      *
91      * @param index preferred language's index to remove.
92      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
93      */
94     static I18nErrorCode RemovePreferredLanguage(int32_t index);
95 
96     /**
97      * @brief Set user's preferrence for temperature type.
98      *
99      * @param type temperature type to set.
100      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
101      */
102     static I18nErrorCode SetTemperatureType(TemperatureType type);
103 
104     /**
105      * @brief Set user's preferrence for first day of week.
106      *
107      * @param type one of week days.
108      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
109      */
110     static I18nErrorCode SetFirstDayOfWeek(WeekDay type);
111 
112     /**
113      * @brief Gets collations supported by system locale.
114      *
115      * @param systemCollations The map will containing the collation's identifier and name.
116      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
117      */
118     static I18nErrorCode GetSystemCollations(std::unordered_map<std::string, std::string>& systemCollations);
119 
120     /**
121      * @brief Gets collation currently used by system locale.
122      *
123      * @param usingCollation The identifier of the collation model used by system locale will be return.
124      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
125      */
126     static I18nErrorCode GetUsingCollation(std::string& usingCollation);
127 
128     /**
129      * @brief Sets the system collation mode.
130      *
131      * @param identifier Identifier of the collation mode.
132      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
133      */
134     static I18nErrorCode SetSystemCollation(const std::string& identifier);
135 
136     /**
137      * @brief Gets numbering systems supported by system locale.
138      *
139      * @param systemNumberingSystems a map will containing the numbering system's identifier and sample.
140      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
141      */
142     static I18nErrorCode GetSystemNumberingSystems(
143         std::unordered_map<std::string, std::string>& systemNumberingSystems);
144 
145     /**
146      * @brief Gets numbering system currently used by system locale.
147      *
148      * @param usingNumberingSystem the numbering systems's identifier
149      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
150      */
151     static I18nErrorCode GetUsingNumberingSystem(std::string& usingNumberingSystem);
152 
153     /**
154      * @brief Sets the numbering system used by the system locale.
155      *
156      * @param identifier Identifier of the numbering system.
157      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
158      */
159     static I18nErrorCode SetSystemNumberingSystem(const std::string& identifier);
160 
161     /**
162      * @brief Gets commonly used number patterns for system locale.
163      *
164      * @param systemNumberPatterns a map containing the used number patterns and example of system locale.
165      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
166      */
167     static I18nErrorCode GetSystemNumberPatterns(std::unordered_map<std::string, std::string>& systemNumberPatterns);
168 
169     /**
170      * @brief Gets number pattern used by system locale.
171      *
172      * @param usingNumberPattern The number pattern identifier used by system locale.
173      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
174      */
175     static I18nErrorCode GetUsingNumberPattern(std::string& usingNumberPattern);
176 
177     /**
178      * @brief Sets the number pattern used by the system locale.
179      *
180      * @param pattern Identifier of the number pattern.
181      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
182      */
183     static I18nErrorCode SetSystemNumberPattern(const std::string& pattern);
184 
185     /**
186      * @brief Gets measurements supported by system locale.
187      *
188      * @param systemMeasurements a map will containing identifier and name of measurements supported by system locale.
189      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
190      */
191     static I18nErrorCode GetSystemMeasurements(std::unordered_map<std::string, std::string>& systemMeasurements);
192 
193     /**
194      * @brief Gets measurement currently used by system locale.
195      *
196      * @param usingMeasurement The identifier of measurement system using by system locale.
197      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
198      */
199     static I18nErrorCode GetUsingMeasurement(std::string& identifier);
200 
201     /**
202      * @brief Sets the measurement system used by the system locale.
203      *
204      * @param identifier Identifier of the measurement system.
205      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
206      */
207     static I18nErrorCode SetSystemMeasurement(const std::string& identifier);
208 
209     /**
210      * @brief Gets numerical date patterns and examples supported by system locale.
211      *
212      * @param numericalDatePatterns a map containing the date patterns and examples.
213      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
214      */
215     static I18nErrorCode GetSystemNumericalDatePatterns(
216         std::unordered_map<std::string, std::string>& numericalDatePatterns);
217 
218     /**
219      * @brief Gets numerical date pattern currently used by system locale.
220      *
221      * @param identifier Identifier of numerical date pattern used by system locale
222      * @return I18nErrorCode Return SUCCESS indicates that the getting was successful.
223      */
224     static I18nErrorCode GetUsingNumericalDatePattern(std::string& identifier);
225 
226     /**
227      * @brief Sets the numerical date pattern used by the system locale.
228      *
229      * @param identifier Identifier of the numerical date pattern.
230      * @return I18nErrorCode Return SUCCESS indicates that the setting was successful.
231      */
232     static I18nErrorCode SetSystemNumericalDatePattern(const std::string& identifier);
233 
234     static std::string GetLanguageFromUserId(int32_t userId);
235 
236 private:
237     /**
238      * @brief Get the proxy of i18n service to access service.
239      *
240      * @param err Indicates whether the acquisition was successful.
241      * @return sptr<II18nServiceAbility> I18n service proxy.
242      */
243     static sptr<II18nServiceAbility> GetProxy(I18nErrorCode &err);
244 };
245 } // namespace I18n
246 } // namespace Global
247 } // namespace OHOS
248 #endif // OHOS_GLOBAL_I18N_I18N_SERVICE_ABILITY_CLIENT_H