• 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 #include "intl_locale_addon.h"
16 
17 #include "error_util.h"
18 #include "i18n_hilog.h"
19 #include "js_utils.h"
20 
21 namespace OHOS {
22 namespace Global {
23 namespace I18n {
24 static thread_local napi_ref* g_IntlLocaleConstructor = nullptr;
25 const std::string NOT_STRING_OBJECT_ERROR_MESSAGE = "tag is not String or Object";
26 
IntlLocaleAddon()27 IntlLocaleAddon::IntlLocaleAddon()
28 {
29 }
30 
~IntlLocaleAddon()31 IntlLocaleAddon::~IntlLocaleAddon()
32 {
33 }
34 
Destructor(napi_env env,void * nativeObject,void * hint)35 void IntlLocaleAddon::Destructor(napi_env env, void *nativeObject, void *hint)
36 {
37     if (!nativeObject) {
38         return;
39     }
40     delete reinterpret_cast<IntlLocaleAddon*>(nativeObject);
41     nativeObject = nullptr;
42 }
43 
SetProperty(napi_env env,napi_callback_info info)44 napi_value IntlLocaleAddon::SetProperty(napi_env env, napi_callback_info info)
45 {
46     // do nothing but provided as an input parameter for DECLARE_NAPI_GETTER_SETTER;
47     napi_value result = nullptr;
48     napi_status status = napi_get_undefined(env, &result);
49     if (status != napi_ok) {
50         HILOG_ERROR_I18N("IntlLocaleAddon::SetProperty: Create undefined failed.");
51         return nullptr;
52     }
53     return result;
54 }
55 
InitIntlLocale(napi_env env,napi_value exports)56 napi_value IntlLocaleAddon::InitIntlLocale(napi_env env, napi_value exports)
57 {
58     napi_property_descriptor properties[] = {
59         DECLARE_NAPI_GETTER_SETTER("language", GetLanguage, SetProperty),
60         DECLARE_NAPI_GETTER_SETTER("baseName", GetBaseName, SetProperty),
61         DECLARE_NAPI_GETTER_SETTER("region", GetRegion, SetProperty),
62         DECLARE_NAPI_GETTER_SETTER("script", GetScript, SetProperty),
63         DECLARE_NAPI_GETTER_SETTER("calendar", GetCalendar, SetProperty),
64         DECLARE_NAPI_GETTER_SETTER("collation", GetCollation, SetProperty),
65         DECLARE_NAPI_GETTER_SETTER("hourCycle", GetHourCycle, SetProperty),
66         DECLARE_NAPI_GETTER_SETTER("numberingSystem", GetNumberingSystem, SetProperty),
67         DECLARE_NAPI_GETTER_SETTER("numeric", GetNumeric, SetProperty),
68         DECLARE_NAPI_GETTER_SETTER("caseFirst", GetCaseFirst, SetProperty),
69         DECLARE_NAPI_FUNCTION("toString", ToString),
70         DECLARE_NAPI_FUNCTION("minimize", Minimize),
71         DECLARE_NAPI_FUNCTION("maximize", Maximize),
72     };
73 
74     napi_value constructor = nullptr;
75     napi_status status = napi_define_class(env, "Locale", NAPI_AUTO_LENGTH, IntlLocaleConstructor, nullptr,
76         sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
77     if (status != napi_ok) {
78         HILOG_ERROR_I18N("IntlLocaleAddon::InitIntlLocale: Define class failed when InitIntlLocale.");
79         return nullptr;
80     }
81 
82     status = napi_set_named_property(env, exports, "Locale", constructor);
83     if (status != napi_ok) {
84         HILOG_ERROR_I18N("IntlLocaleAddon::InitIntlLocale: Set property failed when InitIntlLocale.");
85         return nullptr;
86     }
87 
88     g_IntlLocaleConstructor = new (std::nothrow) napi_ref;
89     if (!g_IntlLocaleConstructor) {
90         HILOG_ERROR_I18N("IntlLocaleAddon::InitIntlLocale: Failed to create Locale ref at init.");
91         return nullptr;
92     }
93 
94     status = napi_create_reference(env, constructor, 1, g_IntlLocaleConstructor);
95     if (status != napi_ok) {
96         HILOG_ERROR_I18N(
97             "IntlLocaleAddon::InitIntlLocale: Failed to create reference g_IntlLocaleConstructor at init.");
98         return nullptr;
99     }
100 
101     return exports;
102 }
103 
IntlLocaleConstructor(napi_env env,napi_callback_info info)104 napi_value IntlLocaleAddon::IntlLocaleConstructor(napi_env env, napi_callback_info info)
105 {
106     size_t argc = 2;
107     napi_value argv[2] = { nullptr };
108     napi_value thisVar = nullptr;
109     void *data = nullptr;
110     napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
111     if (status != napi_ok) {
112         HILOG_ERROR_I18N("IntlLocaleAddon::IntlLocaleConstructor: Get cb info failed.");
113         return nullptr;
114     } else if (argc < 1) {
115         ErrorUtil::NapiThrowUndefined(env, NOT_STRING_OBJECT_ERROR_MESSAGE);
116         return nullptr;
117     }
118 
119     napi_valuetype type = napi_valuetype::napi_undefined;
120     status = napi_typeof(env, argv[0], &type);
121     if (status != napi_ok) {
122         HILOG_ERROR_I18N("IntlLocaleAddon::IntlLocaleConstructor: Get argv[0] type failed.");
123         return nullptr;
124     } else if (type != napi_valuetype::napi_string && type != napi_valuetype::napi_object) {
125         ErrorUtil::NapiThrowUndefined(env, NOT_STRING_OBJECT_ERROR_MESSAGE);
126         return nullptr;
127     }
128 
129     std::string localeTag = IntlLocaleAddon::ParseLocaleTag(env, argv[0], type);
130 
131     std::unordered_map<std::string, std::string> configs = {};
132     if (argc > 1) {
133         IntlLocaleAddon::ParseConfigs(env, argv[1], configs);
134     }
135     IntlLocaleAddon* obj = new (std::nothrow) IntlLocaleAddon();
136     if (obj == nullptr) {
137         HILOG_ERROR_I18N("IntlLocaleAddon::IntlLocaleConstructor: Create IntlLocaleAddon failed.");
138         return nullptr;
139     }
140     status =
141         napi_wrap(env, thisVar, reinterpret_cast<void *>(obj), IntlLocaleAddon::Destructor, nullptr, nullptr);
142     if (status != napi_ok) {
143         HILOG_ERROR_I18N("IntlLocaleAddon::IntlLocaleConstructor: Wrap IntlLocaleAddon failed.");
144         delete obj;
145         return nullptr;
146     }
147     if (!obj->InitLocaleContext(env, localeTag, configs)) {
148         HILOG_ERROR_I18N("IntlLocaleAddon::IntlLocaleConstructor: Init locale context failed.");
149         return nullptr;
150     }
151     return thisVar;
152 }
153 
IsIntlLocale(napi_env env,napi_value argv)154 bool IntlLocaleAddon::IsIntlLocale(napi_env env, napi_value argv)
155 {
156     napi_value constructor = nullptr;
157     if (g_IntlLocaleConstructor == nullptr) {
158         HILOG_ERROR_I18N("IntlLocaleAddon::IsIntlLocale: g_IntlLocaleConstructor is nullptr.");
159         return false;
160     }
161 
162     napi_status status = napi_get_reference_value(env, *g_IntlLocaleConstructor, &constructor);
163     if (status != napi_ok || constructor == nullptr) {
164         HILOG_ERROR_I18N("IntlLocaleAddon::IsIntlLocale: Failed to create reference.");
165         return false;
166     }
167 
168     bool isIntlLocale = false;
169     status = napi_instanceof(env, argv, constructor, &isIntlLocale);
170     if (status != napi_ok) {
171         HILOG_ERROR_I18N("IntlLocaleAddon::IsIntlLocale: Failed to get instance of argv.");
172         return false;
173     }
174     return isIntlLocale;
175 }
176 
InitLocaleContext(napi_env env,const std::string localeTag,std::unordered_map<std::string,std::string> & configs)177 bool IntlLocaleAddon::InitLocaleContext(napi_env env, const std::string localeTag,
178     std::unordered_map<std::string, std::string>& configs)
179 {
180     std::string errMessage;
181     intlLocale = std::make_unique<IntlLocale>(localeTag, configs, errMessage);
182     if (!errMessage.empty()) {
183         ErrorUtil::NapiThrowUndefined(env, errMessage);
184         return false;
185     }
186     return intlLocale != nullptr;
187 }
188 
LocaleToString(napi_env env,napi_value argv)189 std::string IntlLocaleAddon::LocaleToString(napi_env env, napi_value argv)
190 {
191     napi_value funcToString = nullptr;
192     napi_status status = napi_get_named_property(env, argv, "toString", &funcToString);
193     if (status != napi_ok || funcToString == nullptr) {
194         HILOG_ERROR_I18N("IntlLocaleAddon::LocaleToString: Get named property failed.");
195         return "";
196     }
197 
198     napi_value value = nullptr;
199     status = napi_call_function(env, argv, funcToString, 0, nullptr, &value);
200     if (status != napi_ok || value == nullptr) {
201         HILOG_ERROR_I18N("IntlLocaleAddon::LocaleToString: Call toString failed.");
202         return "";
203     }
204 
205     int32_t code = 0;
206     std::string localeTag = JSUtils::GetString(env, value, code);
207     if (code != 0) {
208         HILOG_ERROR_I18N("IntlLocaleAddon::LocaleToString: Get string from value failed.");
209         return "";
210     }
211     return localeTag;
212 }
213 
GetLanguage(napi_env env,napi_callback_info info)214 napi_value IntlLocaleAddon::GetLanguage(napi_env env, napi_callback_info info)
215 {
216     return GetIntlLocaleAttribute(env, info, GetLanguageInner, napi_valuetype::napi_string);
217 }
218 
GetBaseName(napi_env env,napi_callback_info info)219 napi_value IntlLocaleAddon::GetBaseName(napi_env env, napi_callback_info info)
220 {
221     return GetIntlLocaleAttribute(env, info, GetBaseNameInner, napi_valuetype::napi_string);
222 }
223 
GetRegion(napi_env env,napi_callback_info info)224 napi_value IntlLocaleAddon::GetRegion(napi_env env, napi_callback_info info)
225 {
226     return GetIntlLocaleAttribute(env, info, GetRegionInner, napi_valuetype::napi_string);
227 }
228 
GetScript(napi_env env,napi_callback_info info)229 napi_value IntlLocaleAddon::GetScript(napi_env env, napi_callback_info info)
230 {
231     return GetIntlLocaleAttribute(env, info, GetScriptInner, napi_valuetype::napi_string);
232 }
233 
GetCalendar(napi_env env,napi_callback_info info)234 napi_value IntlLocaleAddon::GetCalendar(napi_env env, napi_callback_info info)
235 {
236     return GetIntlLocaleAttribute(env, info, GetCalendarInner, napi_valuetype::napi_string);
237 }
238 
GetCollation(napi_env env,napi_callback_info info)239 napi_value IntlLocaleAddon::GetCollation(napi_env env, napi_callback_info info)
240 {
241     return GetIntlLocaleAttribute(env, info, GetCollationInner, napi_valuetype::napi_string);
242 }
243 
GetHourCycle(napi_env env,napi_callback_info info)244 napi_value IntlLocaleAddon::GetHourCycle(napi_env env, napi_callback_info info)
245 {
246     return GetIntlLocaleAttribute(env, info, GetHourCycleInner, napi_valuetype::napi_string);
247 }
248 
GetNumberingSystem(napi_env env,napi_callback_info info)249 napi_value IntlLocaleAddon::GetNumberingSystem(napi_env env, napi_callback_info info)
250 {
251     return GetIntlLocaleAttribute(env, info, GetNumberingSystemInner, napi_valuetype::napi_string);
252 }
253 
GetNumeric(napi_env env,napi_callback_info info)254 napi_value IntlLocaleAddon::GetNumeric(napi_env env, napi_callback_info info)
255 {
256     return GetIntlLocaleAttribute(env, info, GetNumericInner, napi_valuetype::napi_boolean);
257 }
258 
GetCaseFirst(napi_env env,napi_callback_info info)259 napi_value IntlLocaleAddon::GetCaseFirst(napi_env env, napi_callback_info info)
260 {
261     return GetIntlLocaleAttribute(env, info, GetCaseFirstInner, napi_valuetype::napi_string);
262 }
263 
ToString(napi_env env,napi_callback_info info)264 napi_value IntlLocaleAddon::ToString(napi_env env, napi_callback_info info)
265 {
266     napi_value thisVar = nullptr;
267     void *data = nullptr;
268     napi_status status = napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data);
269     if (status != napi_ok) {
270         return nullptr;
271     }
272     IntlLocaleAddon *obj = nullptr;
273     status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
274     if (status != napi_ok || !obj || !obj->intlLocale) {
275         HILOG_ERROR_I18N("IntlLocaleAddon::ToString: Get IntlLocale object failed.");
276         return nullptr;
277     }
278     std::string errMessage;
279     std::string value = obj->intlLocale->ToString(errMessage);
280     if (!errMessage.empty()) {
281         ErrorUtil::NapiThrowUndefined(env, errMessage);
282         return nullptr;
283     }
284 
285     napi_value result = nullptr;
286     status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
287     if (status != napi_ok) {
288         HILOG_ERROR_I18N("IntlLocaleAddon::ToString: Create string failed.");
289         return nullptr;
290     }
291     return result;
292 }
293 
Minimize(napi_env env,napi_callback_info info)294 napi_value IntlLocaleAddon::Minimize(napi_env env, napi_callback_info info)
295 {
296     napi_value argv = GetIntlLocaleAttribute(env, info, MinimizeInner, napi_valuetype::napi_string);
297     return CreateIntlLocaleObject(env, argv);
298 }
299 
Maximize(napi_env env,napi_callback_info info)300 napi_value IntlLocaleAddon::Maximize(napi_env env, napi_callback_info info)
301 {
302     napi_value argv = GetIntlLocaleAttribute(env, info, MaximizeInner, napi_valuetype::napi_string);
303     return CreateIntlLocaleObject(env, argv);
304 }
305 
GetLanguageInner(std::shared_ptr<IntlLocale> intlLocale)306 std::string IntlLocaleAddon::GetLanguageInner(std::shared_ptr<IntlLocale> intlLocale)
307 {
308     if (intlLocale == nullptr) {
309         return "";
310     }
311     return intlLocale->GetLanguage();
312 }
313 
GetBaseNameInner(std::shared_ptr<IntlLocale> intlLocale)314 std::string IntlLocaleAddon::GetBaseNameInner(std::shared_ptr<IntlLocale> intlLocale)
315 {
316     if (intlLocale == nullptr) {
317         return "";
318     }
319     return intlLocale->GetBaseName();
320 }
321 
GetRegionInner(std::shared_ptr<IntlLocale> intlLocale)322 std::string IntlLocaleAddon::GetRegionInner(std::shared_ptr<IntlLocale> intlLocale)
323 {
324     if (intlLocale == nullptr) {
325         return "";
326     }
327     return intlLocale->GetRegion();
328 }
329 
GetScriptInner(std::shared_ptr<IntlLocale> intlLocale)330 std::string IntlLocaleAddon::GetScriptInner(std::shared_ptr<IntlLocale> intlLocale)
331 {
332     if (intlLocale == nullptr) {
333         return "";
334     }
335     return intlLocale->GetScript();
336 }
337 
GetCalendarInner(std::shared_ptr<IntlLocale> intlLocale)338 std::string IntlLocaleAddon::GetCalendarInner(std::shared_ptr<IntlLocale> intlLocale)
339 {
340     if (intlLocale == nullptr) {
341         return "";
342     }
343     return intlLocale->GetCalendar();
344 }
345 
GetCollationInner(std::shared_ptr<IntlLocale> intlLocale)346 std::string IntlLocaleAddon::GetCollationInner(std::shared_ptr<IntlLocale> intlLocale)
347 {
348     if (intlLocale == nullptr) {
349         return "";
350     }
351     return intlLocale->GetCollation();
352 }
353 
GetHourCycleInner(std::shared_ptr<IntlLocale> intlLocale)354 std::string IntlLocaleAddon::GetHourCycleInner(std::shared_ptr<IntlLocale> intlLocale)
355 {
356     if (intlLocale == nullptr) {
357         return "";
358     }
359     return intlLocale->GetHourCycle();
360 }
361 
GetNumberingSystemInner(std::shared_ptr<IntlLocale> intlLocale)362 std::string IntlLocaleAddon::GetNumberingSystemInner(std::shared_ptr<IntlLocale> intlLocale)
363 {
364     if (intlLocale == nullptr) {
365         return "";
366     }
367     return intlLocale->GetNumberingSystem();
368 }
369 
GetNumericInner(std::shared_ptr<IntlLocale> intlLocale)370 std::string IntlLocaleAddon::GetNumericInner(std::shared_ptr<IntlLocale> intlLocale)
371 {
372     if (intlLocale == nullptr) {
373         return "";
374     }
375     return intlLocale->GetNumeric();
376 }
377 
GetCaseFirstInner(std::shared_ptr<IntlLocale> intlLocale)378 std::string IntlLocaleAddon::GetCaseFirstInner(std::shared_ptr<IntlLocale> intlLocale)
379 {
380     if (intlLocale == nullptr) {
381         return "";
382     }
383     return intlLocale->GetCaseFirst();
384 }
385 
MaximizeInner(std::shared_ptr<IntlLocale> intlLocale)386 std::string IntlLocaleAddon::MaximizeInner(std::shared_ptr<IntlLocale> intlLocale)
387 {
388     if (intlLocale == nullptr) {
389         return "";
390     }
391     return intlLocale->Maximize();
392 }
393 
MinimizeInner(std::shared_ptr<IntlLocale> intlLocale)394 std::string IntlLocaleAddon::MinimizeInner(std::shared_ptr<IntlLocale> intlLocale)
395 {
396     if (intlLocale == nullptr) {
397         return "";
398     }
399     return intlLocale->Minimize();
400 }
401 
GetIntlLocaleAttribute(napi_env env,napi_callback_info info,GetIntlLocaleProperty func,napi_valuetype type)402 napi_value IntlLocaleAddon::GetIntlLocaleAttribute(napi_env env, napi_callback_info info,
403     GetIntlLocaleProperty func, napi_valuetype type)
404 {
405     napi_value thisVar = nullptr;
406     void *data = nullptr;
407     napi_status status = napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data);
408     if (status != napi_ok) {
409         return nullptr;
410     }
411     IntlLocaleAddon *obj = nullptr;
412     status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
413     if (status != napi_ok || !obj || !obj->intlLocale) {
414         HILOG_ERROR_I18N("IntlLocaleAddon::GetIntlLocaleAttribute: Get Locale object failed.");
415         return nullptr;
416     }
417     std::string value = func(obj->intlLocale);
418     if (value.empty()) {
419         return nullptr;
420     }
421     napi_value result = nullptr;
422     switch (type) {
423         case napi_valuetype::napi_boolean: {
424             bool boolValue = (value.compare("true") == 0);
425             status = napi_get_boolean(env, boolValue, &result);
426             if (status != napi_ok || result == nullptr) {
427                 HILOG_ERROR_I18N("IntlLocaleAddon::GetIntlLocaleAttribute: Create attribute boolean failed.");
428                 return nullptr;
429             }
430             break;
431         }
432         case napi_valuetype::napi_string: {
433             status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
434             if (status != napi_ok || result == nullptr) {
435                 HILOG_ERROR_I18N("IntlLocaleAddon::GetIntlLocaleAttribute: Create attribute string failed.");
436                 return JSUtils::CreateEmptyString(env);
437             }
438             break;
439         }
440         default:
441             return JSUtils::CreateEmptyString(env);
442     }
443     return result;
444 }
445 
CreateIntlLocaleObject(napi_env env,napi_value argv)446 napi_value IntlLocaleAddon::CreateIntlLocaleObject(napi_env env, napi_value argv)
447 {
448     if (argv == nullptr) {
449         HILOG_ERROR_I18N("IntlLocaleAddon::CreateIntlLocaleObject: argv is nullptr.");
450         return nullptr;
451     }
452     if (g_IntlLocaleConstructor == nullptr) {
453         HILOG_ERROR_I18N("IntlLocaleAddon::CreateIntlLocaleObject: g_IntlLocaleConstructor is nullptr.");
454         return nullptr;
455     }
456 
457     napi_value constructor = nullptr;
458     napi_status status = napi_get_reference_value(env, *g_IntlLocaleConstructor, &constructor);
459     if (status != napi_ok || constructor == nullptr) {
460         HILOG_ERROR_I18N("IntlLocaleAddon::CreateIntlLocaleObject: Failed to create reference.");
461         return nullptr;
462     }
463     napi_value result = nullptr;
464     status = napi_new_instance(env, constructor, 1, &argv, &result);
465     if (status != napi_ok) {
466         HILOG_ERROR_I18N("IntlLocaleAddon::CreateIntlLocaleObject: Create new IntlLocale instance failed.");
467         return nullptr;
468     }
469     return result;
470 }
471 
ParseLocaleTag(napi_env env,napi_value value,napi_valuetype type)472 std::string IntlLocaleAddon::ParseLocaleTag(napi_env env, napi_value value, napi_valuetype type)
473 {
474     std::string localeTag;
475     if (type == napi_valuetype::napi_object && IntlLocaleAddon::IsIntlLocale(env, value)) {
476         localeTag = IntlLocaleAddon::LocaleToString(env, value);
477     } else {
478         int32_t code = 0;
479         localeTag = JSUtils::GetString(env, value, code);
480         if (code != 0) {
481             HILOG_ERROR_I18N("IntlLocaleAddon::ParseLocaleTag: Get string from value failed.");
482             return "";
483         }
484     }
485     return localeTag;
486 }
487 
ParseConfigs(napi_env env,napi_value options,std::unordered_map<std::string,std::string> & configs)488 void IntlLocaleAddon::ParseConfigs(napi_env env, napi_value options,
489     std::unordered_map<std::string, std::string>& configs)
490 {
491     napi_valuetype type = napi_undefined;
492     napi_status status = napi_typeof(env, options, &type);
493     if (status != napi_ok) {
494         HILOG_ERROR_I18N("IntlLocaleAddon::ParseConfigs: Get options type failed.");
495         return;
496     }
497     if (type != napi_object) {
498         HILOG_ERROR_I18N("IntlLocaleAddon::ParseConfigs: options is not object.");
499         return;
500     }
501     std::string value;
502     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::languageTag, napi_string, value)) {
503         configs.insert({IntlLocale::languageTag, value});
504     }
505     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::baseNameTag, napi_string, value)) {
506         configs.insert({IntlLocale::baseNameTag, value});
507     }
508     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::regionTag, napi_string, value)) {
509         configs.insert({IntlLocale::regionTag, value});
510     }
511     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::scriptTag, napi_string, value)) {
512         configs.insert({IntlLocale::scriptTag, value});
513     }
514     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::calendarTag, napi_string, value)) {
515         configs.insert({IntlLocale::calendarTag, value});
516     }
517     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::collationTag, napi_string, value)) {
518         configs.insert({IntlLocale::collationTag, value});
519     }
520     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::hourCycleTag, napi_string, value)) {
521         configs.insert({IntlLocale::hourCycleTag, value});
522     }
523     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::numberingSystemTag, napi_string, value)) {
524         configs.insert({IntlLocale::numberingSystemTag, value});
525     }
526     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::numericTag, napi_boolean, value)) {
527         configs.insert({IntlLocale::numericTag, value});
528     }
529     if (JSUtils::GetPropertyFormObject(env, options, IntlLocale::caseFirstTag, napi_string, value)) {
530         configs.insert({IntlLocale::caseFirstTag, value});
531     }
532 }
533 
GetIntlLocale()534 std::shared_ptr<IntlLocale> IntlLocaleAddon::GetIntlLocale()
535 {
536     if (!this->intlLocale) {
537         return nullptr;
538     }
539     return this->intlLocale;
540 }
541 } // namespace I18n
542 } // namespace Global
543 } // namespace OHOS