mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-27 01:00:54 +00:00
新增i18n ffi桥接层代码
Signed-off-by: LYQ_YES <liuyuqiang9@huawei.com> Change-Id: I76039e4f0a94b3ae2ac4599c14bc4cf375bb5c39 Signed-off-by: LYQ_YES <liuyuqiang9@huawei.com>
This commit is contained in:
parent
8f08c28c64
commit
d3aec137fb
@ -81,6 +81,7 @@
|
||||
"//base/global/i18n/frameworks/zone:zone_util",
|
||||
"//base/global/i18n/frameworks/intl:build_module",
|
||||
"//base/global/i18n/interfaces/js/kits:build_module",
|
||||
"//base/global/i18n/interfaces/cj:build_module",
|
||||
"//base/global/i18n/frameworks/intl:geocoding_depends",
|
||||
"//base/global/i18n/sa_profile:i18n_service_ability_profile",
|
||||
"//base/global/i18n/services:i18n_service_ability"
|
||||
|
69
interfaces/cj/BUILD.gn
Normal file
69
interfaces/cj/BUILD.gn
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/global/i18n/i18n.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
group("build_module") {
|
||||
deps = [ ":cj_i18n_ffi" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("cj_i18n_ffi") {
|
||||
stack_protector_ret = true
|
||||
include_dirs = [
|
||||
"../../frameworks/intl/include",
|
||||
"../js/kits/include",
|
||||
]
|
||||
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
cflags_cc = [ "-frtti" ]
|
||||
remove_configs = [ "//build/config/compiler:no_rtti" ]
|
||||
|
||||
if (!defined(defines)) {
|
||||
defines = []
|
||||
}
|
||||
|
||||
if (!build_ohos_sdk) {
|
||||
deps = [ "../../frameworks/intl:preferred_language" ]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"icu:shared_icui18n",
|
||||
"icu:shared_icuuc",
|
||||
"napi:ace_napi",
|
||||
"napi:cj_bind_ffi",
|
||||
"napi:cj_bind_native",
|
||||
]
|
||||
sources = [ "i18n_ffi.cpp" ]
|
||||
} else {
|
||||
defines += [ "PREVIEWER" ]
|
||||
sources = [ "cj_i18n_mock.cpp" ]
|
||||
external_deps = [ "napi:cj_bind_ffi" ]
|
||||
}
|
||||
|
||||
if (current_os == "ohos") {
|
||||
defines += [ "OHOS_PLATFORM" ]
|
||||
}
|
||||
|
||||
if (current_os == "mingw") {
|
||||
defines += [ "WINDOWS_PLATFORM" ]
|
||||
}
|
||||
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "global"
|
||||
part_name = "i18n"
|
||||
}
|
20
interfaces/cj/cj_i18n_mock.cpp
Normal file
20
interfaces/cj/cj_i18n_mock.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cj_common_ffi.h"
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT int FfiOHOSGetAppPreferredLanguage = 0;
|
||||
}
|
48
interfaces/cj/i18n_ffi.cpp
Normal file
48
interfaces/cj/i18n_ffi.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "preferred_language.h"
|
||||
#include "i18n_ffi.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace I18n {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
extern "C"
|
||||
{
|
||||
char* MallocCString(const std::string& origin)
|
||||
{
|
||||
if (origin.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto length = origin.length() + 1;
|
||||
char* res = static_cast<char*>(malloc(sizeof(char) * length));
|
||||
if (res == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::char_traits<char>::copy(res, origin.c_str(), length);
|
||||
}
|
||||
|
||||
char* FfiOHOSGetAppPreferredLanguage()
|
||||
{
|
||||
std::string language = PreferredLanguage::GetFirstPreferredLanguage();
|
||||
char* res = MallocCString(language);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
interfaces/cj/i18n_ffi.h
Normal file
26
interfaces/cj/i18n_ffi.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef I18N_FFI_H
|
||||
#define I18N_FFI_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
FFI_EXPORT char* FfiOHOSGetAppPreferredLanguage();
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user