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 #ifndef OHOS_GLOBAL_I18N_SYSTEM_LOCAEL_MANAGER_H
16 #define OHOS_GLOBAL_I18N_SYSTEM_LOCAEL_MANAGER_H
17 
18 #include "system_locale_manager.h"
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 
22 namespace OHOS {
23 namespace Global {
24 namespace I18n {
25 class SystemLocaleManagerAddon {
26 public:
27     SystemLocaleManagerAddon();
28     ~SystemLocaleManagerAddon();
29     static void Destructor(napi_env env, void *nativeObject, void *hint);
30     static napi_value InitSystemLocaleManager(napi_env env, napi_value exports);
31 
32 private:
33     static napi_value SystemLocaleManagerConstructor(napi_env env, napi_callback_info info);
34     bool InitSystemLocaleManagerContext(napi_env env, napi_callback_info info);
35 
36     // process js function call
37     static napi_value GetLanguageInfoArray(napi_env env, napi_callback_info info);
38     static napi_value GetCountryInfoArray(napi_env env, napi_callback_info info);
39     static napi_value GetTimeZoneCityInfoArray(napi_env env, napi_callback_info info);
40 
41     // convert napi variable to c++ variable
42     static void GetSortOptionsFromJsParam(napi_env env, napi_value &jsOptions, SortOptions &options, bool isRegion);
43 
44     // convert c++ variable to napi variable
45     static napi_value CreateTimeZoneCityItem(napi_env env, const TimeZoneCityItem &timezoneCityItem);
46     static napi_value CreateLocaleItemArray(napi_env env, const std::vector<LocaleItem> &localeItemList);
47     static napi_value CreateLocaleItem(napi_env env, const LocaleItem &localeItem);
48     static napi_value CreateSuggestionType(napi_env env, SuggestionType suggestionType);
49 
50     napi_env env_;
51     std::unique_ptr<SystemLocaleManager> systemLocaleManager_ = nullptr;
52 };
53 } // namespace I18n
54 } // namespace Global
55 } // namespace OHOS
56 #endif