replace hilog with macro define

Signed-off-by: sunyaozu <sunyaozu@huawei.com>
This commit is contained in:
sunyaozu 2024-03-06 17:26:38 +08:00
parent 7e733549f0
commit 0c4185676c
36 changed files with 685 additions and 750 deletions

View File

@ -0,0 +1,27 @@
/*
* 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 OHOS_GLOBAL_I18N_I18N_HILOG
#define OHOS_GLOBAL_I18N_I18N_HILOG
#include "hilog/log.h"
#undef LOG_DOMAIN
#define LOG_DOMAIN 0xD001E00
#undef LOG_TAG
#define LOG_TAG "GLOBAL_I18N"
#define HILOG_INFO_I18N(...) HILOG_INFO(LOG_CORE, __VA_ARGS__)
#define HILOG_ERROR_I18N(...) HILOG_ERROR(LOG_CORE, __VA_ARGS__)
#endif

View File

@ -13,23 +13,21 @@
* limitations under the License.
*/
#include "date_rule_init.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "DateRuleInit" };
using namespace OHOS::HiviewDFX;
DateRuleInit::DateRuleInit(std::string& locale)
{
dateTimeRule = new DateTimeRule(locale);
if (dateTimeRule == nullptr) {
HiLog::Error(LABEL, "DateTimeRule construct failed.");
HILOG_ERROR_I18N("DateTimeRule construct failed.");
}
this->locale = dateTimeRule->GetLocale();
filter = new DateTimeFilter(this->locale, dateTimeRule);
if (filter == nullptr) {
HiLog::Error(LABEL, "DateTimeFilter construct failed.");
HILOG_ERROR_I18N("DateTimeFilter construct failed.");
}
Init();
}

View File

@ -14,15 +14,12 @@
*/
#include "date_time_filter.h"
#include <algorithm>
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "utils.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "DateTimeFilter" };
using namespace OHOS::HiviewDFX;
DateTimeFilter::DateTimeFilter(std::string& locale, DateTimeRule* dateTimeRule)
{
this->locale = locale;
@ -155,7 +152,7 @@ std::vector<MatchedDateTimeInfo> DateTimeFilter::FilterOverlayFirst(std::vector<
std::string currentRegex = currentMatch.GetRegex();
std::string matchRegex = match.GetRegex();
if (this->dateTimeRule == nullptr) {
HiLog::Error(LABEL, "FilterOverlayFirst failed because this->dateTimeRule is nullptr.");
HILOG_ERROR_I18N("FilterOverlayFirst failed because this->dateTimeRule is nullptr.");
return matchList;
}
// if the matched time segments overlap, retain the high-priority.
@ -286,7 +283,7 @@ std::vector<MatchedDateTimeInfo> DateTimeFilter::FilterDateTime(icu::UnicodeStri
UErrorCode status = U_ZERO_ERROR;
icu::RegexPattern* pattern = dateTimeRule->GetPatternsMap()["datetime"];
if (pattern == nullptr) {
HiLog::Error(LABEL, "FilterDateTime failed because pattern is nullptr.");
HILOG_ERROR_I18N("FilterDateTime failed because pattern is nullptr.");
return matches;
}
std::string::size_type matchIndex = 1;
@ -338,7 +335,7 @@ std::vector<MatchedDateTimeInfo> DateTimeFilter::FilterPeriod(icu::UnicodeString
UErrorCode status = U_ZERO_ERROR;
icu::RegexPattern* pattern = dateTimeRule->GetPatternsMap()["period"];
if (pattern == nullptr) {
HiLog::Error(LABEL, "FilterPeriod failed because pattern is nullptr.");
HILOG_ERROR_I18N("FilterPeriod failed because pattern is nullptr.");
return matches;
}
std::string::size_type matchIndex = 1;
@ -355,7 +352,7 @@ std::vector<MatchedDateTimeInfo> DateTimeFilter::FilterPeriod(icu::UnicodeString
match.GetBegin() - currentMatch.GetEnd());
icu::RegexMatcher* matcher = pattern->matcher(matchContent, status);
if (matcher == nullptr) {
HiLog::Error(LABEL, "FilterPeriod failed because pattern matcher failed.");
HILOG_ERROR_I18N("FilterPeriod failed because pattern matcher failed.");
return matches;
}
if (matcher->matches(status)) {
@ -430,12 +427,12 @@ bool DateTimeFilter::DealBrackets(icu::UnicodeString& content, std::vector<Match
UErrorCode status = U_ZERO_ERROR;
icu::RegexPattern* pattern = dateTimeRule->GetPatternsMap()["brackets"];
if (pattern == nullptr) {
HiLog::Error(LABEL, "DealBrackets failed because pattern is nullptr.");
HILOG_ERROR_I18N("DealBrackets failed because pattern is nullptr.");
return false;
}
icu::RegexMatcher* matcher = pattern->matcher(endStr, status);
if (matcher == nullptr) {
HiLog::Error(LABEL, "DealBrackets failed because pattern matcher failed.");
HILOG_ERROR_I18N("DealBrackets failed because pattern matcher failed.");
return false;
}
icu::UnicodeString groupStr;
@ -491,7 +488,7 @@ int DateTimeFilter::GetResult(icu::UnicodeString& content, MatchedDateTimeInfo&
int result = 0;
icu::UnicodeString ss = content.tempSubString(current.GetEnd(), nextMatch.GetBegin() - current.GetEnd());
if (this->dateTimeRule == nullptr) {
HiLog::Error(LABEL, "GetResult failed because this->dateTimeRule is nullptr.");
HILOG_ERROR_I18N("GetResult failed because this->dateTimeRule is nullptr.");
return result;
}
if (this->dateTimeRule->IsRelDates(ss, this->locale) || ss.trim() == '(') {
@ -509,12 +506,12 @@ int DateTimeFilter::GetResult(icu::UnicodeString& content, MatchedDateTimeInfo&
UErrorCode status = U_ZERO_ERROR;
icu::RegexPattern* pattern = dateTimeRule->GetPatternsMap()["brackets"];
if (pattern == nullptr) {
HiLog::Error(LABEL, "GetResult failed because pattern is nullptr.");
HILOG_ERROR_I18N("GetResult failed because pattern is nullptr.");
return result;
}
icu::RegexMatcher* matcher = pattern->matcher(endStr, status);
if (matcher == nullptr) {
HiLog::Error(LABEL, "GetResult failed because pattern matcher failed.");
HILOG_ERROR_I18N("GetResult failed because pattern matcher failed.");
return result;
}
icu::UnicodeString str = matcher->find(status) ? matcher->group(1, status) : "";

View File

@ -13,18 +13,16 @@
* limitations under the License.
*/
#include "date_time_matched.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "DateTimeMatched" };
using namespace OHOS::HiviewDFX;
DateTimeMatched::DateTimeMatched(std::string& locale)
{
dateRuleInit = new DateRuleInit(locale);
if (dateRuleInit == nullptr) {
HiLog::Error(LABEL, "DateRuleInit construct failed.");
HILOG_ERROR_I18N("DateRuleInit construct failed.");
}
}
@ -38,7 +36,7 @@ std::vector<int> DateTimeMatched::GetMatchedDateTime(icu::UnicodeString& message
icu::UnicodeString messageStr = message;
std::vector<int> result {0};
if (this->dateRuleInit == nullptr) {
HiLog::Error(LABEL, "GetMatchedDateTime failed because this->dateRuleInit is nullptr.");
HILOG_ERROR_I18N("GetMatchedDateTime failed because this->dateRuleInit is nullptr.");
return result;
}
std::vector<MatchedDateTimeInfo> matches = this->dateRuleInit->Detect(messageStr);

View File

@ -13,24 +13,22 @@
* limitations under the License.
*/
#include "entity_recognizer.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "EntityRecognizer" };
using namespace OHOS::HiviewDFX;
EntityRecognizer::EntityRecognizer(icu::Locale& locale)
{
std::string region = locale.getCountry();
std::string language = locale.getLanguage();
phoneNumberMatched = new PhoneNumberMatched(region);
if (phoneNumberMatched == nullptr) {
HiLog::Error(LABEL, "PhoneNumberMatched construct failed.");
HILOG_ERROR_I18N("PhoneNumberMatched construct failed.");
}
dateTimeMatched = new DateTimeMatched(language);
if (dateTimeMatched == nullptr) {
HiLog::Error(LABEL, "DateTimeMatched construct failed.");
HILOG_ERROR_I18N("DateTimeMatched construct failed.");
}
}
@ -46,13 +44,13 @@ std::vector<std::vector<int>> EntityRecognizer::FindEntityInfo(std::string& mess
messageStr = ConvertQanChar(messageStr);
std::vector<std::vector<int>> EntityInfo;
if (phoneNumberMatched == nullptr) {
HiLog::Error(LABEL, "FindEntityInfo failed because phoneNumberMatched is nullptr.");
HILOG_ERROR_I18N("FindEntityInfo failed because phoneNumberMatched is nullptr.");
return EntityInfo;
}
std::vector<int> phoneNumberInfo = phoneNumberMatched->GetMatchedPhoneNumber(messageStr);
EntityInfo.push_back(phoneNumberInfo);
if (dateTimeMatched == nullptr) {
HiLog::Error(LABEL, "FindEntityInfo failed because dateTimeMatched is nullptr.");
HILOG_ERROR_I18N("FindEntityInfo failed because dateTimeMatched is nullptr.");
return EntityInfo;
}
std::vector<int> dateTimeInfo = dateTimeMatched->GetMatchedDateTime(messageStr);

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "holiday_manager.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include <algorithm>
#include <climits>
#include <ctime>
@ -27,9 +27,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "HolidayManager" };
using namespace OHOS::HiviewDFX;
const char* HolidayManager::ITEM_BEGIN_TAG = "BEGIN:VEVENT";
const char* HolidayManager::ITEM_END_TAG = "END:VEVENT";
const char* HolidayManager::ITEM_DTSTART_TAG = "DTSTART";
@ -40,12 +37,12 @@ const char* HolidayManager::ITEM_RESOURCES_TAG = "RESOURCES";
HolidayManager::HolidayManager(const char* path)
{
if (path == nullptr) {
HiLog::Error(LABEL, "Failed: parameter path is NULL.");
HILOG_ERROR_I18N("Failed: parameter path is NULL.");
return;
}
std::string msg = ValidateHolidayFilePath(path);
if (msg.length() != 0) {
HiLog::Error(LABEL, "Failed: %{public}s .", msg.c_str());
HILOG_ERROR_I18N("Failed: %{public}s .", msg.c_str());
return;
}
std::vector<HolidayInfoItem> items = ReadHolidayFile(path);
@ -54,7 +51,7 @@ HolidayManager::HolidayManager(const char* path)
char strDate[10];
size_t resCode = strftime(strDate, sizeof(strDate), "%Y%m%d", &tmObj);
if (resCode == 0) {
HiLog::Error(LABEL, "Failed: strftime error:%{public}d .", resCode);
HILOG_ERROR_I18N("Failed: strftime error:%{public}d .", resCode);
return;
}
std::string startDate(strDate);

View File

@ -18,7 +18,7 @@
#include <filesystem>
#include <fstream>
#include <sys/stat.h>
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "libxml/globals.h"
#include "libxml/tree.h"
#include "libxml/xmlstring.h"
@ -45,8 +45,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nJs" };
using namespace OHOS::HiviewDFX;
using namespace std::filesystem;
const char *I18nTimeZone::TIMEZONE_KEY = "persist.time.timezone";
@ -711,7 +709,7 @@ std::string I18nTimeZone::GetDisplayName(std::string localeStr, bool isDST)
locale = icu::Locale::forLanguageTag(localeStr, status);
}
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "create icu Locale for %{public}s failed.", localeStr.c_str());
HILOG_ERROR_I18N("create icu Locale for %{public}s failed.", localeStr.c_str());
return result;
}
icu::UnicodeString name;
@ -796,7 +794,7 @@ void I18nTimeZone::GetTimezoneIDFromZoneInfo(std::set<std::string> &availableIDs
for (const auto &dirEntry : directory_iterator{parentPath}) {
std::string zonePath = dirEntry.path();
if (stat(zonePath.c_str(), &s) != 0) {
HiLog::Error(LABEL, "GetTimezoneIDFromZoneInfo: zoneinfo path %{public}s not exist.", parentPath.c_str());
HILOG_ERROR_I18N("GetTimezoneIDFromZoneInfo: zoneinfo path %{public}s not exist.", parentPath.c_str());
return;
}
std::string zoneName = zonePath.substr(parentPath.length() + 1); // 1 add length of path splitor
@ -820,7 +818,7 @@ std::set<std::string> I18nTimeZone::GetAvailableIDs(I18nErrorCode &errorCode)
for (const auto &dirEntry : directory_iterator{ZONEINFO_PATH}) {
std::string parentPath = dirEntry.path();
if (stat(parentPath.c_str(), &s) != 0) {
HiLog::Error(LABEL, "GetAvailableIDs: zoneinfo path %{public}s not exist.", parentPath.c_str());
HILOG_ERROR_I18N("GetAvailableIDs: zoneinfo path %{public}s not exist.", parentPath.c_str());
errorCode = I18nErrorCode::FAILED;
return availableIDs;
}
@ -859,13 +857,13 @@ std::string I18nTimeZone::FindCityDisplayNameFromXml(std::string &cityID, std::s
}
xmlDocPtr doc = xmlParseFile(xmlPath.c_str());
if (!doc) {
HiLog::Error(LABEL, "FindCityDisplayNameFromXml: can't parse city displayname: %{public}s", xmlPath.c_str());
HILOG_ERROR_I18N("FindCityDisplayNameFromXml: can't parse city displayname: %{public}s", xmlPath.c_str());
return "";
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (!cur || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(CITY_DISPLAYNAME_ROOT_TAG))) {
xmlFreeDoc(doc);
HiLog::Error(LABEL,
HILOG_ERROR_I18N(
"FindCityDisplayNameFromXml: city displayname file %{public}s has wrong root tag.", xmlPath.c_str());
return "";
}
@ -912,13 +910,13 @@ std::map<std::string, std::string> I18nTimeZone::FindCityDisplayNameMap(std::str
}
xmlDocPtr doc = xmlParseFile(xmlPath.c_str());
if (!doc) {
HiLog::Error(LABEL, "FindCityDisplayNameMap: can't parse city displayname file %{public}s", xmlPath.c_str());
HILOG_ERROR_I18N("FindCityDisplayNameMap: can't parse city displayname file %{public}s", xmlPath.c_str());
return resultMap;
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (!cur || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(CITY_DISPLAYNAME_ROOT_TAG))) {
xmlFreeDoc(doc);
HiLog::Error(LABEL,
HILOG_ERROR_I18N(
"FindCityDisplayNameMap: city displayname file %{public}s has wrong root tag.", xmlPath.c_str());
return resultMap;
}
@ -964,7 +962,7 @@ bool I18nTimeZone::GetSupportedLocales()
for (const auto &dirEntry : directory_iterator{displayNamePath}) {
std::string xmlPath = dirEntry.path();
if (stat(xmlPath.c_str(), &s) != 0) {
HiLog::Error(LABEL, "city displayname file %{public}s not exist.", xmlPath.c_str());
HILOG_ERROR_I18N("city displayname file %{public}s not exist.", xmlPath.c_str());
return false;
}
int32_t localeStrLen = static_cast<int32_t>(xmlPath.length()) - static_cast<int32_t>(
@ -1011,7 +1009,7 @@ std::string I18nTimeZone::GetCityDisplayName(std::string &cityID, std::string &l
GetAvailableZoneCityIDs();
}
if (availableZoneCityIDs.find(cityID) == availableZoneCityIDs.end()) {
HiLog::Error(LABEL, "%{public}s is not supported cityID.", cityID.c_str());
HILOG_ERROR_I18N("%{public}s is not supported cityID.", cityID.c_str());
return "";
}
std::string requestLocaleStr = GetLocaleBaseName(localeStr);
@ -1029,14 +1027,14 @@ std::string I18nTimeZone::GetLocaleBaseName(std::string &localeStr)
if (supportedLocales.size() == 0) {
bool status = GetSupportedLocales();
if (!status) {
HiLog::Error(LABEL, "get supported Locales failed");
HILOG_ERROR_I18N("get supported Locales failed");
return "";
}
}
UErrorCode errorCode = U_ZERO_ERROR;
icu::Locale locale = icu::Locale::forLanguageTag(localeStr, errorCode);
if (U_FAILURE(errorCode)) {
HiLog::Error(LABEL, "create icu Locale for %{public}s failed", localeStr.c_str());
HILOG_ERROR_I18N("create icu Locale for %{public}s failed", localeStr.c_str());
return "";
}
std::string requestLocaleStr = locale.getBaseName();
@ -1046,7 +1044,7 @@ std::string I18nTimeZone::GetLocaleBaseName(std::string &localeStr)
}
locale.addLikelySubtags(errorCode);
if (U_FAILURE(errorCode)) {
HiLog::Error(LABEL, "add likely subtags for %{public}s failed", localeStr.c_str());
HILOG_ERROR_I18N("add likely subtags for %{public}s failed", localeStr.c_str());
return "";
}
requestLocaleStr = locale.getBaseName();
@ -1077,7 +1075,7 @@ std::vector<std::string> I18nTimeZone::GetTimezoneIdByLocation(const double x, c
std::vector<std::string> tzIdList;
#ifdef SUPPORT_GRAPHICS
if (!CheckLatitudeAndLongitude(x, y)) {
HiLog::Error(LABEL, "invalid longitude:%{public}f or latitude: %{public}f ", x, y);
HILOG_ERROR_I18N("invalid longitude:%{public}f or latitude: %{public}f ", x, y);
return tzIdList;
}
std::map<int, std::string> categoryMap = GetTimeZoneCategoryMap(x, y);
@ -1099,7 +1097,7 @@ std::vector<std::string> I18nTimeZone::GetTimezoneIdByLocation(const double x, c
uint16_t fixedX = static_cast<uint16_t>(calculateX);
uint16_t fixedY = static_cast<uint16_t>(calculateY);
if (ParamExceedScope(fixedX, fixedY, width, height * fileCount)) {
HiLog::Error(LABEL, "invalid width:%{public}d or height: %{public}d", fixedX, fixedY);
HILOG_ERROR_I18N("invalid width:%{public}d or height: %{public}d", fixedX, fixedY);
return tzIdList;
}
uint16_t actualHeight = fileCount > 1 ? (fixedY % height) : fixedY;
@ -1166,7 +1164,7 @@ std::vector<int> I18nTimeZone::GetColorData(const uint16_t x, const uint16_t y,
if (row_pointers == nullptr) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
CloseFile(fp);
HiLog::Error(LABEL, "malloc rowbytes failed.");
HILOG_ERROR_I18N("malloc rowbytes failed.");
return result;
}
png_start_read_image(png_ptr);
@ -1221,26 +1219,26 @@ int I18nTimeZone::InitPngptr(png_structp &png_ptr, png_infop &info_ptr, FILE **f
{
bool validFilePath = CheckTzDataFilePath(preferredPath);
if (!validFilePath) {
HiLog::Error(LABEL, "timezone data filepath invalid.");
HILOG_ERROR_I18N("timezone data filepath invalid.");
return 1;
}
*fp = fopen(preferredPath.c_str(), "rb");
if (*fp == NULL) {
HiLog::Error(LABEL, "timezone data resource file not exists.");
HILOG_ERROR_I18N("timezone data resource file not exists.");
return 1;
}
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
CloseFile(*fp);
HiLog::Error(LABEL, "create read_struct failed.");
HILOG_ERROR_I18N("create read_struct failed.");
return 1;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
CloseFile(*fp);
HiLog::Error(LABEL, "create info_struct failed.");
HILOG_ERROR_I18N("create info_struct failed.");
return 1;
}
return 0;

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "locale_compare.h"
#include "ohos/init_data.h"
#include "unicode/locid.h"
@ -21,8 +21,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "LocaleCompare" };
using namespace OHOS::HiviewDFX;
std::string LocaleCompare::hantSegment = "-Hant-";
std::string LocaleCompare::latnSegment = "-Latn-";
std::string LocaleCompare::qaagSegment = "-Qaag-";
@ -156,7 +154,7 @@ int32_t LocaleCompare::Compare(const std::string& localeTag1, const std::string&
locale1.addLikelySubtags(status);
locale2.addLikelySubtags(status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "LocaleCompare::Compare add likely subtags failed.");
HILOG_ERROR_I18N("LocaleCompare::Compare add likely subtags failed.");
return -1;
}
std::string script1 = locale1.getScript();

View File

@ -22,7 +22,7 @@
#include <common_event_support.h>
#endif
#include <cctype>
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "ipc_skeleton.h"
#include "libxml/parser.h"
#include "locale_info.h"
@ -47,9 +47,6 @@ namespace OHOS {
namespace Global {
namespace I18n {
using namespace std;
using namespace OHOS::HiviewDFX;
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "LocaleConfig" };
const char *LocaleConfig::LANGUAGE_KEY = "persist.global.language";
const char *LocaleConfig::LOCALE_KEY = "persist.global.locale";
const char *LocaleConfig::HOUR_KEY = "persist.global.is24Hour";
@ -625,14 +622,14 @@ std::string LocaleConfig::ComputeLocale(const std::string &displayLocale)
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (!cur || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(supportLocalesTag))) {
xmlFreeDoc(doc);
HiLog::Info(LABEL, "can not parse language supported locale file");
HILOG_INFO_I18N("can not parse language supported locale file");
return DEFAULT_LOCALE;
}
cur = cur->xmlChildrenNode;
while (cur != nullptr) {
xmlChar *content = xmlNodeGetContent(cur);
if (content == nullptr) {
HiLog::Info(LABEL, "get xml node content failed");
HILOG_INFO_I18N("get xml node content failed");
break;
}
std::map<std::string, std::string> localeInfoConfigs = {};
@ -670,13 +667,13 @@ void LocaleConfig::ReadLangData(const char *langDataPath)
}
xmlDocPtr doc = xmlParseFile(langDataPath);
if (!doc) {
HiLog::Info(LABEL, "can not open language data file");
HILOG_INFO_I18N("can not open language data file");
return;
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (!cur || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(rootTag))) {
xmlFreeDoc(doc);
HiLog::Info(LABEL, "parse language data file failed");
HILOG_INFO_I18N("parse language data file failed");
return;
}
cur = cur->xmlChildrenNode;
@ -713,16 +710,16 @@ void LocaleConfig::ReadRegionData(const char *regionDataPath)
}
xmlDocPtr doc = xmlParseFile(regionDataPath);
if (!doc) {
HiLog::Info(LABEL, "can not open region data file");
HILOG_INFO_I18N("can not open region data file");
return;
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (cur) {
HiLog::Info(LABEL, "cur pointer is true");
HILOG_INFO_I18N("cur pointer is true");
}
if (!cur || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(rootRegion))) {
xmlFreeDoc(doc);
HiLog::Info(LABEL, "parse region data file failed");
HILOG_INFO_I18N("parse region data file failed");
return;
}
cur = cur->xmlChildrenNode;
@ -1019,14 +1016,14 @@ std::unordered_set<std::string> LocaleConfig::GetLanguageBlockedRegions()
I18nErrorCode LocaleConfig::SetSystemLanguage(const std::string &languageTag)
{
if (!IsValidTag(languageTag)) {
HiLog::Error(LABEL, "LocaleConfig::SetSystemLanguage %{public}s is not valid language tag.",
HILOG_ERROR_I18N("LocaleConfig::SetSystemLanguage %{public}s is not valid language tag.",
languageTag.c_str());
return I18nErrorCode::INVALID_LANGUAGE_TAG;
}
// save old language, reset system language to old language if update locale failed.
std::string oldLanguageTag = GetSystemLanguage();
if (SetParameter(LANGUAGE_KEY, languageTag.data()) != 0) {
HiLog::Error(LABEL, "LocaleConfig::SetSystemLanguage update system language failed.");
HILOG_ERROR_I18N("LocaleConfig::SetSystemLanguage update system language failed.");
return I18nErrorCode::UPDATE_SYSTEM_LANGUAGE_FAILED;
}
std::string newLocaleTag = UpdateLanguageOfLocale(languageTag);
@ -1034,7 +1031,7 @@ I18nErrorCode LocaleConfig::SetSystemLanguage(const std::string &languageTag)
return I18nErrorCode::SUCCESS;
}
// reset system language to old language in case that system language is inconsist with system locale's lanuage.
HiLog::Error(LABEL, "LocaleConfig::SetSystemLanguage update system locale failed.");
HILOG_ERROR_I18N("LocaleConfig::SetSystemLanguage update system locale failed.");
SetParameter(LANGUAGE_KEY, oldLanguageTag.data());
return I18nErrorCode::UPDATE_SYSTEM_LANGUAGE_FAILED;
}
@ -1042,7 +1039,7 @@ I18nErrorCode LocaleConfig::SetSystemLanguage(const std::string &languageTag)
I18nErrorCode LocaleConfig::SetSystemRegion(const std::string &regionTag)
{
if (!IsValidRegion(regionTag)) {
HiLog::Error(LABEL, "LocaleConfig::SetSystemRegion %{public}s is not valid region tag.", regionTag.c_str());
HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion %{public}s is not valid region tag.", regionTag.c_str());
return I18nErrorCode::INVALID_REGION_TAG;
}
return SetSystemLocale(UpdateRegionOfLocale(regionTag));
@ -1051,7 +1048,7 @@ I18nErrorCode LocaleConfig::SetSystemRegion(const std::string &regionTag)
I18nErrorCode LocaleConfig::SetSystemLocale(const std::string &localeTag)
{
if (!IsValidTag(localeTag)) {
HiLog::Error(LABEL, "LocaleConfig::SetSystemLocale %{public}s is not a valid locale tag.", localeTag.c_str());
HILOG_ERROR_I18N("LocaleConfig::SetSystemLocale %{public}s is not a valid locale tag.", localeTag.c_str());
return I18nErrorCode::INVALID_LOCALE_TAG;
}
if (SetParameter(LOCALE_KEY, localeTag.data()) != 0) {
@ -1076,11 +1073,11 @@ bool LocaleConfig::IsValid24HourClockValue(const std::string &tag)
I18nErrorCode LocaleConfig::Set24HourClock(const std::string &option)
{
if (!IsValid24HourClockValue(option)) {
HiLog::Error(LABEL, "LocaleConfig::Set24HourClock invalid 24 Hour clock tag: %{public}s", option.c_str());
HILOG_ERROR_I18N("LocaleConfig::Set24HourClock invalid 24 Hour clock tag: %{public}s", option.c_str());
return I18nErrorCode::INVALID_24_HOUR_CLOCK_TAG;
}
if (SetParameter(HOUR_KEY, option.data()) != 0) {
HiLog::Error(LABEL, "LocaleConfig::Set24HourClock update 24 hour clock failed with option=%{public}s",
HILOG_ERROR_I18N("LocaleConfig::Set24HourClock update 24 hour clock failed with option=%{public}s",
option.c_str());
return I18nErrorCode::UPDATE_24_HOUR_CLOCK_FAILED;
}
@ -1099,7 +1096,7 @@ I18nErrorCode LocaleConfig::SetUsingLocalDigit(bool flag)
std::string languageTag = localeTag.substr(0, 2); // obtain 2 length language code.
auto it = localDigitMap.find(languageTag);
if (it == localDigitMap.end()) {
HiLog::Error(LABEL, "LocaleConfig::SetUsingLocalDigit current system doesn't support set local digit");
HILOG_ERROR_I18N("LocaleConfig::SetUsingLocalDigit current system doesn't support set local digit");
return I18nErrorCode::UPDATE_LOCAL_DIGIT_FAILED;
}
// update system locale.
@ -1160,7 +1157,7 @@ void LocaleConfig::UpdateConfiguration(const char *key, const std::string &value
configuration.AddItem(key, value);
auto appMgrClient = std::make_unique<AppExecFwk::AppMgrClient>();
appMgrClient->UpdateConfiguration(configuration);
HiLog::Info(LABEL, "LocaleConfig::UpdateLanguageConfiguration update configuration finished.");
HILOG_INFO_I18N("LocaleConfig::UpdateLanguageConfiguration update configuration finished.");
}
I18nErrorCode LocaleConfig::PublishCommonEvent(const std::string &eventType)
@ -1169,11 +1166,11 @@ I18nErrorCode LocaleConfig::PublishCommonEvent(const std::string &eventType)
localeChangeWant.SetAction(eventType);
OHOS::EventFwk::CommonEventData event(localeChangeWant);
if (!OHOS::EventFwk::CommonEventManager::PublishCommonEvent(event)) {
HiLog::Error(LABEL, "LocaleConfig::PublishCommonEvent Failed to Publish event %{public}s",
HILOG_ERROR_I18N("LocaleConfig::PublishCommonEvent Failed to Publish event %{public}s",
localeChangeWant.GetAction().c_str());
return I18nErrorCode::PUBLISH_COMMON_EVENT_FAILED;
}
HiLog::Info(LABEL, "LocaleConfig::PublishCommonEvent publish event finished.");
HILOG_INFO_I18N("LocaleConfig::PublishCommonEvent publish event finished.");
return I18nErrorCode::SUCCESS;
}
#endif
@ -1184,7 +1181,7 @@ std::string LocaleConfig::UpdateLanguageOfLocale(const std::string &languageTag)
UErrorCode status = U_ZERO_ERROR;
icu::Locale languageLocale = icu::Locale::forLanguageTag(languageTag.c_str(), status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "LocaleConfig::UpdateLanguageOfLocale init icu Locale for language %{public}s failed.",
HILOG_ERROR_I18N("LocaleConfig::UpdateLanguageOfLocale init icu Locale for language %{public}s failed.",
languageTag.c_str());
return "";
}
@ -1194,7 +1191,7 @@ std::string LocaleConfig::UpdateLanguageOfLocale(const std::string &languageTag)
std::string systemLocaleTag = GetSystemLocale();
icu::Locale systemLocale = icu::Locale::forLanguageTag(systemLocaleTag.c_str(), status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "LocaleConfig::UpdateSystemLocale init icu Locale for locale %{public}s failed.",
HILOG_ERROR_I18N("LocaleConfig::UpdateSystemLocale init icu Locale for locale %{public}s failed.",
systemLocaleTag.c_str());
return "";
}
@ -1237,7 +1234,7 @@ std::string LocaleConfig::UpdateRegionOfLocale(const std::string &regionTag)
UErrorCode status = U_ZERO_ERROR;
const icu::Locale origin = icu::Locale::forLanguageTag(localeTag, status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "LocaleConfig::UpdateRegionOfLocale init origin locale failed.");
HILOG_ERROR_I18N("LocaleConfig::UpdateRegionOfLocale init origin locale failed.");
return "";
}
icu::LocaleBuilder builder = icu::LocaleBuilder().setLanguage(origin.getLanguage()).
@ -1245,7 +1242,7 @@ std::string LocaleConfig::UpdateRegionOfLocale(const std::string &regionTag)
icu::Locale temp = builder.setExtension('u', "").build(status);
string ret = temp.toLanguageTag<string>(status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "LocaleConfig::UpdateRegionOfLocale obtain new locale's tag failed.");
HILOG_ERROR_I18N("LocaleConfig::UpdateRegionOfLocale obtain new locale's tag failed.");
return "";
}
return ret;
@ -1258,12 +1255,12 @@ std::string LocaleConfig::CreateLocaleFromRegion(const std::string &regionTag)
UErrorCode status = U_ZERO_ERROR;
locale.addLikelySubtags(status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "LocaleConfig::CreateLocaleFromRegion init new locale failed.");
HILOG_ERROR_I18N("LocaleConfig::CreateLocaleFromRegion init new locale failed.");
return "";
}
std::string localeTag = locale.toLanguageTag<string>(status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "LocaleConfig::CreateLocaleFromRegion obtain new locale's tag failed.");
HILOG_ERROR_I18N("LocaleConfig::CreateLocaleFromRegion obtain new locale's tag failed.");
return "";
}
return localeTag;

View File

@ -19,7 +19,7 @@
#include "unicode/localebuilder.h"
#include "locale_config.h"
#include "unicode/locid.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "map"
#include "new"
#include "set"
@ -34,8 +34,6 @@ namespace Global {
namespace I18n {
const int RECV_CHAR_LEN = 128;
using i18n::phonenumbers::PhoneNumberUtil;
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "PhoneNumberFormat" };
using namespace OHOS::HiviewDFX;
void* PhoneNumberFormat::dynamicHandler = nullptr;
std::mutex PhoneNumberFormat::phoneMutex;
@ -171,7 +169,7 @@ std::string PhoneNumberFormat::getPhoneLocationName(const std::string& number, c
std::lock_guard<std::mutex> phoneLock(phoneMutex);
std::string locName;
if (dynamicHandler && !locationNameFunc) {
HiLog::Error(LABEL, "LocationNameFunc Init");
HILOG_ERROR_I18N("LocationNameFunc Init");
locationNameFunc = reinterpret_cast<ExposeLocationName>(
dlsym(dynamicHandler, "exposeLocationName"));
}
@ -191,7 +189,7 @@ std::string PhoneNumberFormat::getPhoneLocationName(const std::string& number, c
void PhoneNumberFormat::OpenHandler()
{
if (dynamicHandler == nullptr) {
HiLog::Info(LABEL, "DynamicHandler init.");
HILOG_INFO_I18N("DynamicHandler init.");
std::lock_guard<std::mutex> phoneLock(phoneMutex);
if (dynamicHandler == nullptr) {
#ifndef SUPPORT_ASAN
@ -199,7 +197,7 @@ void PhoneNumberFormat::OpenHandler()
#else
const char* geocodingSO = "system/asan/lib64/libgeocoding.z.so";
#endif
HiLog::Info(LABEL, "DynamicHandler lock init.");
HILOG_INFO_I18N("DynamicHandler lock init.");
dynamicHandler = dlopen(geocodingSO, RTLD_NOW);
}
}

View File

@ -15,7 +15,7 @@
#include <climits>
#include <set>
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "regex_rule.h"
#include "phone_number_matched.h"
#include "utils.h"
@ -24,8 +24,6 @@ namespace OHOS {
namespace Global {
namespace I18n {
using i18n::phonenumbers::PhoneNumber;
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "PhoneNumberMatched" };
using namespace OHOS::HiviewDFX;
const int PhoneNumberMatched::CONTAIN = 9;
const int PhoneNumberMatched::CONTAIN_OR_INTERSECT = 8;
@ -145,7 +143,7 @@ std::vector<MatchedNumberInfo> PhoneNumberMatched::FindShortNumbers(std::string&
icu::RegexPattern* shortPattern = shortRegexRule->GetPattern();
icu::RegexMatcher* shortMatch = shortPattern->matcher(message, status);
if (shortMatch == nullptr) {
HiLog::Error(LABEL, "shortPattern matcher failed.");
HILOG_ERROR_I18N("shortPattern matcher failed.");
return matchedNumberInfoList;
}
while (shortMatch->find(status)) {
@ -156,7 +154,7 @@ std::vector<MatchedNumberInfo> PhoneNumberMatched::FindShortNumbers(std::string&
PhoneNumberUtil::ErrorType errorType =
phoneNumberUtil->ParseAndKeepRawInput(stringParse, country, &phoneNumber);
if (errorType != PhoneNumberUtil::NO_PARSING_ERROR) {
HiLog::Error(LABEL, "PhoneNumberRule: failed to call the ParseAndKeepRawInput.");
HILOG_ERROR_I18N("PhoneNumberRule: failed to call the ParseAndKeepRawInput.");
continue;
}
// Add the valid short number to the result

View File

@ -17,8 +17,7 @@
#include <unicode/stringpiece.h>
#include "algorithm"
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#include "i18n_hilog.h"
#include "locale_config.h"
#include "unicode/locid.h"
#include "plural_rules.h"
@ -35,9 +34,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "IntlJs" };
using namespace OHOS::HiviewDFX;
std::string PluralRules::ParseOption(std::map<std::string, std::string> &options, const std::string &key)
{
std::map<std::string, std::string>::iterator it = options.find(key);
@ -132,7 +128,7 @@ void PluralRules::InitPluralRules(std::vector<std::string> &localeTags,
}
}
if (status != UErrorCode::U_ZERO_ERROR || !pluralRules) {
HiLog::Error(LABEL, "PluralRules object created failed");
HILOG_ERROR_I18N("PluralRules object created failed");
return;
}
}

View File

@ -21,7 +21,7 @@
#include "iservice_registry.h"
#include "system_ability_definition.h"
#endif
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "locale_config.h"
#include "locale_info.h"
#include "parameter.h"
@ -31,8 +31,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "PreferredLanguage" };
using namespace OHOS::HiviewDFX;
const char *PreferredLanguage::RESOURCE_PATH_HEAD = "/data/accounts/account_0/applications/";
const char *PreferredLanguage::RESOURCE_PATH_TAILOR = "/assets/entry/resources.index";
const char *PreferredLanguage::RESOURCE_PATH_SPLITOR = "/";
@ -90,7 +88,7 @@ std::shared_ptr<NativePreferences::Preferences> PreferredLanguage::GetI18nAppPre
std::shared_ptr<NativePreferences::Preferences> preferences =
NativePreferences::PreferencesHelper::GetPreferences(options, status);
if (status != 0) {
HiLog::Error(LABEL, "PreferredLanguage::GetAppPreferredLanguage get i18n app preferences failed.");
HILOG_ERROR_I18N("PreferredLanguage::GetAppPreferredLanguage get i18n app preferences failed.");
return nullptr;
}
return preferences;
@ -100,7 +98,7 @@ std::string PreferredLanguage::GetAppPreferredLanguage()
{
std::shared_ptr<NativePreferences::Preferences> preferences = GetI18nAppPreferences();
if (preferences == nullptr) {
HiLog::Error(LABEL,
HILOG_ERROR_I18N(
"PreferredLanguage::GetAppPreferredLanguage get i18n preferences failed, return system language.");
return LocaleConfig::GetSystemLanguage();
}
@ -118,13 +116,13 @@ void PreferredLanguage::SetAppPreferredLanguage(const std::string &language, I18
std::shared_ptr<NativePreferences::Preferences> preferences = GetI18nAppPreferences();
if (preferences == nullptr) {
errCode = I18nErrorCode::FAILED;
HiLog::Error(LABEL, "PreferredLanguage::SetAppPreferredLanguage get i18n preferences failed.");
HILOG_ERROR_I18N("PreferredLanguage::SetAppPreferredLanguage get i18n preferences failed.");
return;
}
int32_t status = preferences->PutString(PreferredLanguage::APP_LANGUAGE_KEY, language);
if (status != 0) {
errCode = I18nErrorCode::FAILED;
HiLog::Error(LABEL,
HILOG_ERROR_I18N(
"PreferredLanguage::SetAppPreferredLanguage set app language to i18n preferences failed.");
return;
}
@ -188,7 +186,7 @@ void PreferredLanguage::Split(const std::string &src, const std::string &sep, st
I18nErrorCode PreferredLanguage::AddPreferredLanguage(const std::string &language, int32_t index)
{
if (!IsValidTag(language)) {
HiLog::Error(LABEL, "PreferredLanguage::AddPreferredLanguage %{public}s is not valid language tag.",
HILOG_ERROR_I18N("PreferredLanguage::AddPreferredLanguage %{public}s is not valid language tag.",
language.c_str());
return I18nErrorCode::INVALID_LANGUAGE_TAG;
}
@ -202,7 +200,7 @@ I18nErrorCode PreferredLanguage::AddPreferredLanguage(const std::string &languag
AddExistPreferredLanguage(language, index, preferredLanguages, status);
}
if (status != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "PreferredLanguage::AddPreferredLanguage failed.");
HILOG_ERROR_I18N("PreferredLanguage::AddPreferredLanguage failed.");
return status;
}
return SetPreferredLanguages(JoinPreferredLanguages(preferredLanguages));
@ -212,7 +210,7 @@ I18nErrorCode PreferredLanguage::RemovePreferredLanguage(int32_t index)
{
std::vector<std::string> preferredLanguages = GetPreferredLanguageList();
if (preferredLanguages.size() == 1) {
HiLog::Error(LABEL, "PreferredLanguage::RemovePreferredLanguage can't remove the only language.");
HILOG_ERROR_I18N("PreferredLanguage::RemovePreferredLanguage can't remove the only language.");
return I18nErrorCode::REMOVE_PREFERRED_LANGUAGE_FAILED;
}
// valid index is [0, preferredLanguages.size() - 1] for Remove
@ -222,7 +220,7 @@ I18nErrorCode PreferredLanguage::RemovePreferredLanguage(int32_t index)
// in preferred language list, we need to reset system language.
if (validIndex == 0) {
if (LocaleConfig::SetSystemLanguage(preferredLanguages[0]) != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "PreferredLanguage::RemovePreferredLanguage update system language failed.");
HILOG_ERROR_I18N("PreferredLanguage::RemovePreferredLanguage update system language failed.");
return I18nErrorCode::REMOVE_PREFERRED_LANGUAGE_FAILED;
}
}
@ -240,7 +238,7 @@ void PreferredLanguage::AddNonExistPreferredLanguage(const std::string& language
// in preferred language list, we need to reset system language.
if (validIndex == 0) {
if (LocaleConfig::SetSystemLanguage(preferredLanguages[0]) != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "PreferredLanguage::AddNonExistPreferredLanguage update system language failed.");
HILOG_ERROR_I18N("PreferredLanguage::AddNonExistPreferredLanguage update system language failed.");
errCode = I18nErrorCode::ADD_PREFERRED_LANGUAGE_NON_EXIST_FAILED;
return;
}
@ -267,7 +265,7 @@ void PreferredLanguage::AddExistPreferredLanguage(const std::string& language, i
// in preferred language list, we need to reset system language.
if (languageIdx == 0 || validIndex == 0) {
if (LocaleConfig::SetSystemLanguage(preferredLanguages[0]) != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "PreferredLanguage::AddExistPreferredLanguage update system language failed.");
HILOG_ERROR_I18N("PreferredLanguage::AddExistPreferredLanguage update system language failed.");
errCode = I18nErrorCode::ADD_PREFERRED_LANGUAGE_EXIST_FAILED;
return;
}
@ -316,11 +314,11 @@ I18nErrorCode PreferredLanguage::SetPreferredLanguages(const std::string &prefer
{
// System parameter value's length can't beyong CONFIG_LEN
if (preferredLanguages.length() > CONFIG_LEN) {
HiLog::Error(LABEL, "PreferredLanguage::SetPreferredLanguage preferred language list is too long.");
HILOG_ERROR_I18N("PreferredLanguage::SetPreferredLanguage preferred language list is too long.");
return I18nErrorCode::UPDATE_SYSTEM_PREFERRED_LANGUAGE_FAILED;
}
if (SetParameter(PREFERRED_LANGUAGES, preferredLanguages.data()) != 0) {
HiLog::Error(LABEL, "PreferredLanguage::AddPreferredLanguage udpate preferred language param failed.");
HILOG_ERROR_I18N("PreferredLanguage::AddPreferredLanguage udpate preferred language param failed.");
return I18nErrorCode::UPDATE_SYSTEM_PREFERRED_LANGUAGE_FAILED;
}
return I18nErrorCode::SUCCESS;

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "regex_rule.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "cpp/src/phonenumbers/phonenumberutil.h"
#include "cpp/src/phonenumbers/phonenumber.h"
#include "cpp/src/phonenumbers/shortnumberinfo.h"
@ -25,8 +25,6 @@ using i18n::phonenumbers::PhoneNumberMatch;
using i18n::phonenumbers::PhoneNumber;
using i18n::phonenumbers::PhoneNumberUtil;
using i18n::phonenumbers::ShortNumberInfo;
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "RegexRule" };
using namespace OHOS::HiviewDFX;
RegexRule::RegexRule(icu::UnicodeString& regex, std::string& isValidType, std::string& handleType,
std::string& insensitive, std::string& type)
@ -49,7 +47,7 @@ RegexRule::RegexRule(icu::UnicodeString& regex, std::string& isValidType, std::s
return;
}
if (U_FAILURE(this->status)) {
HiLog::Error(LABEL, "member pattern construct failed.");
HILOG_ERROR_I18N("member pattern construct failed.");
}
}
@ -455,7 +453,7 @@ std::vector<MatchedNumberInfo> RegexRule::GetNumbersWithSlant(icu::UnicodeString
PhoneNumberUtil* pnu = PhoneNumberUtil::GetInstance();
ShortNumberInfo* shortInfo = new ShortNumberInfo();
if (shortInfo == nullptr) {
HiLog::Error(LABEL, "ShortNumberInfo construct failed.");
HILOG_ERROR_I18N("ShortNumberInfo construct failed.");
return shortList;
}
std::string numberFisrt = "";

View File

@ -14,14 +14,11 @@
*/
#include "rules_engine.h"
#include <algorithm>
#include "hilog/log.h"
#include "i18n_hilog.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "RulesEngine" };
using namespace OHOS::HiviewDFX;
RulesEngine::RulesEngine()
{
}
@ -56,12 +53,12 @@ std::vector<MatchedDateTimeInfo> RulesEngine::Match(icu::UnicodeString& message)
icu::RegexPattern* pattern = icu::RegexPattern::compile(regex,
URegexpFlag::UREGEX_CASE_INSENSITIVE, status);
if (pattern == nullptr) {
HiLog::Error(LABEL, "Match failed because pattern is nullptr.");
HILOG_ERROR_I18N("Match failed because pattern is nullptr.");
return matches;
}
icu::RegexMatcher* matcher = pattern->matcher(message, status);
if (matcher == nullptr) {
HiLog::Error(LABEL, "Match failed because pattern matcher failed.");
HILOG_ERROR_I18N("Match failed because pattern matcher failed.");
delete pattern;
return matches;
}
@ -97,12 +94,12 @@ bool RulesEngine::InitRules(std::string& rulesValue)
{
bool isVaild = true;
if (this->dateTimeRule == nullptr) {
HiLog::Error(LABEL, "InitRules failed because this->dateTimeRule is nullptr.");
HILOG_ERROR_I18N("InitRules failed because this->dateTimeRule is nullptr.");
return false;
}
icu::RegexPattern* pattern = dateTimeRule->GetPatternsMap()["rules"];
if (pattern == nullptr) {
HiLog::Error(LABEL, "InitRules failed because pattern is nullptr.");
HILOG_ERROR_I18N("InitRules failed because pattern is nullptr.");
return isVaild;
}
UErrorCode status = U_ZERO_ERROR;
@ -110,7 +107,7 @@ bool RulesEngine::InitRules(std::string& rulesValue)
icu::UnicodeString rules = rulesValue.c_str();
icu::RegexMatcher* matcher = pattern->matcher(rules, status);
if (matcher == nullptr) {
HiLog::Error(LABEL, "InitRules failed because pattern matcher failed.");
HILOG_ERROR_I18N("InitRules failed because pattern matcher failed.");
return false;
}
while (matcher->find(status) && isVaild) {
@ -143,18 +140,18 @@ std::string RulesEngine::InitOptRules(std::string& rule)
icu::UnicodeString matchedStr = rule.c_str();
UErrorCode status = U_ZERO_ERROR;
if (this->dateTimeRule == nullptr) {
HiLog::Error(LABEL, "InitOptRules failed because this->dateTimeRule is nullptr.");
HILOG_ERROR_I18N("InitOptRules failed because this->dateTimeRule is nullptr.");
return rulesValue;
}
icu::RegexPattern* pattern = dateTimeRule->GetPatternsMap()["optrules"];
if (pattern == nullptr) {
HiLog::Error(LABEL, "InitOptRules failed because pattern is nullptr.");
HILOG_ERROR_I18N("InitOptRules failed because pattern is nullptr.");
return rulesValue;
}
if (param.size() != 0 || paramBackup.size() != 0) {
icu::RegexMatcher* matcher = pattern->matcher(matchedStr, status);
if (matcher == nullptr) {
HiLog::Error(LABEL, "InitOptRules failed because pattern matcher failed.");
HILOG_ERROR_I18N("InitOptRules failed because pattern matcher failed.");
return rulesValue;
}
while (matcher->find(status)) {
@ -195,13 +192,13 @@ std::string RulesEngine::InitSubRules(std::string& rule)
UErrorCode status = U_ZERO_ERROR;
icu::RegexPattern* pattern = dateTimeRule->GetPatternsMap()["subrules"];
if (pattern == nullptr) {
HiLog::Error(LABEL, "InitSubRules failed because pattern is nullptr.");
HILOG_ERROR_I18N("InitSubRules failed because pattern is nullptr.");
return rulesValue;
}
if (subRules.size() != 0) {
icu::RegexMatcher* matcher = pattern->matcher(matchedStr, status);
if (matcher == nullptr) {
HiLog::Error(LABEL, "InitSubRules failed because pattern matcher failed.");
HILOG_ERROR_I18N("InitSubRules failed because pattern matcher failed.");
return rulesValue;
}
while (matcher->find(status)) {

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "locale_config.h"
#include "system_locale_manager.h"
#include "unicode/calendar.h"
@ -24,9 +24,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "SystemLocaleManager" };
using namespace OHOS::HiviewDFX;
const char* SystemLocaleManager::SIM_COUNTRY_CODE_KEY = "telephony.sim.countryCode0";
SystemLocaleManager::SystemLocaleManager()
@ -133,7 +130,7 @@ void SystemLocaleManager::SortLocaleItemList(std::vector<LocaleItem> &localeItem
return true;
}
if (result == CompareResult::INVALID) {
HiLog::Error(LABEL, "SystemLocaleManager: invalid compare result for local name.");
HILOG_ERROR_I18N("SystemLocaleManager: invalid compare result for local name.");
}
return false;
}
@ -142,7 +139,7 @@ void SystemLocaleManager::SortLocaleItemList(std::vector<LocaleItem> &localeItem
return true;
}
if (result == CompareResult::INVALID) {
HiLog::Error(LABEL, "SystemLocaleManager: invalid compare result for display name.");
HILOG_ERROR_I18N("SystemLocaleManager: invalid compare result for display name.");
}
return false;
};
@ -204,7 +201,7 @@ void SystemLocaleManager::SortTimezoneCityItemList(const std::string &locale,
return true;
}
if (result == CompareResult::INVALID) {
HiLog::Error(LABEL, "SystemLocaleManager: invalid compare result for city display name.");
HILOG_ERROR_I18N("SystemLocaleManager: invalid compare result for city display name.");
}
return false;
};

View File

@ -16,7 +16,7 @@
#include <cstring>
#include <filesystem>
#include <sys/stat.h>
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "libxml/globals.h"
#include "libxml/tree.h"
#include "libxml/xmlstring.h"
@ -26,8 +26,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "Taboo" };
using namespace OHOS::HiviewDFX;
const char* Taboo::ROOT_TAG = "taboo";
const char* Taboo::ITEM_TAG = "item";
const char* Taboo::NAME_TAG = "name";
@ -66,11 +64,11 @@ std::string Taboo::ReplaceCountryName(const std::string& region, const std::stri
const std::string& name)
{
if (!isTabooDataExist) {
HiLog::Info(LABEL, "Taboo::ReplaceCountryName Taboo data not exist.");
HILOG_INFO_I18N("Taboo::ReplaceCountryName Taboo data not exist.");
return name;
}
if (supportedRegions.find(region) == supportedRegions.end()) {
HiLog::Info(LABEL, "Taboo::ReplaceCountryName taboo data don't support region %{public}s", region.c_str());
HILOG_INFO_I18N("Taboo::ReplaceCountryName taboo data don't support region %{public}s", region.c_str());
return name;
}
std::string key = regionKey + region;
@ -79,7 +77,7 @@ std::string Taboo::ReplaceCountryName(const std::string& region, const std::stri
std::string fileName;
std::tie(fallbackLanguage, fileName) = LanguageFallBack(displayLanguage);
if (fallbackLanguage.length() == 0) {
HiLog::Info(LABEL, "Taboo::ReplaceCountryName language %{public}s fallback failed", displayLanguage.c_str());
HILOG_INFO_I18N("Taboo::ReplaceCountryName language %{public}s fallback failed", displayLanguage.c_str());
return name;
}
if (localeTabooData.find(fallbackLanguage) == localeTabooData.end()) {
@ -93,7 +91,7 @@ std::string Taboo::ReplaceCountryName(const std::string& region, const std::stri
return tabooData[*it];
}
}
HiLog::Info(LABEL, "Taboo::ReplaceCountryName not find taboo data correspond to region %{public}s",
HILOG_INFO_I18N("Taboo::ReplaceCountryName not find taboo data correspond to region %{public}s",
region.c_str());
return name;
}
@ -102,11 +100,11 @@ std::string Taboo::ReplaceLanguageName(const std::string& language, const std::s
const std::string& name)
{
if (!isTabooDataExist) {
HiLog::Info(LABEL, "Taboo::ReplaceLanguageName Taboo data not exist.");
HILOG_INFO_I18N("Taboo::ReplaceLanguageName Taboo data not exist.");
return name;
}
if (supportedLanguages.find(language) == supportedLanguages.end()) {
HiLog::Error(LABEL, "Taboo::ReplaceLanguageName taboo data don't support language %{public}s",
HILOG_ERROR_I18N("Taboo::ReplaceLanguageName taboo data don't support language %{public}s",
language.c_str());
return name;
}
@ -116,7 +114,7 @@ std::string Taboo::ReplaceLanguageName(const std::string& language, const std::s
std::string fileName;
std::tie(fallbackLanguage, fileName) = LanguageFallBack(displayLanguage);
if (fallbackLanguage.size() == 0) {
HiLog::Error(LABEL, "Taboo::ReplaceLanguageName language %{public}s fallback failed", displayLanguage.c_str());
HILOG_ERROR_I18N("Taboo::ReplaceLanguageName language %{public}s fallback failed", displayLanguage.c_str());
return name;
}
if (localeTabooData.find(fallbackLanguage) == localeTabooData.end()) {
@ -130,7 +128,7 @@ std::string Taboo::ReplaceLanguageName(const std::string& language, const std::s
return tabooData[*it];
}
}
HiLog::Error(LABEL, "Taboo::ReplaceLanguageName not find taboo data correspond to language %{public}s",
HILOG_ERROR_I18N("Taboo::ReplaceLanguageName not find taboo data correspond to language %{public}s",
language.c_str());
return name;
}
@ -140,13 +138,13 @@ void Taboo::ParseTabooData(const std::string& path, DataFileType fileType, const
xmlKeepBlanksDefault(0);
xmlDocPtr doc = xmlParseFile(path.c_str());
if (doc == nullptr) {
HiLog::Error(LABEL, "Taboo parse taboo data file failed: %{public}s", path.c_str());
HILOG_ERROR_I18N("Taboo parse taboo data file failed: %{public}s", path.c_str());
return;
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (cur == nullptr || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar*>(ROOT_TAG)) != 0) {
xmlFreeDoc(doc);
HiLog::Error(LABEL, "Taboo get root tag from taboo data file failed: %{public}s", path.c_str());
HILOG_ERROR_I18N("Taboo get root tag from taboo data file failed: %{public}s", path.c_str());
return;
}
cur = cur->xmlChildrenNode;
@ -156,7 +154,7 @@ void Taboo::ParseTabooData(const std::string& path, DataFileType fileType, const
xmlChar* name = xmlGetProp(cur, nameTag);
xmlChar* value = xmlGetProp(cur, valueTag);
if (name == nullptr || value == nullptr) {
HiLog::Error(LABEL, "Taboo get name and value property failed: %{public}s", path.c_str());
HILOG_ERROR_I18N("Taboo get name and value property failed: %{public}s", path.c_str());
cur = cur->next;
continue;
}
@ -247,7 +245,7 @@ void Taboo::ReadResourceList()
for (const auto &dirEntry : directory_iterator{tabooDataPath}) {
std::string path = dirEntry.path();
if (stat(path.c_str(), &s) != 0) {
HiLog::Error(LABEL, "get path status failed");
HILOG_ERROR_I18N("get path status failed");
continue;
}
if (s.st_mode & S_IFDIR) {

View File

@ -22,7 +22,7 @@
#include <unistd.h>
#include <vector>
#include "accesstoken_kit.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "nativetoken_kit.h"
#include "parameter.h"
#include "token_setproc.h"
@ -32,8 +32,6 @@ namespace OHOS {
namespace Global {
namespace I18n {
using namespace std;
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "Utils" };
using namespace OHOS::HiviewDFX;
static constexpr int32_t I18N_UID = 3013;
static constexpr int32_t ROOT_UID = 0;
@ -77,7 +75,7 @@ int32_t ConvertString2Int(const string &numberStr, int32_t& status)
return -1;
} catch (...) {
status = -1;
HiLog::Error(LABEL, "ConvertString2Int: unknow error. numberStr: %{public}s.", numberStr.c_str());
HILOG_ERROR_I18N("ConvertString2Int: unknow error. numberStr: %{public}s.", numberStr.c_str());
return -1;
}
} else {
@ -92,7 +90,7 @@ bool IsValidLocaleTag(icu::Locale &locale)
GetAllValidLocalesTag(allValidLocalesLanguageTag);
std::string languageTag = locale.getLanguage();
if (allValidLocalesLanguageTag.find(languageTag) == allValidLocalesLanguageTag.end()) {
HiLog::Error(LABEL, "GetTimePeriodName does not support this languageTag: %{public}s", languageTag.c_str());
HILOG_ERROR_I18N("GetTimePeriodName does not support this languageTag: %{public}s", languageTag.c_str());
return false;
}
return true;

View File

@ -15,7 +15,7 @@
#include <filesystem>
#include <sys/stat.h>
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_timezone.h"
#include "ohos/init_data.h"
#include "unicode/strenum.h"
@ -27,8 +27,6 @@ using namespace OHOS::Global::I18n;
using namespace icu;
using namespace std;
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "ZoneUtil" };
using namespace OHOS::HiviewDFX;
const char *ZoneUtil::COUNTRY_ZONE_DATA_PATH = "/system/usr/ohos_timezone/tzlookup.xml";
const char *ZoneUtil::DEFAULT_TIMEZONE = "GMT";
const char *ZoneUtil::TIMEZONES_TAG = "timezones";
@ -244,10 +242,10 @@ CountryResult ZoneUtil::LookupTimezoneByCountryAndNITZ(std::string &region, NITZ
}
if (CheckFileExist()) {
bool isBoosted = false;
HiLog::Info(LABEL, "ZoneUtil::LookupTimezoneByCountryAndNITZ use tzlookup.xml");
HILOG_INFO_I18N("ZoneUtil::LookupTimezoneByCountryAndNITZ use tzlookup.xml");
GetCountryZones(region, defaultTimezone, isBoosted, zones);
} else {
HiLog::Info(LABEL, "ZoneUtil::LookupTimezoneByCountryAndNITZ use icu data");
HILOG_INFO_I18N("ZoneUtil::LookupTimezoneByCountryAndNITZ use icu data");
GetICUCountryZones(region, zones, defaultTimezone);
}
return Match(zones, nitzData, systemTimezone);
@ -262,7 +260,7 @@ CountryResult ZoneUtil::LookupTimezoneByNITZ(NITZData &nitzData)
I18nErrorCode status = I18nErrorCode::SUCCESS;
std::set<std::string> icuTimezones = I18nTimeZone::GetAvailableIDs(status);
if (status != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "ZoneUtil::LookupTimezoneByNITZ can not get icu data");
HILOG_ERROR_I18N("ZoneUtil::LookupTimezoneByNITZ can not get icu data");
}
std::vector<std::string> validZones;
for (auto it = icuTimezones.begin(); it != icuTimezones.end(); ++it) {
@ -284,14 +282,14 @@ CountryResult ZoneUtil::LookupTimezoneByCountry(std::string &region, int64_t cur
std::string defaultTimezone;
CountryResult result = { true, MatchQuality::DEFAULT_BOOSTED, defaultTimezone };
if (CheckFileExist()) {
HiLog::Info(LABEL, "ZoneUtil::LookupTimezoneByCountry use tzlookup.xml");
HILOG_INFO_I18N("ZoneUtil::LookupTimezoneByCountry use tzlookup.xml");
GetCountryZones(region, defaultTimezone, isBoosted, zones);
if (defaultTimezone.length() == 0) {
HiLog::Error(LABEL, "ZoneUtil::LookupTimezoneByCountry can't find default timezone for region %{public}s",
HILOG_ERROR_I18N("ZoneUtil::LookupTimezoneByCountry can't find default timezone for region %{public}s",
region.c_str());
}
} else {
HiLog::Info(LABEL, "ZoneUtil::LookupTimezoneByCountry use icu data");
HILOG_INFO_I18N("ZoneUtil::LookupTimezoneByCountry use icu data");
GetICUCountryZones(region, zones, defaultTimezone);
}
result.timezoneId = defaultTimezone;
@ -327,13 +325,13 @@ void ZoneUtil::GetCountryZones(std::string &region, std::string &defaultTimzone,
xmlKeepBlanksDefault(0);
xmlDocPtr doc = xmlParseFile(COUNTRY_ZONE_DATA_PATH);
if (!doc) {
HiLog::Error(LABEL, "ZoneUtil::GetCountryZones can not open tzlookup.xml");
HILOG_ERROR_I18N("ZoneUtil::GetCountryZones can not open tzlookup.xml");
return;
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (!cur || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(ROOT_TAG)) != 0) {
xmlFreeDoc(doc);
HiLog::Error(LABEL, "ZoneUtil::GetCountryZones invalid Root_tag");
HILOG_ERROR_I18N("ZoneUtil::GetCountryZones invalid Root_tag");
return;
}
cur = cur->xmlChildrenNode;
@ -342,7 +340,7 @@ void ZoneUtil::GetCountryZones(std::string &region, std::string &defaultTimzone,
while (cur != nullptr && xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(SECOND_TAG)) == 0) {
value = cur->xmlChildrenNode;
if (xmlStrcmp(value->name, reinterpret_cast<const xmlChar*>(CODE_TAG)) != 0) {
HiLog::Error(LABEL, "ZoneUtil::GetCountryZones invalid code_tag");
HILOG_ERROR_I18N("ZoneUtil::GetCountryZones invalid code_tag");
return;
}
xmlChar *codePtr = xmlNodeGetContent(value);
@ -368,7 +366,7 @@ void ZoneUtil::GetDefaultAndBoost(xmlNodePtr &value, std::string &defaultTimezon
std::vector<std::string> &zones)
{
if (value == nullptr || xmlStrcmp(value->name, reinterpret_cast<const xmlChar*>(DEFAULT_TAG)) != 0) {
HiLog::Error(LABEL, "ZoneUtil::GetDefaultAndBoost invalid default_tag");
HILOG_ERROR_I18N("ZoneUtil::GetDefaultAndBoost invalid default_tag");
return;
}
xmlChar *defaultPtr = xmlNodeGetContent(value);
@ -376,7 +374,7 @@ void ZoneUtil::GetDefaultAndBoost(xmlNodePtr &value, std::string &defaultTimezon
xmlFree(defaultPtr);
value = value->next;
if (value == nullptr) {
HiLog::Error(LABEL, "ZoneUtil::GetDefaultAndBoost doesn't contains id");
HILOG_ERROR_I18N("ZoneUtil::GetDefaultAndBoost doesn't contains id");
return;
}
if (xmlStrcmp(value->name, reinterpret_cast<const xmlChar *>(BOOSTED_TAG)) == 0) {
@ -391,13 +389,13 @@ void ZoneUtil::GetDefaultAndBoost(xmlNodePtr &value, std::string &defaultTimezon
void ZoneUtil::GetTimezones(xmlNodePtr &value, std::vector<std::string> &zones)
{
if (xmlStrcmp(value->name, reinterpret_cast<const xmlChar *>(TIMEZONES_TAG)) != 0) {
HiLog::Error(LABEL, "ZoneUtil::GetTimezones invalid timezones_tag");
HILOG_ERROR_I18N("ZoneUtil::GetTimezones invalid timezones_tag");
return;
}
value = value->xmlChildrenNode;
while (value != nullptr) {
if (xmlStrcmp(value->name, reinterpret_cast<const xmlChar *>(ID_TAG)) != 0) {
HiLog::Error(LABEL, "ZoneUtil::GetTimezones invalid id_tag");
HILOG_ERROR_I18N("ZoneUtil::GetTimezones invalid id_tag");
return;
}
xmlChar *idPtr = xmlNodeGetContent(value);
@ -412,7 +410,7 @@ void ZoneUtil::GetICUCountryZones(std::string &region, std::vector<std::string>
I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
std::set<std::string> validZoneIds = I18nTimeZone::GetAvailableIDs(errorCode);
if (errorCode != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "ZoneUtil::GetICUCountryZones can not get icu data");
HILOG_ERROR_I18N("ZoneUtil::GetICUCountryZones can not get icu data");
}
std::set<std::string> countryZoneIds;
StringEnumeration *strEnum = TimeZone::createEnumeration(region.c_str());
@ -485,7 +483,7 @@ bool ZoneUtil::CheckSameDstOffset(std::vector<std::string> &zones, std::string &
UErrorCode status = U_ZERO_ERROR;
defaultTimezone->getOffset(currentMillis, (UBool)local, rawOffset, dstOffset, status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "ZoneUtil::CheckSameDstOffset can not get timezone defaultID offset");
HILOG_ERROR_I18N("ZoneUtil::CheckSameDstOffset can not get timezone defaultID offset");
return false;
}
int32_t totalOffset = rawOffset + dstOffset;
@ -494,7 +492,7 @@ bool ZoneUtil::CheckSameDstOffset(std::vector<std::string> &zones, std::string &
TimeZone *timezone = TimeZone::createTimeZone(unicodeZoneID);
timezone->getOffset(currentMillis, (UBool)local, rawOffset, dstOffset, status);
if (U_FAILURE(status)) {
HiLog::Error(LABEL, "ZoneUtil::CheckSameDstOffset can not get timezone unicodeZoneID offset");
HILOG_ERROR_I18N("ZoneUtil::CheckSameDstOffset can not get timezone unicodeZoneID offset");
return false;
}
if (totalOffset - rawOffset != dstOffset) {

View File

@ -15,7 +15,7 @@
#include <unicode/locid.h>
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "utils.h"
#include "variable_convertor.h"
#include "entity_recognizer_addon.h"
@ -23,9 +23,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "EntityRecognizerAddonJs" };
using namespace OHOS::HiviewDFX;
EntityRecognizerAddon::EntityRecognizerAddon() {}
EntityRecognizerAddon::~EntityRecognizerAddon()
@ -50,12 +47,12 @@ napi_value EntityRecognizerAddon::InitEntityRecognizer(napi_env env, napi_value
napi_status status = napi_define_class(env, "EntityRecognizer", NAPI_AUTO_LENGTH, constructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &entityConstructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to define class EntityRecognizer at Init.");
HILOG_ERROR_I18N("Failed to define class EntityRecognizer at Init.");
return nullptr;
}
status = napi_set_named_property(env, exports, "EntityRecognizer", entityConstructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitEntityRecognizer");
HILOG_ERROR_I18N("Set property failed when InitEntityRecognizer");
return nullptr;
}
return exports;
@ -123,7 +120,7 @@ napi_value EntityRecognizerAddon::FindEntityInfo(napi_env env, napi_callback_inf
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_string) {
HiLog::Error(LABEL, "Invalid parameter type");
HILOG_ERROR_I18N("Invalid parameter type");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
@ -135,7 +132,7 @@ napi_value EntityRecognizerAddon::FindEntityInfo(napi_env env, napi_callback_inf
EntityRecognizerAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || obj == nullptr || obj->entityRecognizer_ == nullptr) {
HiLog::Error(LABEL, "Get EntityRecognizer object failed");
HILOG_ERROR_I18N("Get EntityRecognizer object failed");
return nullptr;
}
std::vector<std::vector<int>> entityInfo = obj->entityRecognizer_->FindEntityInfo(message);
@ -148,7 +145,7 @@ napi_value EntityRecognizerAddon::GetEntityInfoItem(napi_env env, std::vector<st
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, entityInfo[0][0] + entityInfo[1][0], &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create EntityInfo array failed.");
HILOG_ERROR_I18N("create EntityInfo array failed.");
return nullptr;
}
std::vector<std::string> types = {"phone_number", "date"};
@ -162,7 +159,7 @@ napi_value EntityRecognizerAddon::GetEntityInfoItem(napi_env env, std::vector<st
status = napi_set_element(env, result, index, item);
index++;
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set item element.");
HILOG_ERROR_I18N("Failed to set item element.");
return nullptr;
}
}
@ -176,25 +173,25 @@ napi_value EntityRecognizerAddon::CreateEntityInfoItem(napi_env env, const int b
napi_value result;
napi_status status = napi_create_object(env, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create EntityInfoItem object failed.");
HILOG_ERROR_I18N("Create EntityInfoItem object failed.");
return nullptr;
}
status = napi_set_named_property(env, result, "begin",
VariableConvertor::CreateNumber(env, begin));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element begin.");
HILOG_ERROR_I18N("Failed to set element begin.");
return nullptr;
}
status = napi_set_named_property(env, result, "end",
VariableConvertor::CreateNumber(env, end));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element end.");
HILOG_ERROR_I18N("Failed to set element end.");
return nullptr;
}
status = napi_set_named_property(env, result, "type",
VariableConvertor::CreateString(env, type));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element type.");
HILOG_ERROR_I18N("Failed to set element type.");
return nullptr;
}
return result;

View File

@ -15,7 +15,7 @@
#include <vector>
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "locale_config.h"
#include "variable_convertor.h"
#include "holiday_manager_addon.h"
@ -23,9 +23,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "HolidayManagerJs" };
using namespace OHOS::HiviewDFX;
HolidayManagerAddon::HolidayManagerAddon() : env_(nullptr) {}
HolidayManagerAddon::~HolidayManagerAddon()
@ -53,13 +50,13 @@ napi_value HolidayManagerAddon::InitHolidayManager(napi_env env, napi_value expo
status = napi_define_class(env, "HolidayManager", NAPI_AUTO_LENGTH, HolidayManagerConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitHolidayManager");
HILOG_ERROR_I18N("Define class failed when InitHolidayManager");
return nullptr;
}
status = napi_set_named_property(env, exports, "HolidayManager", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitHolidayManager");
HILOG_ERROR_I18N("Set property failed when InitHolidayManager");
return nullptr;
}
return exports;
@ -85,7 +82,7 @@ napi_value HolidayManagerAddon::HolidayManagerConstructor(napi_env env, napi_cal
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), HolidayManagerAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "Wrap HolidayManagerAddon failed");
HILOG_ERROR_I18N("Wrap HolidayManagerAddon failed");
return nullptr;
}
int32_t code = 0;
@ -94,7 +91,7 @@ napi_value HolidayManagerAddon::HolidayManagerConstructor(napi_env env, napi_cal
return nullptr;
}
if (!obj->InitHolidayManagerContext(env, info, path.c_str())) {
HiLog::Error(LABEL, "Init HolidayManager failed");
HILOG_ERROR_I18N("Init HolidayManager failed");
return nullptr;
}
obj.release();
@ -106,7 +103,7 @@ bool HolidayManagerAddon::InitHolidayManagerContext(napi_env env, napi_callback_
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get global failed");
HILOG_ERROR_I18N("Get global failed");
return false;
}
env_ = env;
@ -119,14 +116,14 @@ std::string HolidayManagerAddon::GetString(napi_env &env, napi_value &value, int
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, value, nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get string failed");
HILOG_ERROR_I18N("Get string failed");
code = 1;
return "";
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, value, buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create string failed");
HILOG_ERROR_I18N("Create string failed");
code = 1;
return "";
}
@ -145,7 +142,7 @@ napi_value HolidayManagerAddon::IsHoliday(napi_env env, napi_callback_info info)
HolidayManagerAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->holidayManager_) {
HiLog::Error(LABEL, "IsHoliday: Get HolidayManager object failed");
HILOG_ERROR_I18N("IsHoliday: Get HolidayManager object failed");
return nullptr;
}
napi_value result = nullptr;
@ -177,7 +174,7 @@ napi_value HolidayManagerAddon::GetHolidayInfoItemArray(napi_env env, napi_callb
HolidayManagerAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->holidayManager_) {
HiLog::Error(LABEL, "GetHolidayInfoItemArray: Get HolidayManager object failed");
HILOG_ERROR_I18N("GetHolidayInfoItemArray: Get HolidayManager object failed");
return nullptr;
}
bool flag = VariableConvertor::CheckNapiValueType(env, argv[0]);
@ -196,14 +193,14 @@ napi_value HolidayManagerAddon::GetHolidayInfoItemResult(napi_env env, std::vect
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, itemList.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create HolidayInfoItem array failed.");
HILOG_ERROR_I18N("create HolidayInfoItem array failed.");
return nullptr;
}
for (size_t i = 0; i < itemList.size(); i++) {
napi_value item = CreateHolidayItem(env, itemList[i]);
status = napi_set_element(env, result, i, item);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set HolidayInfoItem element.");
HILOG_ERROR_I18N("Failed to set HolidayInfoItem element.");
return nullptr;
}
}
@ -234,19 +231,19 @@ int HolidayManagerAddon::GetDateValue(napi_env env, napi_value value, const std:
napi_value funcGetDateInfo = nullptr;
napi_status status = napi_get_named_property(env, value, method.c_str(), &funcGetDateInfo);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get method %{public}s failed", method.c_str());
HILOG_ERROR_I18N("Get method %{public}s failed", method.c_str());
return val;
}
napi_value ret_value = nullptr;
status = napi_call_function(env, value, funcGetDateInfo, 0, nullptr, &ret_value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get milliseconds failed");
HILOG_ERROR_I18N("Get milliseconds failed");
return val;
}
status = napi_get_value_int32(env, ret_value, &val);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDateValue: Retrieve field failed");
HILOG_ERROR_I18N("GetDateValue: Retrieve field failed");
return val;
}
return val;
@ -263,7 +260,7 @@ int32_t HolidayManagerAddon::ValidateParamNumber(napi_env &env, napi_value &argv
int32_t val = 0;
napi_status status = napi_get_value_int32(env, argv, &val);
if (status != napi_ok) {
HiLog::Error(LABEL, "ValidateParamNumber: Retrieve field failed");
HILOG_ERROR_I18N("ValidateParamNumber: Retrieve field failed");
return -1;
}
return val;
@ -274,38 +271,38 @@ napi_value HolidayManagerAddon::CreateHolidayItem(napi_env env, const HolidayInf
napi_value result;
napi_status status = napi_create_object(env, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create Holiday Item object failed.");
HILOG_ERROR_I18N("Create Holiday Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, result, "baseName",
VariableConvertor::CreateString(env, holidayItem.baseName));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element baseName.");
HILOG_ERROR_I18N("Failed to set element baseName.");
return nullptr;
}
status = napi_set_named_property(env, result, "year",
VariableConvertor::CreateNumber(env, holidayItem.year));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element year.");
HILOG_ERROR_I18N("Failed to set element year.");
return nullptr;
}
status = napi_set_named_property(env, result, "month",
VariableConvertor::CreateNumber(env, holidayItem.month));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element month.");
HILOG_ERROR_I18N("Failed to set element month.");
return nullptr;
}
status = napi_set_named_property(env, result, "day",
VariableConvertor::CreateNumber(env, holidayItem.day));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element day.");
HILOG_ERROR_I18N("Failed to set element day.");
return nullptr;
}
napi_value localNames = HolidayLocalNameItem(env, holidayItem.localNames);
if (localNames != nullptr) {
status = napi_set_named_property(env, result, "localNames", localNames);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element localNames.");
HILOG_ERROR_I18N("Failed to set element localNames.");
return nullptr;
}
}
@ -317,31 +314,31 @@ napi_value HolidayManagerAddon::HolidayLocalNameItem(napi_env env, const std::ve
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, localNames.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create HolidayLocalName array failed.");
HILOG_ERROR_I18N("create HolidayLocalName array failed.");
return nullptr;
}
for (size_t i = 0; i < localNames.size(); i++) {
napi_value localNameItem;
status = napi_create_object(env, &localNameItem);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create HolidayLocalName Item object failed.");
HILOG_ERROR_I18N("Create HolidayLocalName Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, localNameItem, "language",
VariableConvertor::CreateString(env, localNames[i].language));
if (status != napi_ok) {
HiLog::Error(LABEL, "Create HolidayLocalName.language Item object failed.");
HILOG_ERROR_I18N("Create HolidayLocalName.language Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, localNameItem, "name",
VariableConvertor::CreateString(env, localNames[i].name));
if (status != napi_ok) {
HiLog::Error(LABEL, "Create HolidayLocalName.name Item object failed.");
HILOG_ERROR_I18N("Create HolidayLocalName.name Item object failed.");
return nullptr;
}
status = napi_set_element(env, result, i, localNameItem);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set HolidayLocalName element.");
HILOG_ERROR_I18N("Failed to set HolidayLocalName element.");
return nullptr;
}
}

View File

@ -16,7 +16,7 @@
#include <vector>
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "holiday_manager_addon.h"
#include "entity_recognizer_addon.h"
#include "i18n_calendar_addon.h"
@ -40,9 +40,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nJs" };
using namespace OHOS::HiviewDFX;
static thread_local napi_ref* g_brkConstructor = nullptr;
static thread_local napi_ref g_indexUtilConstructor = nullptr;
static thread_local napi_ref* g_transConstructor = nullptr;
@ -75,13 +72,13 @@ napi_value I18nAddon::InitI18nUtil(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "I18NUtil", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nUtil: Define class failed when InitI18NUtil.");
HILOG_ERROR_I18N("InitI18nUtil: Define class failed when InitI18NUtil.");
return nullptr;
}
status = napi_set_named_property(env, exports, "I18NUtil", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nUtil: Set property failed when InitI18NUtil.");
HILOG_ERROR_I18N("InitI18nUtil: Set property failed when InitI18NUtil.");
return nullptr;
}
return exports;
@ -112,7 +109,7 @@ napi_value I18nAddon::Init(napi_env env, napi_value exports)
initStatus = napi_define_properties(env, exports, sizeof(properties) / sizeof(napi_property_descriptor),
properties);
if (initStatus != napi_ok) {
HiLog::Error(LABEL, "Failed to set properties at init");
HILOG_ERROR_I18N("Failed to set properties at init");
return nullptr;
}
return exports;
@ -126,7 +123,7 @@ void GetOptionMap(napi_env env, napi_value option, std::map<std::string, std::st
std::vector<char> styleBuf(len + 1);
napi_status status = napi_get_value_string_utf8(env, option, styleBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetOptionMap: Failed to get string item");
HILOG_ERROR_I18N("GetOptionMap: Failed to get string item");
return;
}
map.insert(std::make_pair("unitDisplay", styleBuf.data()));
@ -179,7 +176,7 @@ napi_value I18nAddon::UnitConvert(napi_env env, napi_callback_info info)
napi_value result;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "UnitConvert: Failed to create string item");
HILOG_ERROR_I18N("UnitConvert: Failed to create string item");
return nullptr;
}
return result;
@ -200,19 +197,19 @@ napi_value I18nAddon::GetDateOrder(napi_env env, napi_callback_info info)
std::vector<char> languageBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], languageBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to get locale string for GetDateOrder");
HILOG_ERROR_I18N("Failed to get locale string for GetDateOrder");
return nullptr;
}
UErrorCode icuStatus = U_ZERO_ERROR;
icu::Locale locale = icu::Locale::forLanguageTag(languageBuf.data(), icuStatus);
if (icuStatus != U_ZERO_ERROR) {
HiLog::Error(LABEL, "Failed to create locale for GetDateOrder");
HILOG_ERROR_I18N("Failed to create locale for GetDateOrder");
return nullptr;
}
icu::SimpleDateFormat* formatter = dynamic_cast<icu::SimpleDateFormat*>
(icu::DateFormat::createDateInstance(icu::DateFormat::EStyle::kDefault, locale));
if (icuStatus != U_ZERO_ERROR || formatter == nullptr) {
HiLog::Error(LABEL, "Failed to create SimpleDateFormat");
HILOG_ERROR_I18N("Failed to create SimpleDateFormat");
return nullptr;
}
std::string tempValue;
@ -224,7 +221,7 @@ napi_value I18nAddon::GetDateOrder(napi_env env, napi_callback_info info)
napi_value result;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDateOrder Failed to create string item");
HILOG_ERROR_I18N("GetDateOrder Failed to create string item");
return nullptr;
}
return result;
@ -271,7 +268,7 @@ napi_value I18nAddon::GetTimePeriodName(napi_env env, napi_callback_info info)
int32_t hour;
std::string localeTag;
if (GetParamOfGetTimePeriodName(env, info, localeTag, hour) == -1) {
HiLog::Error(LABEL, "GetTimePeriodName param error");
HILOG_ERROR_I18N("GetTimePeriodName param error");
napi_create_string_utf8(env, "", NAPI_AUTO_LENGTH, &result);
return result;
}
@ -279,13 +276,13 @@ napi_value I18nAddon::GetTimePeriodName(napi_env env, napi_callback_info info)
UErrorCode icuStatus = U_ZERO_ERROR;
icu::Locale locale = icu::Locale::forLanguageTag(localeTag.data(), icuStatus);
if (U_FAILURE(icuStatus) || !IsValidLocaleTag(locale)) {
HiLog::Error(LABEL, "GetTimePeriodName does not support this locale");
HILOG_ERROR_I18N("GetTimePeriodName does not support this locale");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
}
icu::SimpleDateFormat* formatter = dynamic_cast<icu::SimpleDateFormat*>
(icu::DateFormat::createDateInstance(icu::DateFormat::EStyle::kDefault, locale));
if (!formatter) {
HiLog::Error(LABEL, "GetTimePeriodName Failed to create SimpleDateFormat");
HILOG_ERROR_I18N("GetTimePeriodName Failed to create SimpleDateFormat");
napi_create_string_utf8(env, "", NAPI_AUTO_LENGTH, &result);
return result;
}
@ -311,19 +308,19 @@ int I18nAddon::GetParamOfGetTimePeriodName(napi_env env, napi_callback_info info
void *data = nullptr;
napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetTimePeriodName can't get parameters from getTimePerioudName.");
HILOG_ERROR_I18N("GetTimePeriodName can't get parameters from getTimePerioudName.");
return -1;
}
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_number) {
HiLog::Error(LABEL, "GetTimePeriodName Parameter type does not match argv[0]");
HILOG_ERROR_I18N("GetTimePeriodName Parameter type does not match argv[0]");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
}
status = napi_get_value_int32(env, argv[0], &hour);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetTimePeriodName can't get number from js param");
HILOG_ERROR_I18N("GetTimePeriodName can't get number from js param");
return -1;
}
@ -335,11 +332,11 @@ int I18nAddon::GetParamOfGetTimePeriodName(napi_env env, napi_callback_info info
int code = 0;
tag = VariableConvertor::GetString(env, argv[1], code);
if (code) {
HiLog::Error(LABEL, "GetTimePeriodName can't get string from js param");
HILOG_ERROR_I18N("GetTimePeriodName can't get string from js param");
return -1;
}
} else {
HiLog::Error(LABEL, "GetTimePeriodName Parameter type does not match argv[1]");
HILOG_ERROR_I18N("GetTimePeriodName Parameter type does not match argv[1]");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
}
return 0;
@ -350,14 +347,14 @@ LocaleInfo* ProcessJsParamLocale(napi_env env, napi_value argv)
int32_t code = 0;
std::string localeTag = VariableConvertor::GetString(env, argv, code);
if (code != 0) {
HiLog::Error(LABEL, "GetBestMatchLocale get param locale failed.");
HILOG_ERROR_I18N("GetBestMatchLocale get param locale failed.");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
UErrorCode icuStatus = U_ZERO_ERROR;
icu::Locale locale = icu::Locale::forLanguageTag(localeTag.data(), icuStatus);
if (U_FAILURE(icuStatus) || !IsValidLocaleTag(locale)) {
HiLog::Error(LABEL, "GetBestMatchLocale param locale Invalid.");
HILOG_ERROR_I18N("GetBestMatchLocale param locale Invalid.");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return nullptr;
}
@ -369,7 +366,7 @@ bool ProcessJsParamLocaleList(napi_env env, napi_value argv, std::vector<LocaleI
{
std::vector<std::string> localeTagList;
if (!VariableConvertor::GetStringArrayFromJsParam(env, argv, localeTagList)) {
HiLog::Error(LABEL, "GetBestMatchLocale get param localeList failed.");
HILOG_ERROR_I18N("GetBestMatchLocale get param localeList failed.");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return false;
}
@ -380,7 +377,7 @@ bool ProcessJsParamLocaleList(napi_env env, napi_value argv, std::vector<LocaleI
UErrorCode icuStatus = U_ZERO_ERROR;
icu::Locale locale = icu::Locale::forLanguageTag(it->data(), icuStatus);
if (U_FAILURE(icuStatus) || !IsValidLocaleTag(locale)) {
HiLog::Error(LABEL, "GetBestMatchLocale param localeList Invalid: %{public}s.", it->data());
HILOG_ERROR_I18N("GetBestMatchLocale param localeList Invalid: %{public}s.", it->data());
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return false;
}
@ -432,7 +429,7 @@ napi_value I18nAddon::GetBestMatchLocale(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, bestMatchLocaleTag.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create format stirng failed.");
HILOG_ERROR_I18N("Create format stirng failed.");
return nullptr;
}
return result;
@ -478,18 +475,18 @@ napi_value I18nAddon::InitI18nTransliterator(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "Transliterator", NAPI_AUTO_LENGTH, I18nTransliteratorConstructor,
nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nTransliterator: Failed to define transliterator class at Init");
HILOG_ERROR_I18N("InitI18nTransliterator: Failed to define transliterator class at Init");
return nullptr;
}
exports = I18nAddon::InitTransliterator(env, exports);
g_transConstructor = new (std::nothrow) napi_ref;
if (!g_transConstructor) {
HiLog::Error(LABEL, "InitI18nTransliterator: Failed to create trans ref at init");
HILOG_ERROR_I18N("InitI18nTransliterator: Failed to create trans ref at init");
return nullptr;
}
status = napi_create_reference(env, constructor, 1, g_transConstructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nTransliterator: Failed to create trans reference at init");
HILOG_ERROR_I18N("InitI18nTransliterator: Failed to create trans reference at init");
return nullptr;
}
return exports;
@ -505,12 +502,12 @@ napi_value I18nAddon::InitTransliterator(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "I18nTransliterator", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor,
nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitTransliterator: Failed to define class Transliterator.");
HILOG_ERROR_I18N("InitTransliterator: Failed to define class Transliterator.");
return nullptr;
}
status = napi_set_named_property(env, exports, "Transliterator", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitTransliterator: Set property failed When InitTransliterator.");
HILOG_ERROR_I18N("InitTransliterator: Set property failed When InitTransliterator.");
return nullptr;
}
return exports;
@ -542,7 +539,7 @@ napi_value I18nAddon::I18nTransliteratorConstructor(napi_env env, napi_callback_
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), I18nAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "I18nTransliteratorConstructor: TransliteratorConstructor: Wrap II18nAddon failed");
HILOG_ERROR_I18N("I18nTransliteratorConstructor: TransliteratorConstructor: Wrap II18nAddon failed");
return nullptr;
}
if (!obj->InitTransliteratorContext(env, info, idTag)) {
@ -575,7 +572,7 @@ napi_value I18nAddon::Transform(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->transliterator_) {
HiLog::Error(LABEL, "Get Transliterator object failed");
HILOG_ERROR_I18N("Get Transliterator object failed");
return nullptr;
}
if (!argv[0]) {
@ -590,13 +587,13 @@ napi_value I18nAddon::Transform(napi_env env, napi_callback_info info)
size_t len = 0;
status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Transform: Get field length failed napi_get_value_string_utf8");
HILOG_ERROR_I18N("Transform: Get field length failed napi_get_value_string_utf8");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Transform: Get string value failed");
HILOG_ERROR_I18N("Transform: Get string value failed");
return nullptr;
}
icu::UnicodeString unistr = icu::UnicodeString::fromUTF8(buf.data());
@ -606,7 +603,7 @@ napi_value I18nAddon::Transform(napi_env env, napi_callback_info info)
napi_value value;
status = napi_create_string_utf8(env, temp.c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Transform: Get field length failed napi_create_string_utf8");
HILOG_ERROR_I18N("Transform: Get field length failed napi_create_string_utf8");
return nullptr;
}
return value;
@ -625,7 +622,7 @@ napi_value I18nAddon::GetAvailableIDs(napi_env env, napi_callback_info info)
UErrorCode icuStatus = U_ZERO_ERROR;
icu::StringEnumeration *strenum = icu::Transliterator::getAvailableIDs(icuStatus);
if (icuStatus != U_ZERO_ERROR) {
HiLog::Error(LABEL, "Failed to get available ids");
HILOG_ERROR_I18N("Failed to get available ids");
if (strenum) {
delete strenum;
}
@ -662,13 +659,13 @@ napi_value I18nAddon::GetTransliteratorInstance(napi_env env, napi_callback_info
napi_value constructor = nullptr;
napi_status status = napi_get_reference_value(env, *g_transConstructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference at GetCalendar");
HILOG_ERROR_I18N("Failed to create reference at GetCalendar");
return nullptr;
}
napi_value result = nullptr;
status = napi_new_instance(env, constructor, 1, argv, &result); // 2 arguments
if (status != napi_ok) {
HiLog::Error(LABEL, "Get Transliterator create instance failed");
HILOG_ERROR_I18N("Get Transliterator create instance failed");
return nullptr;
}
return result;
@ -689,14 +686,14 @@ napi_value I18nAddon::IsRTL(napi_env env, napi_callback_info info)
std::vector<char> localeBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], localeBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsRTL: Failed to get string item");
HILOG_ERROR_I18N("IsRTL: Failed to get string item");
return nullptr;
}
bool isRTL = LocaleConfig::IsRTL(localeBuf.data());
napi_value result = nullptr;
status = napi_get_boolean(env, isRTL, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsRTL failed");
HILOG_ERROR_I18N("IsRTL failed");
return nullptr;
}
return result;
@ -715,13 +712,13 @@ napi_value I18nAddon::InitPhoneNumberFormat(napi_env env, napi_value exports)
status = napi_define_class(env, "PhoneNumberFormat", NAPI_AUTO_LENGTH, PhoneNumberFormatConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitPhoneNumberFormat: Define class failed when InitPhoneNumberFormat");
HILOG_ERROR_I18N("InitPhoneNumberFormat: Define class failed when InitPhoneNumberFormat");
return nullptr;
}
status = napi_set_named_property(env, exports, "PhoneNumberFormat", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitPhoneNumberFormat");
HILOG_ERROR_I18N("Set property failed when InitPhoneNumberFormat");
return nullptr;
}
return exports;
@ -746,13 +743,13 @@ napi_value I18nAddon::PhoneNumberFormatConstructor(napi_env env, napi_callback_i
size_t len = 0;
status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get country tag length failed");
HILOG_ERROR_I18N("Get country tag length failed");
return nullptr;
}
std::vector<char> country (len + 1);
status = napi_get_value_string_utf8(env, argv[0], country.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get country tag failed");
HILOG_ERROR_I18N("Get country tag failed");
return nullptr;
}
std::map<std::string, std::string> options;
@ -764,7 +761,7 @@ napi_value I18nAddon::PhoneNumberFormatConstructor(napi_env env, napi_callback_i
status = napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()),
I18nAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "PhoneNumberFormatConstructor: Wrap I18nAddon failed");
HILOG_ERROR_I18N("PhoneNumberFormatConstructor: Wrap I18nAddon failed");
return nullptr;
}
if (!obj->InitPhoneNumberFormatContext(env, info, country.data(), options)) {
@ -780,7 +777,7 @@ bool I18nAddon::InitPhoneNumberFormatContext(napi_env env, napi_callback_info in
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitPhoneNumberFormatContext: Get global failed");
HILOG_ERROR_I18N("InitPhoneNumberFormatContext: Get global failed");
return false;
}
env_ = env;
@ -806,20 +803,20 @@ napi_value I18nAddon::IsValidPhoneNumber(napi_env env, napi_callback_info info)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsValidPhoneNumber: Get phone number length failed");
HILOG_ERROR_I18N("IsValidPhoneNumber: Get phone number length failed");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsValidPhoneNumber: Get phone number failed");
HILOG_ERROR_I18N("IsValidPhoneNumber: Get phone number failed");
return nullptr;
}
I18nAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->phonenumberfmt_) {
HiLog::Error(LABEL, "IsValidPhoneNumber: GetPhoneNumberFormat object failed");
HILOG_ERROR_I18N("IsValidPhoneNumber: GetPhoneNumberFormat object failed");
return nullptr;
}
@ -828,7 +825,7 @@ napi_value I18nAddon::IsValidPhoneNumber(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_get_boolean(env, isValid, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsValidPhoneNumber: Create boolean failed");
HILOG_ERROR_I18N("IsValidPhoneNumber: Create boolean failed");
return nullptr;
}
@ -856,7 +853,7 @@ napi_value I18nAddon::GetLocationName(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->phonenumberfmt_) {
HiLog::Error(LABEL, "GetLocationName: GetPhoneNumberFormat object failed");
HILOG_ERROR_I18N("GetLocationName: GetPhoneNumberFormat object failed");
return nullptr;
}
@ -864,7 +861,7 @@ napi_value I18nAddon::GetLocationName(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, resStr.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create result string failed");
HILOG_ERROR_I18N("Create result string failed");
return nullptr;
}
@ -888,20 +885,20 @@ napi_value I18nAddon::FormatPhoneNumber(napi_env env, napi_callback_info info)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "FormatPhoneNumber: Get phone number length failed");
HILOG_ERROR_I18N("FormatPhoneNumber: Get phone number length failed");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "FormatPhoneNumber: Get phone number failed");
HILOG_ERROR_I18N("FormatPhoneNumber: Get phone number failed");
return nullptr;
}
I18nAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->phonenumberfmt_) {
HiLog::Error(LABEL, "Get PhoneNumberFormat object failed");
HILOG_ERROR_I18N("Get PhoneNumberFormat object failed");
return nullptr;
}
@ -910,7 +907,7 @@ napi_value I18nAddon::FormatPhoneNumber(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, formattedPhoneNumber.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create format phone number failed");
HILOG_ERROR_I18N("Create format phone number failed");
return nullptr;
}
return result;
@ -928,13 +925,13 @@ napi_value I18nAddon::InitI18nIndexUtil(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "IndexUtil", NAPI_AUTO_LENGTH, I18nIndexUtilConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nIndexUtil: Define class failed when InitI18nIndexUtil.");
HILOG_ERROR_I18N("InitI18nIndexUtil: Define class failed when InitI18nIndexUtil.");
return nullptr;
}
exports = I18nAddon::InitIndexUtil(env, exports);
status = napi_create_reference(env, constructor, 1, &g_indexUtilConstructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nIndexUtil: Failed to create reference at init.");
HILOG_ERROR_I18N("InitI18nIndexUtil: Failed to create reference at init.");
return nullptr;
}
return exports;
@ -947,12 +944,12 @@ napi_value I18nAddon::InitIndexUtil(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "I18nIndexUtil", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor,
nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitIndexUtil: Failed to define class IndexUtil.");
HILOG_ERROR_I18N("InitIndexUtil: Failed to define class IndexUtil.");
return nullptr;
}
status = napi_set_named_property(env, exports, "IndexUtil", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitIndexUtil: Set property failed When InitIndexUtil.");
HILOG_ERROR_I18N("InitIndexUtil: Set property failed When InitIndexUtil.");
return nullptr;
}
return exports;
@ -984,12 +981,12 @@ napi_value I18nAddon::I18nBreakIteratorConstructor(napi_env env, napi_callback_i
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), I18nAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "BreakIteratorConstructor: Wrap II18nAddon failed");
HILOG_ERROR_I18N("BreakIteratorConstructor: Wrap II18nAddon failed");
return nullptr;
}
obj->brkiter_ = std::make_unique<I18nBreakIterator>(localeTag);
if (!obj->brkiter_) {
HiLog::Error(LABEL, "Wrap BreakIterator failed");
HILOG_ERROR_I18N("Wrap BreakIterator failed");
return nullptr;
}
obj.release();
@ -1013,18 +1010,18 @@ napi_value I18nAddon::InitI18nBreakIterator(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "BreakIterator", NAPI_AUTO_LENGTH, I18nBreakIteratorConstructor,
nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nBreakIterator: Failed to define class BreakIterator at Init");
HILOG_ERROR_I18N("InitI18nBreakIterator: Failed to define class BreakIterator at Init");
return nullptr;
}
exports = I18nAddon::InitBreakIterator(env, exports);
g_brkConstructor = new (std::nothrow) napi_ref;
if (!g_brkConstructor) {
HiLog::Error(LABEL, "InitI18nBreakIterator: Failed to create brkiterator ref at init");
HILOG_ERROR_I18N("InitI18nBreakIterator: Failed to create brkiterator ref at init");
return nullptr;
}
status = napi_create_reference(env, constructor, 1, g_brkConstructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nBreakIterator: Failed to create reference g_brkConstructor at init");
HILOG_ERROR_I18N("InitI18nBreakIterator: Failed to create reference g_brkConstructor at init");
return nullptr;
}
return exports;
@ -1037,12 +1034,12 @@ napi_value I18nAddon::InitBreakIterator(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "I18nBreakIterator", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor,
nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitBreakIterator: Failed to define class BreakIterator.");
HILOG_ERROR_I18N("InitBreakIterator: Failed to define class BreakIterator.");
return nullptr;
}
status = napi_set_named_property(env, exports, "BreakIterator", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitBreakIterator: Set property failed When InitBreakIterator.");
HILOG_ERROR_I18N("InitBreakIterator: Set property failed When InitBreakIterator.");
return nullptr;
}
return exports;
@ -1058,7 +1055,7 @@ napi_value I18nAddon::GetLineInstance(napi_env env, napi_callback_info info)
napi_value constructor = nullptr;
napi_status status = napi_get_reference_value(env, *g_brkConstructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference at GetLineInstance");
HILOG_ERROR_I18N("Failed to create reference at GetLineInstance");
return nullptr;
}
if (!argv[0]) {
@ -1067,7 +1064,7 @@ napi_value I18nAddon::GetLineInstance(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_new_instance(env, constructor, 1, argv, &result); // 1 arguments
if (status != napi_ok) {
HiLog::Error(LABEL, "GetLineInstance create instance failed");
HILOG_ERROR_I18N("GetLineInstance create instance failed");
return nullptr;
}
return result;
@ -1083,14 +1080,14 @@ napi_value I18nAddon::Current(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "Current: Get BreakIterator object failed");
HILOG_ERROR_I18N("Current: Get BreakIterator object failed");
return nullptr;
}
int value = obj->brkiter_->Current();
napi_value result = nullptr;
status = napi_create_int32(env, value, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Current: Create int32_t value failed");
HILOG_ERROR_I18N("Current: Create int32_t value failed");
return nullptr;
}
return result;
@ -1106,14 +1103,14 @@ napi_value I18nAddon::First(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "First: Get BreakIterator object failed");
HILOG_ERROR_I18N("First: Get BreakIterator object failed");
return nullptr;
}
int value = obj->brkiter_->First();
napi_value result = nullptr;
status = napi_create_int32(env, value, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "First: Create int32_t value failed");
HILOG_ERROR_I18N("First: Create int32_t value failed");
return nullptr;
}
return result;
@ -1129,14 +1126,14 @@ napi_value I18nAddon::Last(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "Last: Get BreakIterator object failed");
HILOG_ERROR_I18N("Last: Get BreakIterator object failed");
return nullptr;
}
int value = obj->brkiter_->Last();
napi_value result = nullptr;
status = napi_create_int32(env, value, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Last: Create int32_t value failed");
HILOG_ERROR_I18N("Last: Create int32_t value failed");
return nullptr;
}
return result;
@ -1152,14 +1149,14 @@ napi_value I18nAddon::Previous(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "Previous: Get BreakIterator object failed");
HILOG_ERROR_I18N("Previous: Get BreakIterator object failed");
return nullptr;
}
int value = obj->brkiter_->Previous();
napi_value result = nullptr;
status = napi_create_int32(env, value, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Previous: Create int32_t value failed");
HILOG_ERROR_I18N("Previous: Create int32_t value failed");
return nullptr;
}
return result;
@ -1175,7 +1172,7 @@ napi_value I18nAddon::Next(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "Next: Get BreakIterator object failed");
HILOG_ERROR_I18N("Next: Get BreakIterator object failed");
return nullptr;
}
int value = 1;
@ -1188,7 +1185,7 @@ napi_value I18nAddon::Next(napi_env env, napi_callback_info info)
}
status = napi_get_value_int32(env, argv[0], &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Retrieve next value failed");
HILOG_ERROR_I18N("Retrieve next value failed");
return nullptr;
}
}
@ -1196,7 +1193,7 @@ napi_value I18nAddon::Next(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_int32(env, value, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Next: Create int32_t value failed");
HILOG_ERROR_I18N("Next: Create int32_t value failed");
return nullptr;
}
return result;
@ -1212,7 +1209,7 @@ napi_value I18nAddon::SetText(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "SetText: Get BreakIterator object failed");
HILOG_ERROR_I18N("SetText: Get BreakIterator object failed");
return nullptr;
}
if (!argv[0]) {
@ -1227,13 +1224,13 @@ napi_value I18nAddon::SetText(napi_env env, napi_callback_info info)
size_t len = 0;
status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetText: Get field length failed");
HILOG_ERROR_I18N("SetText: Get field length failed");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetText: Get string value failed");
HILOG_ERROR_I18N("SetText: Get string value failed");
return nullptr;
}
obj->brkiter_->SetText(buf.data());
@ -1250,7 +1247,7 @@ napi_value I18nAddon::GetText(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "GetText: Get BreakIterator object failed");
HILOG_ERROR_I18N("GetText: Get BreakIterator object failed");
return nullptr;
}
napi_value value = nullptr;
@ -1258,7 +1255,7 @@ napi_value I18nAddon::GetText(napi_env env, napi_callback_info info)
obj->brkiter_->GetText(temp);
status = napi_create_string_utf8(env, temp.c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetText: Get field length failed");
HILOG_ERROR_I18N("GetText: Get field length failed");
return nullptr;
}
return value;
@ -1274,7 +1271,7 @@ napi_value I18nAddon::Following(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "Following: Get BreakIterator object failed");
HILOG_ERROR_I18N("Following: Get BreakIterator object failed");
return nullptr;
}
if (!argv[0]) {
@ -1289,14 +1286,14 @@ napi_value I18nAddon::Following(napi_env env, napi_callback_info info)
int value;
status = napi_get_value_int32(env, argv[0], &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Following: Retrieve following value failed");
HILOG_ERROR_I18N("Following: Retrieve following value failed");
return nullptr;
}
value = obj->brkiter_->Following(value);
napi_value result = nullptr;
status = napi_create_int32(env, value, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Following: Create int32_t value failed");
HILOG_ERROR_I18N("Following: Create int32_t value failed");
return nullptr;
}
return result;
@ -1312,7 +1309,7 @@ napi_value I18nAddon::IsBoundary(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->brkiter_) {
HiLog::Error(LABEL, "IsBoundary: Get BreakIterator object failed");
HILOG_ERROR_I18N("IsBoundary: Get BreakIterator object failed");
return nullptr;
}
if (!argv[0]) {
@ -1327,14 +1324,14 @@ napi_value I18nAddon::IsBoundary(napi_env env, napi_callback_info info)
}
status = napi_get_value_int32(env, argv[0], &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsBoundary: Retrieve following value failed");
HILOG_ERROR_I18N("IsBoundary: Retrieve following value failed");
return nullptr;
}
bool boundary = obj->brkiter_->IsBoundary(value);
napi_value result = nullptr;
status = napi_get_boolean(env, boundary, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsBoundary: Create boolean failed");
HILOG_ERROR_I18N("IsBoundary: Create boolean failed");
return nullptr;
}
return result;
@ -1361,13 +1358,13 @@ napi_value I18nAddon::I18nIndexUtilConstructor(napi_env env, napi_callback_info
size_t len = 0;
status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "IndexUtilConstructor: Get locale length failed");
HILOG_ERROR_I18N("IndexUtilConstructor: Get locale length failed");
return nullptr;
}
std::vector<char> localeBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], localeBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "IndexUtilConstructor: Get locale failed");
HILOG_ERROR_I18N("IndexUtilConstructor: Get locale failed");
return nullptr;
}
localeTag = localeBuf.data();
@ -1377,7 +1374,7 @@ napi_value I18nAddon::I18nIndexUtilConstructor(napi_env env, napi_callback_info
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), I18nAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "IndexUtilConstructor: Wrap II18nAddon failed");
HILOG_ERROR_I18N("IndexUtilConstructor: Wrap II18nAddon failed");
return nullptr;
}
if (!obj->InitIndexUtilContext(env, info, localeTag)) {
@ -1392,7 +1389,7 @@ bool I18nAddon::InitIndexUtilContext(napi_env env, napi_callback_info info, cons
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitIndexUtilContext: Get global failed");
HILOG_ERROR_I18N("InitIndexUtilContext: Get global failed");
return false;
}
env_ = env;
@ -1410,7 +1407,7 @@ napi_value I18nAddon::GetIndexUtil(napi_env env, napi_callback_info info)
napi_value constructor = nullptr;
napi_status status = napi_get_reference_value(env, g_indexUtilConstructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference at GetIndexUtil");
HILOG_ERROR_I18N("Failed to create reference at GetIndexUtil");
return nullptr;
}
napi_value result = nullptr;
@ -1420,7 +1417,7 @@ napi_value I18nAddon::GetIndexUtil(napi_env env, napi_callback_info info)
status = napi_new_instance(env, constructor, 1, argv, &result);
}
if (status != napi_ok) {
HiLog::Error(LABEL, "Get calendar create instance failed");
HILOG_ERROR_I18N("Get calendar create instance failed");
return nullptr;
}
return result;
@ -1435,7 +1432,7 @@ napi_value I18nAddon::GetIndexList(napi_env env, napi_callback_info info)
I18nAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->indexUtil_) {
HiLog::Error(LABEL, "GetIndexList: GetPhoneNumberFormat object failed");
HILOG_ERROR_I18N("GetIndexList: GetPhoneNumberFormat object failed");
return nullptr;
}
@ -1443,19 +1440,19 @@ napi_value I18nAddon::GetIndexList(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_array_with_length(env, indexList.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create array");
HILOG_ERROR_I18N("Failed to create array");
return nullptr;
}
for (size_t i = 0; i < indexList.size(); i++) {
napi_value element = nullptr;
status = napi_create_string_utf8(env, indexList[i].c_str(), NAPI_AUTO_LENGTH, &element);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetIndexList: Failed to create string item");
HILOG_ERROR_I18N("GetIndexList: Failed to create string item");
return nullptr;
}
status = napi_set_element(env, result, i, element);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set array item");
HILOG_ERROR_I18N("Failed to set array item");
return nullptr;
}
}
@ -1478,19 +1475,19 @@ napi_value I18nAddon::AddLocale(napi_env env, napi_callback_info info)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "AddLocale: Get locale length failed");
HILOG_ERROR_I18N("AddLocale: Get locale length failed");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "AddLocale: Get locale failed");
HILOG_ERROR_I18N("AddLocale: Get locale failed");
return nullptr;
}
I18nAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->indexUtil_) {
HiLog::Error(LABEL, "AddLocale: Get IndexUtil object failed");
HILOG_ERROR_I18N("AddLocale: Get IndexUtil object failed");
return nullptr;
}
obj->indexUtil_->AddLocale(buf.data());
@ -1513,26 +1510,26 @@ napi_value I18nAddon::GetIndex(napi_env env, napi_callback_info info)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get String length failed");
HILOG_ERROR_I18N("Get String length failed");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get String failed");
HILOG_ERROR_I18N("Get String failed");
return nullptr;
}
I18nAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->indexUtil_) {
HiLog::Error(LABEL, "GetIndex: Get IndexUtil object failed");
HILOG_ERROR_I18N("GetIndex: Get IndexUtil object failed");
return nullptr;
}
std::string index = obj->indexUtil_->GetIndex(buf.data());
napi_value result = nullptr;
status = napi_create_string_utf8(env, index.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetIndex Failed");
HILOG_ERROR_I18N("GetIndex Failed");
return nullptr;
}
return result;
@ -1551,7 +1548,7 @@ napi_value I18nAddon::ObjectConstructor(napi_env env, napi_callback_info info)
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), I18nAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "ObjectConstructor: Wrap I18nAddon failed");
HILOG_ERROR_I18N("ObjectConstructor: Wrap I18nAddon failed");
return nullptr;
}
obj.release();
@ -1569,13 +1566,13 @@ napi_value I18nAddon::InitUtil(napi_env env, napi_value exports)
status = napi_define_class(env, "Util", NAPI_AUTO_LENGTH, ObjectConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitUtil");
HILOG_ERROR_I18N("Define class failed when InitUtil");
return nullptr;
}
status = napi_set_named_property(env, exports, "Util", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitUtil");
HILOG_ERROR_I18N("Set property failed when InitUtil");
return nullptr;
}
return exports;

View File

@ -17,7 +17,7 @@
#include <unordered_set>
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_calendar_addon.h"
#include "js_utils.h"
#include "variable_convertor.h"
@ -25,9 +25,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nCalendarAddonJs" };
using namespace OHOS::HiviewDFX;
static thread_local napi_ref* g_constructor = nullptr;
static std::unordered_map<std::string, UCalendarDateFields> g_fieldsMap {
{ "era", UCAL_ERA },
@ -109,18 +106,18 @@ napi_value I18nCalendarAddon::InitI18nCalendar(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "Calendar", NAPI_AUTO_LENGTH, I18nCalendarConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to define class at Init");
HILOG_ERROR_I18N("Failed to define class at Init");
return nullptr;
}
exports = I18nCalendarAddon::InitCalendar(env, exports);
g_constructor = new (std::nothrow) napi_ref;
if (!g_constructor) {
HiLog::Error(LABEL, "Failed to create ref at init");
HILOG_ERROR_I18N("Failed to create ref at init");
return nullptr;
}
status = napi_create_reference(env, constructor, 1, g_constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference at init");
HILOG_ERROR_I18N("Failed to create reference at init");
return nullptr;
}
return exports;
@ -133,12 +130,12 @@ napi_value I18nCalendarAddon::InitCalendar(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "I18nCalendar", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitCalendar: Failed to define class Calendar.");
HILOG_ERROR_I18N("InitCalendar: Failed to define class Calendar.");
return nullptr;
}
status = napi_set_named_property(env, exports, "Calendar", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitCalendar: Set property failed When InitCalendar.");
HILOG_ERROR_I18N("InitCalendar: Set property failed When InitCalendar.");
return nullptr;
}
return exports;
@ -156,7 +153,7 @@ napi_value I18nCalendarAddon::GetCalendar(napi_env env, napi_callback_info info)
napi_value constructor = nullptr;
napi_status status = napi_get_reference_value(env, *g_constructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference at GetCalendar");
HILOG_ERROR_I18N("Failed to create reference at GetCalendar");
return nullptr;
}
napi_valuetype valueType = napi_valuetype::napi_undefined;
@ -170,7 +167,7 @@ napi_value I18nCalendarAddon::GetCalendar(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_new_instance(env, constructor, 2, argv, &result); // 2 arguments
if (status != napi_ok) {
HiLog::Error(LABEL, "Get calendar create instance failed");
HILOG_ERROR_I18N("Get calendar create instance failed");
return nullptr;
}
return result;
@ -205,7 +202,7 @@ napi_value I18nCalendarAddon::I18nCalendarConstructor(napi_env env, napi_callbac
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), I18nCalendarAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "CalendarConstructor: Wrap II18nAddon failed");
HILOG_ERROR_I18N("CalendarConstructor: Wrap II18nAddon failed");
return nullptr;
}
if (!obj->InitCalendarContext(env, info, localeTag, type)) {
@ -229,7 +226,7 @@ napi_value I18nCalendarAddon::SetTime(napi_env env, napi_callback_info info)
I18nCalendarAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "SetTime: Get calendar object failed");
HILOG_ERROR_I18N("SetTime: Get calendar object failed");
return nullptr;
}
napi_valuetype type = napi_valuetype::napi_undefined;
@ -271,14 +268,14 @@ napi_value I18nCalendarAddon::Set(napi_env env, napi_callback_info info)
}
status = napi_get_value_int32(env, argv[i], times + i);
if (status != napi_ok) {
HiLog::Error(LABEL, "Retrieve time value failed");
HILOG_ERROR_I18N("Retrieve time value failed");
return nullptr;
}
}
I18nCalendarAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "Set: Get calendar object failed");
HILOG_ERROR_I18N("Set: Get calendar object failed");
return nullptr;
}
obj->calendar_->Set(times[0], times[1], times[2]); // 2 is the index of date
@ -298,14 +295,14 @@ napi_value I18nCalendarAddon::GetTimeZone(napi_env env, napi_callback_info info)
I18nCalendarAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "GetTimeZone: Get calendar object failed");
HILOG_ERROR_I18N("GetTimeZone: Get calendar object failed");
return nullptr;
}
std::string temp = obj->calendar_->GetTimeZone();
napi_value result = nullptr;
status = napi_create_string_utf8(env, temp.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create timezone string failed");
HILOG_ERROR_I18N("Create timezone string failed");
return nullptr;
}
return result;
@ -328,20 +325,20 @@ napi_value I18nCalendarAddon::SetTimeZone(napi_env env, napi_callback_info info)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get timezone length failed");
HILOG_ERROR_I18N("Get timezone length failed");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get timezone failed");
HILOG_ERROR_I18N("Get timezone failed");
return nullptr;
}
std::string timezone(buf.data());
I18nCalendarAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "SetTimeZone: Get calendar object failed");
HILOG_ERROR_I18N("SetTimeZone: Get calendar object failed");
return nullptr;
}
obj->calendar_->SetTimeZone(timezone);
@ -358,14 +355,14 @@ napi_value I18nCalendarAddon::GetFirstDayOfWeek(napi_env env, napi_callback_info
I18nCalendarAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "GetFirstDayOfWeek: Get calendar object failed");
HILOG_ERROR_I18N("GetFirstDayOfWeek: Get calendar object failed");
return nullptr;
}
int32_t temp = obj->calendar_->GetFirstDayOfWeek();
napi_value result = nullptr;
status = napi_create_int32(env, temp, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetFirstDayOfWeek: Create int32 failed");
HILOG_ERROR_I18N("GetFirstDayOfWeek: Create int32 failed");
return nullptr;
}
return result;
@ -388,13 +385,13 @@ napi_value I18nCalendarAddon::SetFirstDayOfWeek(napi_env env, napi_callback_info
int32_t value = 0;
napi_status status = napi_get_value_int32(env, argv[0], &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetFirstDayOfWeek: Get int32 failed");
HILOG_ERROR_I18N("SetFirstDayOfWeek: Get int32 failed");
return nullptr;
}
I18nCalendarAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "SetFirstDayOfWeek: Get calendar object failed");
HILOG_ERROR_I18N("SetFirstDayOfWeek: Get calendar object failed");
return nullptr;
}
obj->calendar_->SetFirstDayOfWeek(value);
@ -411,14 +408,14 @@ napi_value I18nCalendarAddon::GetMinimalDaysInFirstWeek(napi_env env, napi_callb
I18nCalendarAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "GetMinimalDaysInFirstWeek: Get calendar object failed");
HILOG_ERROR_I18N("GetMinimalDaysInFirstWeek: Get calendar object failed");
return nullptr;
}
int32_t temp = obj->calendar_->GetMinimalDaysInFirstWeek();
napi_value result = nullptr;
status = napi_create_int32(env, temp, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetMinimalDaysInFirstWeek: Create int32 failed");
HILOG_ERROR_I18N("GetMinimalDaysInFirstWeek: Create int32 failed");
return nullptr;
}
return result;
@ -441,13 +438,13 @@ napi_value I18nCalendarAddon::SetMinimalDaysInFirstWeek(napi_env env, napi_callb
int32_t value = 0;
napi_status status = napi_get_value_int32(env, argv[0], &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetMinimalDaysInFirstWeek: Get int32 failed");
HILOG_ERROR_I18N("SetMinimalDaysInFirstWeek: Get int32 failed");
return nullptr;
}
I18nCalendarAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "SetMinimalDaysInFirstWeek: Get calendar object failed");
HILOG_ERROR_I18N("SetMinimalDaysInFirstWeek: Get calendar object failed");
return nullptr;
}
obj->calendar_->SetMinimalDaysInFirstWeek(value);
@ -471,31 +468,31 @@ napi_value I18nCalendarAddon::Get(napi_env env, napi_callback_info info)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get field length failed");
HILOG_ERROR_I18N("Get field length failed");
return nullptr;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get field failed");
HILOG_ERROR_I18N("Get field failed");
return nullptr;
}
std::string field(buf.data());
if (g_fieldsMap.find(field) == g_fieldsMap.end()) {
HiLog::Error(LABEL, "Invalid field");
HILOG_ERROR_I18N("Invalid field");
return nullptr;
}
I18nCalendarAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "Get: Get calendar object failed");
HILOG_ERROR_I18N("Get: Get calendar object failed");
return nullptr;
}
int32_t value = obj->calendar_->Get(g_fieldsMap[field]);
napi_value result = nullptr;
status = napi_create_int32(env, value, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get: Create int32 failed");
HILOG_ERROR_I18N("Get: Create int32 failed");
return nullptr;
}
return result;
@ -509,14 +506,14 @@ napi_value I18nCalendarAddon::Add(napi_env env, napi_callback_info info)
void *data = nullptr;
napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
if (status != napi_ok) {
HiLog::Error(LABEL, "can not obtain add function param.");
HILOG_ERROR_I18N("can not obtain add function param.");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_string) {
HiLog::Error(LABEL, "Parameter type does not match argv[0]");
HILOG_ERROR_I18N("Parameter type does not match argv[0]");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
@ -527,21 +524,21 @@ napi_value I18nCalendarAddon::Add(napi_env env, napi_callback_info info)
}
napi_typeof(env, argv[1], &valueType);
if (valueType != napi_valuetype::napi_number) {
HiLog::Error(LABEL, "Parameter type does not match argv[1]");
HILOG_ERROR_I18N("Parameter type does not match argv[1]");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
int32_t amount;
status = napi_get_value_int32(env, argv[1], &amount);
if (status != napi_ok) {
HiLog::Error(LABEL, "Can not obtain add function param.");
HILOG_ERROR_I18N("Can not obtain add function param.");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return nullptr;
}
I18nCalendarAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "Add: Get calendar object failed");
HILOG_ERROR_I18N("Add: Get calendar object failed");
return nullptr;
}
obj->calendar_->Add(g_fieldsMap[field], amount);
@ -570,7 +567,7 @@ napi_value I18nCalendarAddon::GetDisplayName(napi_env env, napi_callback_info in
I18nCalendarAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "GetDisplayName: Get calendar object failed");
HILOG_ERROR_I18N("GetDisplayName: Get calendar object failed");
return nullptr;
}
if (!obj->calendar_) {
@ -580,7 +577,7 @@ napi_value I18nCalendarAddon::GetDisplayName(napi_env env, napi_callback_info in
napi_value result = nullptr;
status = napi_create_string_utf8(env, name.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create calendar name string failed");
HILOG_ERROR_I18N("Create calendar name string failed");
return nullptr;
}
return result;
@ -597,7 +594,7 @@ napi_value I18nCalendarAddon::GetTimeInMillis(napi_env env, napi_callback_info i
I18nCalendarAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "GetTimeInMillis: Get calendar object failed");
HILOG_ERROR_I18N("GetTimeInMillis: Get calendar object failed");
flag = false;
}
UDate temp = 0;
@ -607,7 +604,7 @@ napi_value I18nCalendarAddon::GetTimeInMillis(napi_env env, napi_callback_info i
napi_value result = nullptr;
status = napi_create_double(env, temp, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create UDate failed");
HILOG_ERROR_I18N("Create UDate failed");
napi_create_double(env, 0, &result);
}
return result;
@ -626,7 +623,7 @@ napi_value I18nCalendarAddon::IsWeekend(napi_env env, napi_callback_info info)
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
do {
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "IsWeekend: Get calendar object failed");
HILOG_ERROR_I18N("IsWeekend: Get calendar object failed");
break;
}
if (!VariableConvertor::CheckNapiValueType(env, argv[0])) {
@ -635,19 +632,19 @@ napi_value I18nCalendarAddon::IsWeekend(napi_env env, napi_callback_info info)
napi_value funcGetDateInfo = nullptr;
status = napi_get_named_property(env, argv[0], "valueOf", &funcGetDateInfo);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get method now failed");
HILOG_ERROR_I18N("Get method now failed");
break;
}
napi_value value = nullptr;
status = napi_call_function(env, argv[0], funcGetDateInfo, 0, nullptr, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsWeekend: Get milliseconds failed");
HILOG_ERROR_I18N("IsWeekend: Get milliseconds failed");
break;
}
double milliseconds = 0;
status = napi_get_value_double(env, value, &milliseconds);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsWeekend: Retrieve milliseconds failed");
HILOG_ERROR_I18N("IsWeekend: Retrieve milliseconds failed");
break;
}
UErrorCode error = U_ZERO_ERROR;
@ -657,7 +654,7 @@ napi_value I18nCalendarAddon::IsWeekend(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_get_boolean(env, isWeekEnd, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create boolean failed");
HILOG_ERROR_I18N("Create boolean failed");
return nullptr;
}
return result;
@ -674,7 +671,7 @@ napi_value I18nCalendarAddon::CompareDays(napi_env env, napi_callback_info info)
UDate milliseconds = 0;
napi_status status = napi_get_date_value(env, argv[0], &milliseconds);
if (status != napi_ok) {
HiLog::Error(LABEL, "compareDays function param is not Date");
HILOG_ERROR_I18N("compareDays function param is not Date");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
@ -682,7 +679,7 @@ napi_value I18nCalendarAddon::CompareDays(napi_env env, napi_callback_info info)
I18nCalendarAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->calendar_) {
HiLog::Error(LABEL, "CompareDays: Get calendar object failed");
HILOG_ERROR_I18N("CompareDays: Get calendar object failed");
status = napi_create_int32(env, 0, &result); // if error return 0
return result;
}
@ -735,7 +732,7 @@ void I18nCalendarAddon::SetField(napi_env env, napi_value value, UCalendarDateFi
}
napi_status status = napi_get_value_int32(env, value, &val);
if (status != napi_ok) {
HiLog::Error(LABEL, "Retrieve field failed");
HILOG_ERROR_I18N("Retrieve field failed");
return;
}
if (calendar_ != nullptr) {
@ -747,13 +744,13 @@ std::string I18nCalendarAddon::GetAddField(napi_env &env, napi_value &value, int
{
std::string field = VariableConvertor::GetString(env, value, code);
if (code != 0) {
HiLog::Error(LABEL, "can't get string from js array param.");
HILOG_ERROR_I18N("can't get string from js array param.");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return field;
}
if (g_fieldsInFunctionAdd.find(field) == g_fieldsInFunctionAdd.end()) {
code = 1;
HiLog::Error(LABEL, "Parameter rangs do not match");
HILOG_ERROR_I18N("Parameter rangs do not match");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return field;
}
@ -768,13 +765,13 @@ napi_value I18nCalendarAddon::GetDate(napi_env env, napi_value value)
napi_value funcGetDateInfo = nullptr;
napi_status status = napi_get_named_property(env, value, "valueOf", &funcGetDateInfo);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get method valueOf failed");
HILOG_ERROR_I18N("Get method valueOf failed");
return nullptr;
}
napi_value ret_value = nullptr;
status = napi_call_function(env, value, funcGetDateInfo, 0, nullptr, &ret_value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDate: Get milliseconds failed");
HILOG_ERROR_I18N("GetDate: Get milliseconds failed");
return nullptr;
}
return ret_value;
@ -794,7 +791,7 @@ void I18nCalendarAddon::SetMilliseconds(napi_env env, napi_value value)
}
napi_status status = napi_get_value_double(env, value, &milliseconds);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetMilliseconds: Retrieve milliseconds failed");
HILOG_ERROR_I18N("SetMilliseconds: Retrieve milliseconds failed");
return;
}
if (calendar_ != nullptr) {

View File

@ -14,7 +14,7 @@
*/
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "js_utils.h"
#include "locale_config.h"
#include "variable_convertor.h"
@ -23,9 +23,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nNormalizerJs" };
using namespace OHOS::HiviewDFX;
static thread_local napi_ref* g_normalizerConstructor = nullptr;
const char *I18nNormalizerAddon::NORMALIZER_MODE_NFC_NAME = "NFC";
@ -56,18 +53,18 @@ napi_value I18nNormalizerAddon::InitI18nNormalizer(napi_env env, napi_value expo
napi_status status = napi_define_class(env, "Normalizer", NAPI_AUTO_LENGTH, I18nNormalizerConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nNormalizer: Failed to define class Normalizer at Init");
HILOG_ERROR_I18N("InitI18nNormalizer: Failed to define class Normalizer at Init");
return nullptr;
}
exports = I18nNormalizerAddon::InitNormalizer(env, exports);
g_normalizerConstructor = new (std::nothrow) napi_ref;
if (!g_normalizerConstructor) {
HiLog::Error(LABEL, "InitI18nNormalizer: Failed to create Normalizer ref at init");
HILOG_ERROR_I18N("InitI18nNormalizer: Failed to create Normalizer ref at init");
return nullptr;
}
status = napi_create_reference(env, constructor, 1, g_normalizerConstructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nNormalizer: Failed to create reference g_normalizerConstructor at init.");
HILOG_ERROR_I18N("InitI18nNormalizer: Failed to create reference g_normalizerConstructor at init.");
return nullptr;
}
return exports;
@ -82,12 +79,12 @@ napi_value I18nNormalizerAddon::InitNormalizer(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "I18nNormalizer", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor,
nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitNormalizer: Failed to define class Normalizer.");
HILOG_ERROR_I18N("InitNormalizer: Failed to define class Normalizer.");
return nullptr;
}
status = napi_set_named_property(env, exports, "Normalizer", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitNormalizer: Set property failed When InitNormalizer.");
HILOG_ERROR_I18N("InitNormalizer: Set property failed When InitNormalizer.");
return nullptr;
}
return exports;
@ -158,7 +155,7 @@ napi_value I18nNormalizerAddon::Normalize(napi_env env, napi_callback_info info)
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_string) {
HiLog::Error(LABEL, "Invalid parameter type");
HILOG_ERROR_I18N("Invalid parameter type");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
@ -171,7 +168,7 @@ napi_value I18nNormalizerAddon::Normalize(napi_env env, napi_callback_info info)
I18nNormalizerAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || obj == nullptr || obj->normalizer_ == nullptr) {
HiLog::Error(LABEL, "Get Normalizer object failed");
HILOG_ERROR_I18N("Get Normalizer object failed");
return nullptr;
}
I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
@ -183,7 +180,7 @@ napi_value I18nNormalizerAddon::Normalize(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, normalizedText.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create result failed");
HILOG_ERROR_I18N("Create result failed");
return nullptr;
}
return result;
@ -251,21 +248,21 @@ napi_value I18nNormalizerAddon::GetI18nNormalizerInstance(napi_env env, napi_cal
void *data = nullptr;
napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to get parameter of Normalizer.createInstance");
HILOG_ERROR_I18N("Failed to get parameter of Normalizer.createInstance");
return nullptr;
}
napi_value constructor = nullptr;
status = napi_get_reference_value(env, *g_normalizerConstructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference of normalizer Constructor");
HILOG_ERROR_I18N("Failed to create reference of normalizer Constructor");
return nullptr;
}
napi_value result = nullptr;
status = napi_new_instance(env, constructor, argc, argv, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create normalizer instance failed");
HILOG_ERROR_I18N("create normalizer instance failed");
return nullptr;
}
return result;

View File

@ -14,7 +14,7 @@
*/
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_service_ability_client.h"
#include "i18n_service_ability_load_manager.h"
#include "i18n_system_addon.h"
@ -27,9 +27,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nSystemAddonJS" };
using namespace OHOS::HiviewDFX;
I18nSystemAddon::I18nSystemAddon() {}
I18nSystemAddon::~I18nSystemAddon() {}
@ -72,13 +69,13 @@ napi_value I18nSystemAddon::InitI18nSystem(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "System", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitSystem.");
HILOG_ERROR_I18N("Define class failed when InitSystem.");
return nullptr;
}
status = napi_set_named_property(env, exports, "System", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitSystem.");
HILOG_ERROR_I18N("Set property failed when InitSystem.");
return nullptr;
}
return exports;
@ -111,19 +108,19 @@ napi_value I18nSystemAddon::GetSystemLanguages(napi_env env, napi_callback_info
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, systemLanguages.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemLanguages: Failed to create array");
HILOG_ERROR_I18N("GetSystemLanguages: Failed to create array");
return nullptr;
}
for (size_t i = 0; i < systemLanguages.size(); i++) {
napi_value value = nullptr;
status = napi_create_string_utf8(env, systemLanguages[i].c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemLanguages: Failed to create string item");
HILOG_ERROR_I18N("GetSystemLanguages: Failed to create string item");
return nullptr;
}
status = napi_set_element(env, result, i, value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemLanguages: Failed to set array item");
HILOG_ERROR_I18N("GetSystemLanguages: Failed to set array item");
return nullptr;
}
}
@ -156,7 +153,7 @@ napi_value I18nSystemAddon::GetSystemLanguage(napi_env env, napi_callback_info i
napi_value result = nullptr;
napi_status status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemLanguage: Failed to create string item");
HILOG_ERROR_I18N("GetSystemLanguage: Failed to create string item");
return nullptr;
}
return result;
@ -178,7 +175,7 @@ napi_value I18nSystemAddon::GetSystemRegion(napi_env env, napi_callback_info inf
napi_value result = nullptr;
napi_status status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemRegion: Failed to create string item");
HILOG_ERROR_I18N("GetSystemRegion: Failed to create string item");
return nullptr;
}
return result;
@ -200,7 +197,7 @@ napi_value I18nSystemAddon::GetSystemLocale(napi_env env, napi_callback_info inf
napi_value result = nullptr;
napi_status status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemLocale: Failed to create string item");
HILOG_ERROR_I18N("GetSystemLocale: Failed to create string item");
return nullptr;
}
return result;
@ -222,7 +219,7 @@ napi_value I18nSystemAddon::Is24HourClock(napi_env env, napi_callback_info info)
napi_value result = nullptr;
napi_status status = napi_get_boolean(env, is24HourClock, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create boolean item");
HILOG_ERROR_I18N("Failed to create boolean item");
return nullptr;
}
return result;
@ -265,19 +262,19 @@ napi_value I18nSystemAddon::GetPreferredLanguageList(napi_env env, napi_callback
napi_status status = napi_ok;
status = napi_create_array_with_length(env, languageList.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "getPreferrdLanguageList: create array failed");
HILOG_ERROR_I18N("getPreferrdLanguageList: create array failed");
return nullptr;
}
for (size_t i = 0; i < languageList.size(); i++) {
napi_value value = nullptr;
status = napi_create_string_utf8(env, languageList[i].c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "getPreferrdLanguageList: create string failed");
HILOG_ERROR_I18N("getPreferrdLanguageList: create string failed");
return nullptr;
}
status = napi_set_element(env, result, i, value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetPreferredLanguageList: set array item failed");
HILOG_ERROR_I18N("GetPreferredLanguageList: set array item failed");
return nullptr;
}
}
@ -291,7 +288,7 @@ napi_value I18nSystemAddon::GetFirstPreferredLanguage(napi_env env, napi_callbac
napi_status status = napi_ok;
status = napi_create_string_utf8(env, language.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "getFirstPreferrdLanguage: create string result failed");
HILOG_ERROR_I18N("getFirstPreferrdLanguage: create string result failed");
return nullptr;
}
return result;
@ -307,20 +304,20 @@ napi_value I18nSystemAddon::SetAppPreferredLanguage(napi_env env, napi_callback_
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_string) {
HiLog::Error(LABEL, "SetAppPreferredLanguage Parameter type is not string");
HILOG_ERROR_I18N("SetAppPreferredLanguage Parameter type is not string");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
int code = 0;
std::string localeTag = VariableConvertor::GetString(env, argv[0], code);
if (code) {
HiLog::Error(LABEL, "SetAppPreferredLanguage can't get string from js param");
HILOG_ERROR_I18N("SetAppPreferredLanguage can't get string from js param");
return nullptr;
}
UErrorCode icuStatus = U_ZERO_ERROR;
icu::Locale locale = icu::Locale::forLanguageTag(localeTag.data(), icuStatus);
if (U_FAILURE(icuStatus) || !IsValidLocaleTag(locale)) {
HiLog::Error(LABEL, "GetTimePeriodName does not support this locale");
HILOG_ERROR_I18N("GetTimePeriodName does not support this locale");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return nullptr;
}
@ -328,7 +325,7 @@ napi_value I18nSystemAddon::SetAppPreferredLanguage(napi_env env, napi_callback_
I18nErrorCode errCode = I18nErrorCode::SUCCESS;
PreferredLanguage::SetAppPreferredLanguage(localeTag, errCode);
if (errCode != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "SetAppPreferredLanguage: set app language to i18n app preferences failed.");
HILOG_ERROR_I18N("SetAppPreferredLanguage: set app language to i18n app preferences failed.");
}
#endif
return nullptr;
@ -345,7 +342,7 @@ napi_value I18nSystemAddon::GetAppPreferredLanguage(napi_env env, napi_callback_
napi_status status = napi_ok;
status = napi_create_string_utf8(env, language.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "getAppPreferrdLanguage: create string result failed");
HILOG_ERROR_I18N("getAppPreferrdLanguage: create string result failed");
return nullptr;
}
return result;
@ -384,7 +381,7 @@ napi_value I18nSystemAddon::GetDisplayCountryImpl(napi_env env, napi_callback_in
return nullptr;
}
if (argc < FUNC_ARGS_COUNT) {
HiLog::Error(LABEL, "GetDisplayCountryImpl: Missing parameter");
HILOG_ERROR_I18N("GetDisplayCountryImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -393,7 +390,7 @@ napi_value I18nSystemAddon::GetDisplayCountryImpl(napi_env env, napi_callback_in
std::vector<char> localeBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], localeBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDisplayCountryImpl: Failed to get string item argv[0]");
HILOG_ERROR_I18N("GetDisplayCountryImpl: Failed to get string item argv[0]");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -401,7 +398,7 @@ napi_value I18nSystemAddon::GetDisplayCountryImpl(napi_env env, napi_callback_in
std::vector<char> displayLocaleBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[1], displayLocaleBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDisplayCountryImpl: Failed to get string item argv[1]");
HILOG_ERROR_I18N("GetDisplayCountryImpl: Failed to get string item argv[1]");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -417,7 +414,7 @@ napi_value I18nSystemAddon::GetDisplayCountryImpl(napi_env env, napi_callback_in
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDisplayCountryImpl: Failed to create string item");
HILOG_ERROR_I18N("GetDisplayCountryImpl: Failed to create string item");
return nullptr;
}
return result;
@ -435,7 +432,7 @@ napi_value I18nSystemAddon::GetDisplayLanguageImpl(napi_env env, napi_callback_i
return nullptr;
}
if (argc < FUNC_ARGS_COUNT) {
HiLog::Error(LABEL, "GetDisplayLanguageImpl: Missing parameter");
HILOG_ERROR_I18N("GetDisplayLanguageImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -444,7 +441,7 @@ napi_value I18nSystemAddon::GetDisplayLanguageImpl(napi_env env, napi_callback_i
std::vector<char> localeBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], localeBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDisplayLanguageImpl: Failed to get string item argv[0]");
HILOG_ERROR_I18N("GetDisplayLanguageImpl: Failed to get string item argv[0]");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -452,7 +449,7 @@ napi_value I18nSystemAddon::GetDisplayLanguageImpl(napi_env env, napi_callback_i
std::vector<char> displayLocaleBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[1], displayLocaleBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDisplayLanguageImpl: Failed to get string item argv[1]");
HILOG_ERROR_I18N("GetDisplayLanguageImpl: Failed to get string item argv[1]");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -470,7 +467,7 @@ napi_value I18nSystemAddon::GetDisplayLanguageImpl(napi_env env, napi_callback_i
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetDisplayLanguageImpl: Failed to create string item");
HILOG_ERROR_I18N("GetDisplayLanguageImpl: Failed to create string item");
return nullptr;
}
return result;
@ -487,7 +484,7 @@ napi_value I18nSystemAddon::GetSystemCountriesImpl(napi_env env, napi_callback_i
return nullptr;
}
if (argc < 1) {
HiLog::Error(LABEL, "GetSystemCountriesImpl: Missing parameter");
HILOG_ERROR_I18N("GetSystemCountriesImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -496,7 +493,7 @@ napi_value I18nSystemAddon::GetSystemCountriesImpl(napi_env env, napi_callback_i
std::vector<char> localeBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], localeBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemCountriesImpl Failed to get string item");
HILOG_ERROR_I18N("GetSystemCountriesImpl Failed to get string item");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -505,19 +502,19 @@ napi_value I18nSystemAddon::GetSystemCountriesImpl(napi_env env, napi_callback_i
napi_value result = nullptr;
status = napi_create_array_with_length(env, systemCountries.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemCountriesImpl: Failed to create array");
HILOG_ERROR_I18N("GetSystemCountriesImpl: Failed to create array");
return nullptr;
}
for (size_t i = 0; i < systemCountries.size(); i++) {
napi_value value = nullptr;
status = napi_create_string_utf8(env, systemCountries[i].c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemCountries: Failed to create string item");
HILOG_ERROR_I18N("GetSystemCountries: Failed to create string item");
return nullptr;
}
status = napi_set_element(env, result, i, value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetSystemCountries: Failed to set array item");
HILOG_ERROR_I18N("GetSystemCountries: Failed to set array item");
return nullptr;
}
}
@ -536,7 +533,7 @@ napi_value I18nSystemAddon::IsSuggestedImpl(napi_env env, napi_callback_info inf
return nullptr;
}
if (argc < 1) {
HiLog::Error(LABEL, "IsSuggestedImpl: Missing parameter");
HILOG_ERROR_I18N("IsSuggestedImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -545,7 +542,7 @@ napi_value I18nSystemAddon::IsSuggestedImpl(napi_env env, napi_callback_info inf
std::vector<char> languageBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], languageBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsSuggestedImpl: Failed to get string item argv[0]");
HILOG_ERROR_I18N("IsSuggestedImpl: Failed to get string item argv[0]");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -555,7 +552,7 @@ napi_value I18nSystemAddon::IsSuggestedImpl(napi_env env, napi_callback_info inf
std::vector<char> regionBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[1], regionBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "IsSuggestedImpl: Failed to get string item argv[1]");
HILOG_ERROR_I18N("IsSuggestedImpl: Failed to get string item argv[1]");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -566,7 +563,7 @@ napi_value I18nSystemAddon::IsSuggestedImpl(napi_env env, napi_callback_info inf
napi_value result = nullptr;
status = napi_get_boolean(env, isSuggested, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create case first boolean value failed");
HILOG_ERROR_I18N("Create case first boolean value failed");
return nullptr;
}
return result;
@ -583,7 +580,7 @@ napi_value I18nSystemAddon::SetSystemLanguageImpl(napi_env env, napi_callback_in
return nullptr;
}
if (argc < 1) {
HiLog::Error(LABEL, "SetSystemLanguageImpl: Missing parameter");
HILOG_ERROR_I18N("SetSystemLanguageImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -592,12 +589,12 @@ napi_value I18nSystemAddon::SetSystemLanguageImpl(napi_env env, napi_callback_in
std::vector<char> languageBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], languageBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetSystemLanguageImpl: Failed to get string item");
HILOG_ERROR_I18N("SetSystemLanguageImpl: Failed to get string item");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
I18nErrorCode err = I18nServiceAbilityClient::SetSystemLanguage(languageBuf.data());
HiLog::Info(LABEL, "I18nSystemAddon::SetSystemLanguageImpl with code %{public}d", static_cast<int32_t>(err));
HILOG_INFO_I18N("I18nSystemAddon::SetSystemLanguageImpl with code %{public}d", static_cast<int32_t>(err));
bool success = err == I18nErrorCode::SUCCESS;
if (throwError) {
if (!success) {
@ -608,7 +605,7 @@ napi_value I18nSystemAddon::SetSystemLanguageImpl(napi_env env, napi_callback_in
napi_value result = nullptr;
status = napi_get_boolean(env, success, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetSystemLanguageImpl: Create set system language boolean value failed");
HILOG_ERROR_I18N("SetSystemLanguageImpl: Create set system language boolean value failed");
return nullptr;
}
return result;
@ -625,7 +622,7 @@ napi_value I18nSystemAddon::SetSystemRegionImpl(napi_env env, napi_callback_info
return nullptr;
}
if (argc < 1) {
HiLog::Error(LABEL, "SetSystemRegionImpl: Missing parameter");
HILOG_ERROR_I18N("SetSystemRegionImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -634,12 +631,12 @@ napi_value I18nSystemAddon::SetSystemRegionImpl(napi_env env, napi_callback_info
std::vector<char> regionBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], regionBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetSystemRegionImpl: Failed to get string item");
HILOG_ERROR_I18N("SetSystemRegionImpl: Failed to get string item");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
I18nErrorCode err = I18nServiceAbilityClient::SetSystemRegion(regionBuf.data());
HiLog::Info(LABEL, "I18nSystemAddon::SetSystemRegionImpl with code %{public}d", static_cast<int32_t>(err));
HILOG_INFO_I18N("I18nSystemAddon::SetSystemRegionImpl with code %{public}d", static_cast<int32_t>(err));
bool success = err == I18nErrorCode::SUCCESS;
if (throwError) {
if (!success) {
@ -650,7 +647,7 @@ napi_value I18nSystemAddon::SetSystemRegionImpl(napi_env env, napi_callback_info
napi_value result = nullptr;
status = napi_get_boolean(env, success, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetSystemRegionImpl: Create set system language boolean value failed");
HILOG_ERROR_I18N("SetSystemRegionImpl: Create set system language boolean value failed");
return nullptr;
}
return result;
@ -667,7 +664,7 @@ napi_value I18nSystemAddon::SetSystemLocaleImpl(napi_env env, napi_callback_info
return nullptr;
}
if (argc < 1) {
HiLog::Error(LABEL, "SetSystemLocaleImpl: Missing parameter");
HILOG_ERROR_I18N("SetSystemLocaleImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -676,12 +673,12 @@ napi_value I18nSystemAddon::SetSystemLocaleImpl(napi_env env, napi_callback_info
std::vector<char> localeBuf(len + 1);
status = napi_get_value_string_utf8(env, argv[0], localeBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetSystemLocaleImpl: Failed to get string item");
HILOG_ERROR_I18N("SetSystemLocaleImpl: Failed to get string item");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
I18nErrorCode err = I18nServiceAbilityClient::SetSystemLocale(localeBuf.data());
HiLog::Info(LABEL, "I18nSystemAddon::SetSystemLocaleImpl with code %{public}d", static_cast<int32_t>(err));
HILOG_INFO_I18N("I18nSystemAddon::SetSystemLocaleImpl with code %{public}d", static_cast<int32_t>(err));
bool success = err == I18nErrorCode::SUCCESS;
if (throwError) {
if (!success) {
@ -692,7 +689,7 @@ napi_value I18nSystemAddon::SetSystemLocaleImpl(napi_env env, napi_callback_info
napi_value result = nullptr;
status = napi_get_boolean(env, success, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "SetSystemLocaleImpl: Create set system language boolean value failed");
HILOG_ERROR_I18N("SetSystemLocaleImpl: Create set system language boolean value failed");
return nullptr;
}
return result;
@ -709,7 +706,7 @@ napi_value I18nSystemAddon::Set24HourClockImpl(napi_env env, napi_callback_info
return nullptr;
}
if (argc < 1) {
HiLog::Error(LABEL, "Set24HourClockImpl: Missing parameter");
HILOG_ERROR_I18N("Set24HourClockImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -717,13 +714,13 @@ napi_value I18nSystemAddon::Set24HourClockImpl(napi_env env, napi_callback_info
bool option = false;
status = napi_get_value_bool(env, argv[0], &option);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to get boolean item");
HILOG_ERROR_I18N("Failed to get boolean item");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
std::string optionStr = option ? "true" : "false";
I18nErrorCode err = I18nServiceAbilityClient::Set24HourClock(optionStr);
HiLog::Info(LABEL, "I18nSystemAddon::Set24HourClock with code %{public}d", static_cast<int32_t>(err));
HILOG_INFO_I18N("I18nSystemAddon::Set24HourClock with code %{public}d", static_cast<int32_t>(err));
bool success = err == I18nErrorCode::SUCCESS;
if (throwError) {
if (!success) {
@ -734,7 +731,7 @@ napi_value I18nSystemAddon::Set24HourClockImpl(napi_env env, napi_callback_info
napi_value result = nullptr;
status = napi_get_boolean(env, success, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create set 24HourClock boolean value failed");
HILOG_ERROR_I18N("Create set 24HourClock boolean value failed");
return nullptr;
}
return result;
@ -761,12 +758,12 @@ napi_value I18nSystemAddon::AddPreferredLanguageImpl(napi_env env, napi_callback
status = napi_get_value_int32(env, argv[1], &index);
}
if (status != napi_ok) {
HiLog::Error(LABEL, "addPreferrdLanguage: get index failed");
HILOG_ERROR_I18N("addPreferrdLanguage: get index failed");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
I18nErrorCode err = I18nServiceAbilityClient::AddPreferredLanguage(language.data(), index);
HiLog::Info(LABEL, "I18nSystemAddon::AddPreferredLanguageImpl with code %{public}d", static_cast<int32_t>(err));
HILOG_INFO_I18N("I18nSystemAddon::AddPreferredLanguageImpl with code %{public}d", static_cast<int32_t>(err));
if (throwError) {
if (err == I18nErrorCode::NO_PERMISSION) {
ErrorUtil::NapiThrow(env, I18N_NO_PERMISSION, throwError);
@ -783,7 +780,7 @@ napi_value I18nSystemAddon::AddPreferredLanguageImpl(napi_env env, napi_callback
napi_value result = nullptr;
status = napi_get_boolean(env, addResult, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "addPreferrdLanguage: create boolean result failed");
HILOG_ERROR_I18N("addPreferrdLanguage: create boolean result failed");
return nullptr;
}
return result;
@ -801,7 +798,7 @@ napi_value I18nSystemAddon::RemovePreferredLanguageImpl(napi_env env, napi_callb
return nullptr;
}
if (argc < 1) {
HiLog::Error(LABEL, "RemovePreferredLanguageImpl: Missing parameter");
HILOG_ERROR_I18N("RemovePreferredLanguageImpl: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
@ -815,7 +812,7 @@ napi_value I18nSystemAddon::RemovePreferredLanguageImpl(napi_env env, napi_callb
int index = 1000000;
status = napi_get_value_int32(env, argv[0], &index);
if (status != napi_ok) {
HiLog::Error(LABEL, "removePreferrdLanguage: get index failed");
HILOG_ERROR_I18N("removePreferrdLanguage: get index failed");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
@ -836,7 +833,7 @@ napi_value I18nSystemAddon::RemovePreferredLanguageImpl(napi_env env, napi_callb
napi_value result = nullptr;
status = napi_get_boolean(env, success, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "removePreferrdLanguage: create boolean result failed");
HILOG_ERROR_I18N("removePreferrdLanguage: create boolean result failed");
return nullptr;
}
return result;
@ -851,25 +848,25 @@ napi_value I18nSystemAddon::SetUsingLocalDigitAddonImpl(napi_env env, napi_callb
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
if (argc < 1) {
HiLog::Error(LABEL, "Invalid parameter nullptr");
HILOG_ERROR_I18N("Invalid parameter nullptr");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return nullptr;
}
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_boolean) {
HiLog::Error(LABEL, "Invalid parameter type");
HILOG_ERROR_I18N("Invalid parameter type");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return nullptr;
}
bool flag = false;
napi_status status = napi_get_value_bool(env, argv[0], &flag);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get parameter flag failed");
HILOG_ERROR_I18N("Get parameter flag failed");
return nullptr;
}
I18nErrorCode err = I18nServiceAbilityClient::SetUsingLocalDigit(flag);
HiLog::Info(LABEL, "I18nSystemAddon::SetUsingLocalDigitAddonImpl with code %{public}d",
HILOG_INFO_I18N("I18nSystemAddon::SetUsingLocalDigitAddonImpl with code %{public}d",
static_cast<int32_t>(err));
bool res = err == I18nErrorCode::SUCCESS;
if (throwError) {
@ -881,7 +878,7 @@ napi_value I18nSystemAddon::SetUsingLocalDigitAddonImpl(napi_env env, napi_callb
napi_value value = nullptr;
status = napi_get_boolean(env, res, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Invalid result");
HILOG_ERROR_I18N("Invalid result");
return nullptr;
}
return value;
@ -890,7 +887,7 @@ napi_value I18nSystemAddon::SetUsingLocalDigitAddonImpl(napi_env env, napi_callb
bool I18nSystemAddon::ParseStringParam(napi_env env, napi_value argv, bool throwError, std::string &strParam)
{
if (argv == nullptr) {
HiLog::Error(LABEL, "ParseStringParam: Missing parameter");
HILOG_ERROR_I18N("ParseStringParam: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, throwError);
return false;
}
@ -903,14 +900,14 @@ bool I18nSystemAddon::ParseStringParam(napi_env env, napi_value argv, bool throw
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv, nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "get string parameter length failed");
HILOG_ERROR_I18N("get string parameter length failed");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, throwError);
return false;
}
std::vector<char> res(len + 1);
status = napi_get_value_string_utf8(env, argv, res.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "get string parameter failed");
HILOG_ERROR_I18N("get string parameter failed");
return false;
}
strParam = res.data();

View File

@ -14,7 +14,7 @@
*/
#include "character.h"
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_timezone_addon.h"
#include "js_utils.h"
#include "variable_convertor.h"
@ -22,9 +22,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nTimeZoneAddonJs" };
using namespace OHOS::HiviewDFX;
static thread_local napi_ref* g_timezoneConstructor = nullptr;
I18nTimeZoneAddon::I18nTimeZoneAddon() {}
@ -65,18 +62,18 @@ napi_value I18nTimeZoneAddon::InitI18nTimeZone(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "TimeZone", NAPI_AUTO_LENGTH, I18nTimeZoneConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nTimeZone: Failed to define class TimeZone at Init");
HILOG_ERROR_I18N("InitI18nTimeZone: Failed to define class TimeZone at Init");
return nullptr;
}
exports = I18nTimeZoneAddon::InitTimeZone(env, exports);
g_timezoneConstructor = new (std::nothrow) napi_ref;
if (!g_timezoneConstructor) {
HiLog::Error(LABEL, "InitI18nTimeZone: Failed to create TimeZone ref at init");
HILOG_ERROR_I18N("InitI18nTimeZone: Failed to create TimeZone ref at init");
return nullptr;
}
status = napi_create_reference(env, constructor, 1, g_timezoneConstructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nTimeZone: Failed to create reference g_timezoneConstructor at init");
HILOG_ERROR_I18N("InitI18nTimeZone: Failed to create reference g_timezoneConstructor at init");
return nullptr;
}
return exports;
@ -95,12 +92,12 @@ napi_value I18nTimeZoneAddon::InitTimeZone(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "I18nTimeZone", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitTimeZone: Failed to define class TimeZone.");
HILOG_ERROR_I18N("InitTimeZone: Failed to define class TimeZone.");
return nullptr;
}
status = napi_set_named_property(env, exports, "TimeZone", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitTimeZone: Set property failed When InitTimeZone.");
HILOG_ERROR_I18N("InitTimeZone: Set property failed When InitTimeZone.");
return nullptr;
}
return exports;
@ -165,7 +162,7 @@ napi_value I18nTimeZoneAddon::GetAvailableTimezoneIDs(napi_env env, napi_callbac
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, timezoneIDs.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetAvailableTimezoneIDs: Failed to create array");
HILOG_ERROR_I18N("GetAvailableTimezoneIDs: Failed to create array");
return nullptr;
}
size_t index = 0;
@ -173,12 +170,12 @@ napi_value I18nTimeZoneAddon::GetAvailableTimezoneIDs(napi_env env, napi_callbac
napi_value value = nullptr;
status = napi_create_string_utf8(env, (*it).c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create string item");
HILOG_ERROR_I18N("Failed to create string item");
return nullptr;
}
status = napi_set_element(env, result, index, value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set array item");
HILOG_ERROR_I18N("Failed to set array item");
return nullptr;
}
++index;
@ -192,7 +189,7 @@ napi_value I18nTimeZoneAddon::GetAvailableZoneCityIDs(napi_env env, napi_callbac
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, cityIDs.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetAvailableZoneCityIDs: Failed to create array");
HILOG_ERROR_I18N("GetAvailableZoneCityIDs: Failed to create array");
return nullptr;
}
size_t index = 0;
@ -200,12 +197,12 @@ napi_value I18nTimeZoneAddon::GetAvailableZoneCityIDs(napi_env env, napi_callbac
napi_value value = nullptr;
status = napi_create_string_utf8(env, (*it).c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetAvailableZoneCityIDs: Failed to create string item");
HILOG_ERROR_I18N("GetAvailableZoneCityIDs: Failed to create string item");
return nullptr;
}
status = napi_set_element(env, result, index, value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetAvailableZoneCityIDs: Failed to set array item");
HILOG_ERROR_I18N("GetAvailableZoneCityIDs: Failed to set array item");
return nullptr;
}
++index;
@ -229,7 +226,7 @@ napi_value I18nTimeZoneAddon::GetCityDisplayName(napi_env env, napi_callback_inf
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_string) {
HiLog::Error(LABEL, "GetCityDisplayName: Invalid parameter type");
HILOG_ERROR_I18N("GetCityDisplayName: Invalid parameter type");
return nullptr;
}
int32_t code = 0;
@ -271,7 +268,7 @@ napi_value I18nTimeZoneAddon::GetTimezonesByLocation(napi_env env, napi_callback
return nullptr;
}
if (argc < FUNC_ARGS_COUNT) {
HiLog::Error(LABEL, "GetTimezonesByLocation: Missing parameter");
HILOG_ERROR_I18N("GetTimezonesByLocation: Missing parameter");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
@ -305,17 +302,17 @@ bool I18nTimeZoneAddon::CheckParamTypeAndScope(napi_env env, napi_value *argv, d
{
napi_status status = napi_get_value_double(env, argv[0], &x);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetTimezonesByLocation: Parse first argument x failed");
HILOG_ERROR_I18N("GetTimezonesByLocation: Parse first argument x failed");
return false;
}
status = napi_get_value_double(env, argv[1], &y);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetTimezonesByLocation: Parse second argument y failed");
HILOG_ERROR_I18N("GetTimezonesByLocation: Parse second argument y failed");
return false;
}
// -180 and 179.9 is the scope of longitude, -90 and 89.9 is the scope of latitude
if (x < -180 || x > 179.9 || y < -90 || y > 89.9) {
HiLog::Error(LABEL, "GetTimezonesByLocation: Args x or y exceed it's scope.");
HILOG_ERROR_I18N("GetTimezonesByLocation: Args x or y exceed it's scope.");
return false;
}
return true;
@ -331,14 +328,14 @@ napi_value I18nTimeZoneAddon::GetID(napi_env env, napi_callback_info info)
I18nTimeZoneAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->timezone_) {
HiLog::Error(LABEL, "GetID: Get TimeZone object failed");
HILOG_ERROR_I18N("GetID: Get TimeZone object failed");
return nullptr;
}
std::string result = obj->timezone_->GetID();
napi_value value = nullptr;
status = napi_create_string_utf8(env, result.c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetID: Create result failed");
HILOG_ERROR_I18N("GetID: Create result failed");
return nullptr;
}
return value;
@ -358,7 +355,7 @@ napi_value I18nTimeZoneAddon::GetTimeZoneDisplayName(napi_env env, napi_callback
I18nTimeZoneAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->timezone_) {
HiLog::Error(LABEL, "GetTimeZoneDisplayName: Get TimeZone object failed");
HILOG_ERROR_I18N("GetTimeZoneDisplayName: Get TimeZone object failed");
return nullptr;
}
@ -383,7 +380,7 @@ napi_value I18nTimeZoneAddon::GetTimeZoneDisplayName(napi_env env, napi_callback
napi_value value = nullptr;
status = napi_create_string_utf8(env, result.c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetTimeZoneDisplayName: Create result failed");
HILOG_ERROR_I18N("GetTimeZoneDisplayName: Create result failed");
return nullptr;
}
return value;
@ -399,14 +396,14 @@ napi_value I18nTimeZoneAddon::GetRawOffset(napi_env env, napi_callback_info info
I18nTimeZoneAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->timezone_) {
HiLog::Error(LABEL, "GetRawOffset: Get TimeZone object failed");
HILOG_ERROR_I18N("GetRawOffset: Get TimeZone object failed");
return nullptr;
}
int32_t result = obj->timezone_->GetRawOffset();
napi_value value = nullptr;
status = napi_create_int32(env, result, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetRawOffset: Create result failed");
HILOG_ERROR_I18N("GetRawOffset: Create result failed");
return nullptr;
}
return value;
@ -428,12 +425,12 @@ napi_value I18nTimeZoneAddon::GetOffset(napi_env env, napi_callback_info info)
napi_valuetype valueType = napi_valuetype::napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_valuetype::napi_number) {
HiLog::Error(LABEL, "GetOffset: Invalid parameter type");
HILOG_ERROR_I18N("GetOffset: Invalid parameter type");
return nullptr;
}
status = napi_get_value_double(env, argv[0], &date);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get parameter date failed");
HILOG_ERROR_I18N("Get parameter date failed");
return nullptr;
}
} else {
@ -446,14 +443,14 @@ napi_value I18nTimeZoneAddon::GetOffset(napi_env env, napi_callback_info info)
I18nTimeZoneAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->timezone_) {
HiLog::Error(LABEL, "GetOffset: Get TimeZone object failed");
HILOG_ERROR_I18N("GetOffset: Get TimeZone object failed");
return nullptr;
}
int32_t result = obj->timezone_->GetOffset(date);
napi_value value = nullptr;
status = napi_create_int32(env, result, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetOffset: Create result failed");
HILOG_ERROR_I18N("GetOffset: Create result failed");
return nullptr;
}
return value;
@ -464,7 +461,7 @@ napi_value I18nTimeZoneAddon::StaticGetTimeZone(napi_env env, napi_value *argv,
napi_value constructor = nullptr;
napi_status status = napi_get_reference_value(env, *g_timezoneConstructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference at StaticGetTimeZone");
HILOG_ERROR_I18N("Failed to create reference at StaticGetTimeZone");
return nullptr;
}
napi_value newArgv[2] = { 0 };
@ -476,7 +473,7 @@ napi_value I18nTimeZoneAddon::StaticGetTimeZone(napi_env env, napi_value *argv,
napi_value result = nullptr;
status = napi_new_instance(env, constructor, 2, newArgv, &result); // 2 is parameter num
if (status != napi_ok) {
HiLog::Error(LABEL, "StaticGetTimeZone create instance failed");
HILOG_ERROR_I18N("StaticGetTimeZone create instance failed");
return nullptr;
}
return result;
@ -513,13 +510,13 @@ bool I18nTimeZoneAddon::GetStringFromJS(napi_env env, napi_value argv, std::stri
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv, nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to get string length");
HILOG_ERROR_I18N("Failed to get string length");
return false;
}
std::vector<char> argvBuf(len + 1);
status = napi_get_value_string_utf8(env, argv, argvBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to get string item");
HILOG_ERROR_I18N("Failed to get string item");
return false;
}
jsString = argvBuf.data();

View File

@ -14,7 +14,7 @@
*/
#include "character.h"
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_unicode_addon.h"
#include "js_utils.h"
#include "variable_convertor.h"
@ -22,9 +22,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nUnicodeAddonJs" };
using namespace OHOS::HiviewDFX;
I18nUnicodeAddon::I18nUnicodeAddon() {}
I18nUnicodeAddon::~I18nUnicodeAddon() {}
@ -55,13 +52,13 @@ napi_value I18nUnicodeAddon::InitI18nUnicode(napi_env env, napi_value exports)
napi_status status = napi_define_class(env, "Unicode", NAPI_AUTO_LENGTH, JSUtils::DefaultConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nUnicode: Define class failed when InitUnicode.");
HILOG_ERROR_I18N("InitI18nUnicode: Define class failed when InitUnicode.");
return nullptr;
}
status = napi_set_named_property(env, exports, "Unicode", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitI18nUnicode: Set property failed when InitUnicode.");
HILOG_ERROR_I18N("InitI18nUnicode: Set property failed when InitUnicode.");
return nullptr;
}
return exports;
@ -86,13 +83,13 @@ napi_value I18nUnicodeAddon::InitCharacter(napi_env env, napi_value exports)
status = napi_define_class(env, "Character", NAPI_AUTO_LENGTH, ObjectConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitCharacter");
HILOG_ERROR_I18N("Define class failed when InitCharacter");
return nullptr;
}
status = napi_set_named_property(env, exports, "Character", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitCharacter");
HILOG_ERROR_I18N("Set property failed when InitCharacter");
return nullptr;
}
return exports;
@ -123,7 +120,7 @@ napi_value I18nUnicodeAddon::IsDigitAddon(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_get_boolean(env, isDigit, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isDigit boolean value failed");
HILOG_ERROR_I18N("Create isDigit boolean value failed");
return nullptr;
}
return result;
@ -154,7 +151,7 @@ napi_value I18nUnicodeAddon::IsSpaceCharAddon(napi_env env, napi_callback_info i
napi_value result = nullptr;
status = napi_get_boolean(env, isSpaceChar, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isSpaceChar boolean value failed");
HILOG_ERROR_I18N("Create isSpaceChar boolean value failed");
return nullptr;
}
return result;
@ -185,7 +182,7 @@ napi_value I18nUnicodeAddon::IsWhiteSpaceAddon(napi_env env, napi_callback_info
napi_value result = nullptr;
status = napi_get_boolean(env, isWhiteSpace, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isWhiteSpace boolean value failed");
HILOG_ERROR_I18N("Create isWhiteSpace boolean value failed");
return nullptr;
}
return result;
@ -216,7 +213,7 @@ napi_value I18nUnicodeAddon::IsRTLCharacterAddon(napi_env env, napi_callback_inf
napi_value result = nullptr;
status = napi_get_boolean(env, isRTLCharacter, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isRTLCharacter boolean value failed");
HILOG_ERROR_I18N("Create isRTLCharacter boolean value failed");
return nullptr;
}
return result;
@ -247,7 +244,7 @@ napi_value I18nUnicodeAddon::IsIdeoGraphicAddon(napi_env env, napi_callback_info
napi_value result = nullptr;
status = napi_get_boolean(env, isIdeoGraphic, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isIdeoGraphic boolean value failed");
HILOG_ERROR_I18N("Create isIdeoGraphic boolean value failed");
return nullptr;
}
return result;
@ -278,7 +275,7 @@ napi_value I18nUnicodeAddon::IsLetterAddon(napi_env env, napi_callback_info info
napi_value result = nullptr;
status = napi_get_boolean(env, isLetter, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isLetter boolean value failed");
HILOG_ERROR_I18N("Create isLetter boolean value failed");
return nullptr;
}
return result;
@ -309,7 +306,7 @@ napi_value I18nUnicodeAddon::IsLowerCaseAddon(napi_env env, napi_callback_info i
napi_value result = nullptr;
status = napi_get_boolean(env, isLowerCase, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isLowerCase boolean value failed");
HILOG_ERROR_I18N("Create isLowerCase boolean value failed");
return nullptr;
}
return result;
@ -340,7 +337,7 @@ napi_value I18nUnicodeAddon::IsUpperCaseAddon(napi_env env, napi_callback_info i
napi_value result = nullptr;
status = napi_get_boolean(env, isUpperCase, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create isUpperCase boolean value failed");
HILOG_ERROR_I18N("Create isUpperCase boolean value failed");
return nullptr;
}
return result;
@ -371,7 +368,7 @@ napi_value I18nUnicodeAddon::GetTypeAddon(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, type.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create getType string value failed");
HILOG_ERROR_I18N("Create getType string value failed");
return nullptr;
}
return result;
@ -390,7 +387,7 @@ napi_value I18nUnicodeAddon::ObjectConstructor(napi_env env, napi_callback_info
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), I18nUnicodeAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "Wrap I18nAddon failed");
HILOG_ERROR_I18N("Wrap I18nAddon failed");
return nullptr;
}
obj.release();

View File

@ -18,15 +18,13 @@
#include <vector>
#include <set>
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "js_utils.h"
#include "node_api.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "IntlJs" };
using namespace OHOS::HiviewDFX;
static thread_local napi_ref *g_constructor = nullptr;
IntlAddon::IntlAddon() : env_(nullptr) {}
@ -75,23 +73,23 @@ napi_value IntlAddon::InitLocale(napi_env env, napi_value exports)
status = napi_define_class(env, "Locale", NAPI_AUTO_LENGTH, LocaleConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitLocale");
HILOG_ERROR_I18N("Define class failed when InitLocale");
return nullptr;
}
status = napi_set_named_property(env, exports, "Locale", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitLocale");
HILOG_ERROR_I18N("Set property failed when InitLocale");
return nullptr;
}
g_constructor = new (std::nothrow) napi_ref;
if (!g_constructor) {
HiLog::Error(LABEL, "Failed to create ref at init");
HILOG_ERROR_I18N("Failed to create ref at init");
return nullptr;
}
status = napi_create_reference(env, constructor, 1, g_constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create reference at init");
HILOG_ERROR_I18N("Failed to create reference at init");
return nullptr;
}
return exports;
@ -110,13 +108,13 @@ napi_value IntlAddon::InitDateTimeFormat(napi_env env, napi_value exports)
status = napi_define_class(env, "DateTimeFormat", NAPI_AUTO_LENGTH, DateTimeFormatConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitDateTimeFormat");
HILOG_ERROR_I18N("Define class failed when InitDateTimeFormat");
return nullptr;
}
status = napi_set_named_property(env, exports, "DateTimeFormat", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitDateTimeFormat");
HILOG_ERROR_I18N("Set property failed when InitDateTimeFormat");
return nullptr;
}
return exports;
@ -135,13 +133,13 @@ napi_value IntlAddon::InitRelativeTimeFormat(napi_env env, napi_value exports)
status = napi_define_class(env, "RelativeTimeFormat", NAPI_AUTO_LENGTH, RelativeTimeFormatConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitRelativeTimeFormat");
HILOG_ERROR_I18N("Define class failed when InitRelativeTimeFormat");
return nullptr;
}
status = napi_set_named_property(env, exports, "RelativeTimeFormat", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitRelativeTimeFormat");
HILOG_ERROR_I18N("Set property failed when InitRelativeTimeFormat");
return nullptr;
}
return exports;
@ -159,13 +157,13 @@ napi_value IntlAddon::InitNumberFormat(napi_env env, napi_value exports)
status = napi_define_class(env, "NumberFormat", NAPI_AUTO_LENGTH, NumberFormatConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitNumberFormat");
HILOG_ERROR_I18N("Define class failed when InitNumberFormat");
return nullptr;
}
status = napi_set_named_property(env, exports, "NumberFormat", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitNumberFormat");
HILOG_ERROR_I18N("Set property failed when InitNumberFormat");
return nullptr;
}
return exports;
@ -178,7 +176,7 @@ void GetOptionValue(napi_env env, napi_value options, const std::string &optionN
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, options, &type);
if (status != napi_ok && type != napi_object) {
HiLog::Error(LABEL, "Get option failed, option is not an object");
HILOG_ERROR_I18N("Get option failed, option is not an object");
return;
}
bool hasProperty = false;
@ -206,7 +204,7 @@ int64_t GetIntegerOptionValue(napi_env env, napi_value options, const std::strin
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, options, &type);
if (status != napi_ok && type != napi_object) {
HiLog::Error(LABEL, "GetIntegerOptionValue: Set option failed, option is not an object");
HILOG_ERROR_I18N("GetIntegerOptionValue: Set option failed, option is not an object");
return integerValue;
}
bool hasProperty = false;
@ -230,7 +228,7 @@ void GetBoolOptionValue(napi_env env, napi_value options, const std::string &opt
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, options, &type);
if (status != napi_ok && type != napi_object) {
HiLog::Error(LABEL, "GetBoolOptionValue: Set option failed, option is not an object");
HILOG_ERROR_I18N("GetBoolOptionValue: Set option failed, option is not an object");
return;
}
bool hasProperty = false;
@ -290,13 +288,13 @@ std::string GetLocaleTag(napi_env env, napi_value argv)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, argv, nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetLocaleTag -> string: Get locale tag length failed");
HILOG_ERROR_I18N("GetLocaleTag -> string: Get locale tag length failed");
return "";
}
buf.resize(len + 1);
status = napi_get_value_string_utf8(env, argv, buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetLocaleTag: Get locale tag failed");
HILOG_ERROR_I18N("GetLocaleTag: Get locale tag failed");
return "";
}
localeTag = buf.data();
@ -332,7 +330,7 @@ napi_value IntlAddon::LocaleConstructor(napi_env env, napi_callback_info info)
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), IntlAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "LocaleConstructor: Wrap IntlAddon failed");
HILOG_ERROR_I18N("LocaleConstructor: Wrap IntlAddon failed");
return nullptr;
}
if (!obj->InitLocaleContext(env, info, localeTag, map)) {
@ -348,7 +346,7 @@ bool IntlAddon::InitLocaleContext(napi_env env, napi_callback_info info, const s
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitLocaleContext: Get global failed");
HILOG_ERROR_I18N("InitLocaleContext: Get global failed");
return false;
}
env_ = env;
@ -362,13 +360,13 @@ void GetLocaleTags(napi_env env, napi_value rawLocaleTag, std::vector<std::strin
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, rawLocaleTag, nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetLocaleTag -> void: Get locale tag length failed");
HILOG_ERROR_I18N("GetLocaleTag -> void: Get locale tag length failed");
return;
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, rawLocaleTag, buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetLocaleTags: Get locale tag failed");
HILOG_ERROR_I18N("GetLocaleTags: Get locale tag failed");
return;
}
localeTags.push_back(buf.data());
@ -411,11 +409,11 @@ napi_value IntlAddon::DateTimeFormatConstructor(napi_env env, napi_callback_info
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), IntlAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "DateTimeFormatConstructor: Wrap IntlAddon failed");
HILOG_ERROR_I18N("DateTimeFormatConstructor: Wrap IntlAddon failed");
return nullptr;
}
if (!obj->InitDateTimeFormatContext(env, info, localeTags, map)) {
HiLog::Error(LABEL, "DateTimeFormatConstructor: Init DateTimeFormat failed");
HILOG_ERROR_I18N("DateTimeFormatConstructor: Init DateTimeFormat failed");
return nullptr;
}
obj.release();
@ -428,7 +426,7 @@ bool IntlAddon::InitDateTimeFormatContext(napi_env env, napi_callback_info info,
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitDateTimeFormatContext: Get global failed");
HILOG_ERROR_I18N("InitDateTimeFormatContext: Get global failed");
return false;
}
env_ = env;
@ -474,11 +472,11 @@ napi_value IntlAddon::RelativeTimeFormatConstructor(napi_env env, napi_callback_
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), IntlAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "RelativeTimeFormatConstructor: Wrap IntlAddon failed");
HILOG_ERROR_I18N("RelativeTimeFormatConstructor: Wrap IntlAddon failed");
return nullptr;
}
if (!obj->InitRelativeTimeFormatContext(env, info, localeTags, map)) {
HiLog::Error(LABEL, "Init RelativeTimeFormat failed");
HILOG_ERROR_I18N("Init RelativeTimeFormat failed");
return nullptr;
}
obj.release();
@ -509,14 +507,14 @@ napi_value IntlAddon::FormatDateTime(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->datefmt_) {
HiLog::Error(LABEL, "FormatDateTime: Get DateTimeFormat object failed");
HILOG_ERROR_I18N("FormatDateTime: Get DateTimeFormat object failed");
return nullptr;
}
std::string value = obj->datefmt_->Format(milliseconds);
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "FormatDateTime: Create format string failed");
HILOG_ERROR_I18N("FormatDateTime: Create format string failed");
return nullptr;
}
return result;
@ -530,7 +528,7 @@ napi_value IntlAddon::FormatDateTimeRange(napi_env env, napi_callback_info info)
void *data = nullptr;
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
if (argc < FUNC_ARGS_COUNT) {
HiLog::Error(LABEL, "Parameter wrong");
HILOG_ERROR_I18N("Parameter wrong");
return nullptr;
}
int64_t firstMilliseconds = GetMilliseconds(env, argv, 0);
@ -541,14 +539,14 @@ napi_value IntlAddon::FormatDateTimeRange(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->datefmt_) {
HiLog::Error(LABEL, "FormatDateTimeRange: Get DateTimeFormat object failed");
HILOG_ERROR_I18N("FormatDateTimeRange: Get DateTimeFormat object failed");
return nullptr;
}
std::string value = obj->datefmt_->FormatRange(firstMilliseconds, secondMilliseconds);
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "FormatDateTimeRange: Create format string failed");
HILOG_ERROR_I18N("FormatDateTimeRange: Create format string failed");
return nullptr;
}
return result;
@ -573,7 +571,7 @@ void GetNumberOptionValues(napi_env env, napi_value options, std::map<std::strin
int64_t minFd = GetIntegerOptionValue(env, options, "minimumFractionDigits", map);
int64_t maxFd = GetIntegerOptionValue(env, options, "maximumFractionDigits", map);
if (minFd != -1 && maxFd != -1 && minFd > maxFd) {
HiLog::Error(LABEL,
HILOG_ERROR_I18N(
"GetNumberOptionValues: Invalid parameter value: minimumFractionDigits > maximumFractionDigits");
}
GetIntegerOptionValue(env, options, "minimumSignificantDigits", map);
@ -618,11 +616,11 @@ napi_value IntlAddon::NumberFormatConstructor(napi_env env, napi_callback_info i
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), IntlAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "NumberFormatConstructor: Wrap IntlAddon failed");
HILOG_ERROR_I18N("NumberFormatConstructor: Wrap IntlAddon failed");
return nullptr;
}
if (!obj->InitNumberFormatContext(env, info, localeTags, map)) {
HiLog::Error(LABEL, "Init NumberFormat failed");
HILOG_ERROR_I18N("Init NumberFormat failed");
return nullptr;
}
obj.release();
@ -635,7 +633,7 @@ bool IntlAddon::InitNumberFormatContext(napi_env env, napi_callback_info info, s
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitNumberFormatContext: Get global failed");
HILOG_ERROR_I18N("InitNumberFormatContext: Get global failed");
return false;
}
env_ = env;
@ -649,19 +647,19 @@ int64_t IntlAddon::GetMilliseconds(napi_env env, napi_value *argv, int index)
napi_value funcGetDateInfo = nullptr;
napi_status status = napi_get_named_property(env, argv[index], "getTime", &funcGetDateInfo);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get Milliseconds property failed");
HILOG_ERROR_I18N("Get Milliseconds property failed");
return -1;
}
napi_value ret_value = nullptr;
status = napi_call_function(env, argv[index], funcGetDateInfo, 0, nullptr, &ret_value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get Milliseconds function failed");
HILOG_ERROR_I18N("Get Milliseconds function failed");
return -1;
}
int64_t milliseconds = 0;
status = napi_get_value_int64(env, ret_value, &milliseconds);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get Milliseconds failed");
HILOG_ERROR_I18N("Get Milliseconds failed");
return -1;
}
return milliseconds;
@ -676,7 +674,7 @@ napi_value IntlAddon::GetLanguage(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetLanguage: Get Locale object failed");
HILOG_ERROR_I18N("GetLanguage: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetLanguage();
@ -684,7 +682,7 @@ napi_value IntlAddon::GetLanguage(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetLanguage: Create language string failed");
HILOG_ERROR_I18N("GetLanguage: Create language string failed");
return nullptr;
}
return result;
@ -699,7 +697,7 @@ napi_value IntlAddon::GetScript(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetScript: Get Locale object failed");
HILOG_ERROR_I18N("GetScript: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetScript();
@ -707,7 +705,7 @@ napi_value IntlAddon::GetScript(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create script string failed");
HILOG_ERROR_I18N("Create script string failed");
return nullptr;
}
return result;
@ -722,7 +720,7 @@ napi_value IntlAddon::GetRegion(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetRegion: Get Locale object failed");
HILOG_ERROR_I18N("GetRegion: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetRegion();
@ -730,7 +728,7 @@ napi_value IntlAddon::GetRegion(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create region string failed");
HILOG_ERROR_I18N("Create region string failed");
return nullptr;
}
return result;
@ -745,7 +743,7 @@ napi_value IntlAddon::GetBaseName(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetBaseName: Get Locale object failed");
HILOG_ERROR_I18N("GetBaseName: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetBaseName();
@ -753,7 +751,7 @@ napi_value IntlAddon::GetBaseName(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetBaseName: Create base name string failed");
HILOG_ERROR_I18N("GetBaseName: Create base name string failed");
return nullptr;
}
return result;
@ -768,7 +766,7 @@ napi_value IntlAddon::GetCalendar(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetCalendar: Get Locale object failed");
HILOG_ERROR_I18N("GetCalendar: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetCalendar();
@ -776,7 +774,7 @@ napi_value IntlAddon::GetCalendar(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetCalendar: Create base name string failed");
HILOG_ERROR_I18N("GetCalendar: Create base name string failed");
return nullptr;
}
return result;
@ -791,7 +789,7 @@ napi_value IntlAddon::GetCollation(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetCollation: Get Locale object failed");
HILOG_ERROR_I18N("GetCollation: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetCollation();
@ -799,7 +797,7 @@ napi_value IntlAddon::GetCollation(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetCollation: Create base name string failed");
HILOG_ERROR_I18N("GetCollation: Create base name string failed");
return nullptr;
}
return result;
@ -814,7 +812,7 @@ napi_value IntlAddon::GetHourCycle(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetHourCycle: Get Locale object failed");
HILOG_ERROR_I18N("GetHourCycle: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetHourCycle();
@ -822,7 +820,7 @@ napi_value IntlAddon::GetHourCycle(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetHourCycle: Create base name string failed");
HILOG_ERROR_I18N("GetHourCycle: Create base name string failed");
return nullptr;
}
return result;
@ -837,7 +835,7 @@ napi_value IntlAddon::GetNumberingSystem(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetNumberingSystem: Get Locale object failed");
HILOG_ERROR_I18N("GetNumberingSystem: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetNumberingSystem();
@ -845,7 +843,7 @@ napi_value IntlAddon::GetNumberingSystem(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetNumberingSystem: Create base name string failed");
HILOG_ERROR_I18N("GetNumberingSystem: Create base name string failed");
return nullptr;
}
return result;
@ -860,7 +858,7 @@ napi_value IntlAddon::GetNumeric(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetNumeric: Get Locale object failed");
HILOG_ERROR_I18N("GetNumeric: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetNumeric();
@ -868,7 +866,7 @@ napi_value IntlAddon::GetNumeric(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_get_boolean(env, optionBoolValue, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create numeric boolean value failed");
HILOG_ERROR_I18N("Create numeric boolean value failed");
return nullptr;
}
return result;
@ -883,14 +881,14 @@ napi_value IntlAddon::GetCaseFirst(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "GetCaseFirst: Get Locale object failed");
HILOG_ERROR_I18N("GetCaseFirst: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->GetCaseFirst();
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create caseFirst string failed");
HILOG_ERROR_I18N("Create caseFirst string failed");
return nullptr;
}
return result;
@ -905,7 +903,7 @@ napi_value IntlAddon::ToString(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "ToString: Get Locale object failed");
HILOG_ERROR_I18N("ToString: Get Locale object failed");
return nullptr;
}
std::string value = obj->locale_->ToString();
@ -913,7 +911,7 @@ napi_value IntlAddon::ToString(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "ToString: Create language string failed");
HILOG_ERROR_I18N("ToString: Create language string failed");
return nullptr;
}
return result;
@ -928,7 +926,7 @@ napi_value IntlAddon::Maximize(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "Maximize: Get Locale object failed");
HILOG_ERROR_I18N("Maximize: Get Locale object failed");
return nullptr;
}
std::string localeTag = obj->locale_->Maximize();
@ -936,19 +934,19 @@ napi_value IntlAddon::Maximize(napi_env env, napi_callback_info info)
napi_value constructor = nullptr;
status = napi_get_reference_value(env, *g_constructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Maximize: Get locale constructor reference failed");
HILOG_ERROR_I18N("Maximize: Get locale constructor reference failed");
return nullptr;
}
napi_value result = nullptr;
napi_value arg = nullptr;
status = napi_create_string_utf8(env, localeTag.c_str(), NAPI_AUTO_LENGTH, &arg);
if (status != napi_ok) {
HiLog::Error(LABEL, "Maximize: Create localeTag string failed");
HILOG_ERROR_I18N("Maximize: Create localeTag string failed");
return nullptr;
}
status = napi_new_instance(env, constructor, 1, &arg, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Maximize: Create new locale instance failed");
HILOG_ERROR_I18N("Maximize: Create new locale instance failed");
return nullptr;
}
return result;
@ -963,7 +961,7 @@ napi_value IntlAddon::Minimize(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->locale_) {
HiLog::Error(LABEL, "Minimize: Get Locale object failed");
HILOG_ERROR_I18N("Minimize: Get Locale object failed");
return nullptr;
}
std::string localeTag = obj->locale_->Minimize();
@ -971,19 +969,19 @@ napi_value IntlAddon::Minimize(napi_env env, napi_callback_info info)
napi_value constructor = nullptr;
status = napi_get_reference_value(env, *g_constructor, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Minimize: Get locale constructor reference failed");
HILOG_ERROR_I18N("Minimize: Get locale constructor reference failed");
return nullptr;
}
napi_value result = nullptr;
napi_value arg = nullptr;
status = napi_create_string_utf8(env, localeTag.c_str(), NAPI_AUTO_LENGTH, &arg);
if (status != napi_ok) {
HiLog::Error(LABEL, "Minimize: Create localeTag string failed");
HILOG_ERROR_I18N("Minimize: Create localeTag string failed");
return nullptr;
}
status = napi_new_instance(env, constructor, 1, &arg, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Minimize: Create new locale instance failed");
HILOG_ERROR_I18N("Minimize: Create new locale instance failed");
return nullptr;
}
return result;
@ -1045,7 +1043,7 @@ napi_value IntlAddon::GetRelativeTimeResolvedOptions(napi_env env, napi_callback
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->relativetimefmt_) {
HiLog::Error(LABEL, "GetRelativeTimeResolvedOptions: Get RelativeTimeFormat object failed");
HILOG_ERROR_I18N("GetRelativeTimeResolvedOptions: Get RelativeTimeFormat object failed");
return nullptr;
}
napi_value result = nullptr;
@ -1068,7 +1066,7 @@ napi_value IntlAddon::GetDateTimeResolvedOptions(napi_env env, napi_callback_inf
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->datefmt_) {
HiLog::Error(LABEL, "GetDateTimeResolvedOptions: Get DateTimeFormat object failed");
HILOG_ERROR_I18N("GetDateTimeResolvedOptions: Get DateTimeFormat object failed");
return nullptr;
}
napi_value result = nullptr;
@ -1107,7 +1105,7 @@ napi_value IntlAddon::GetNumberResolvedOptions(napi_env env, napi_callback_info
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->numberfmt_) {
HiLog::Error(LABEL, "GetNumberResolvedOptions: Get NumberFormat object failed");
HILOG_ERROR_I18N("GetNumberResolvedOptions: Get NumberFormat object failed");
return nullptr;
}
napi_value result = nullptr;
@ -1148,14 +1146,14 @@ napi_value IntlAddon::FormatNumber(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->numberfmt_) {
HiLog::Error(LABEL, "FormatNumber: Get NumberFormat object failed");
HILOG_ERROR_I18N("FormatNumber: Get NumberFormat object failed");
return nullptr;
}
std::string value = obj->numberfmt_->Format(number);
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "FormatNumber: Create format string failed");
HILOG_ERROR_I18N("FormatNumber: Create format string failed");
return nullptr;
}
return result;
@ -1168,7 +1166,7 @@ void GetCollatorLocaleMatcher(napi_env env, napi_value options, std::map<std::st
if (it != map.end()) {
std::string localeMatcher = it->second;
if (localeMatcher != "lookup" && localeMatcher != "best fit") {
HiLog::Error(LABEL, "invalid localeMatcher");
HILOG_ERROR_I18N("invalid localeMatcher");
return;
}
} else {
@ -1183,7 +1181,7 @@ void GetCollatorUsage(napi_env env, napi_value options, std::map<std::string, st
if (it != map.end()) {
std::string usage = it->second;
if (usage != "sort" && usage != "search") {
HiLog::Error(LABEL, "invalid usage");
HILOG_ERROR_I18N("invalid usage");
return;
}
} else {
@ -1198,7 +1196,7 @@ void GetCollatorSensitivity(napi_env env, napi_value options, std::map<std::stri
if (it != map.end()) {
std::string sensitivity = it->second;
if (sensitivity != "base" && sensitivity != "accent" && sensitivity != "case" && sensitivity != "variant") {
HiLog::Error(LABEL, "invalid sensitivity");
HILOG_ERROR_I18N("invalid sensitivity");
return;
}
} else {
@ -1213,7 +1211,7 @@ void GetCollatorIgnorePunctuation(napi_env env, napi_value options, std::map<std
if (it != map.end()) {
std::string ignorePunctuation = it->second;
if (ignorePunctuation != "true" && ignorePunctuation != "false") {
HiLog::Error(LABEL, "invalid ignorePunctuation");
HILOG_ERROR_I18N("invalid ignorePunctuation");
return;
}
} else {
@ -1228,7 +1226,7 @@ void GetCollatorNumeric(napi_env env, napi_value options, std::map<std::string,
if (it != map.end()) {
std::string numeric = it->second;
if (numeric != "true" && numeric != "false") {
HiLog::Error(LABEL, "invalid numeric");
HILOG_ERROR_I18N("invalid numeric");
return;
}
}
@ -1241,7 +1239,7 @@ void GetCollatorCaseFirst(napi_env env, napi_value options, std::map<std::string
if (it != map.end()) {
std::string caseFirst = it->second;
if (caseFirst != "upper" && caseFirst != "lower" && caseFirst != "false") {
HiLog::Error(LABEL, "invalid caseFirst");
HILOG_ERROR_I18N("invalid caseFirst");
return;
}
}
@ -1299,13 +1297,13 @@ napi_value IntlAddon::InitCollator(napi_env env, napi_value exports)
status = napi_define_class(env, "Collator", NAPI_AUTO_LENGTH, CollatorConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitCollator");
HILOG_ERROR_I18N("Define class failed when InitCollator");
return nullptr;
}
status = napi_set_named_property(env, exports, "Collator", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitCollator");
HILOG_ERROR_I18N("Set property failed when InitCollator");
return nullptr;
}
return exports;
@ -1348,11 +1346,11 @@ napi_value IntlAddon::CollatorConstructor(napi_env env, napi_callback_info info)
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), IntlAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "CollatorConstructor: Wrap IntlAddon failed");
HILOG_ERROR_I18N("CollatorConstructor: Wrap IntlAddon failed");
return nullptr;
}
if (!obj->InitCollatorContext(env, info, localeTags, map)) {
HiLog::Error(LABEL, "CollatorConstructor: Init DateTimeFormat failed");
HILOG_ERROR_I18N("CollatorConstructor: Init DateTimeFormat failed");
return nullptr;
}
obj.release();
@ -1365,7 +1363,7 @@ bool IntlAddon::InitCollatorContext(napi_env env, napi_callback_info info, std::
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitCollatorContext: Get global failed");
HILOG_ERROR_I18N("InitCollatorContext: Get global failed");
return false;
}
env_ = env;
@ -1385,13 +1383,13 @@ bool GetStringParameter(napi_env env, napi_value value, std::vector<char> &buf)
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, value, nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get first length failed");
HILOG_ERROR_I18N("Get first length failed");
return false;
}
buf.resize(len + 1);
status = napi_get_value_string_utf8(env, value, buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get first failed");
HILOG_ERROR_I18N("Get first failed");
return false;
}
@ -1409,7 +1407,7 @@ napi_value IntlAddon::FormatRelativeTime(napi_env env, napi_callback_info info)
double number;
status = napi_get_value_double(env, argv[0], &number);
if (status != napi_ok) {
HiLog::Error(LABEL, "FormatRelativeTime: Get number failed");
HILOG_ERROR_I18N("FormatRelativeTime: Get number failed");
return nullptr;
}
std::vector<char> unit;
@ -1419,14 +1417,14 @@ napi_value IntlAddon::FormatRelativeTime(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->relativetimefmt_) {
HiLog::Error(LABEL, "FormatRelativeTime: Get RelativeTimeFormat object failed");
HILOG_ERROR_I18N("FormatRelativeTime: Get RelativeTimeFormat object failed");
return nullptr;
}
std::string value = obj->relativetimefmt_->Format(number, unit.data());
napi_value result = nullptr;
status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "FormatRelativeTime: Create format string failed");
HILOG_ERROR_I18N("FormatRelativeTime: Create format string failed");
return nullptr;
}
return result;
@ -1439,13 +1437,13 @@ void IntlAddon::FillInArrayElement(napi_env env, napi_value &result, napi_status
napi_value value = nullptr;
status = napi_create_string_utf8(env, timeVector[i][1].c_str(), NAPI_AUTO_LENGTH, &value);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create string item imeVector[i][1].");
HILOG_ERROR_I18N("Failed to create string item imeVector[i][1].");
return;
}
napi_value type = nullptr;
status = napi_create_string_utf8(env, timeVector[i][0].c_str(), NAPI_AUTO_LENGTH, &type);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create string item timeVector[i][0].");
HILOG_ERROR_I18N("Failed to create string item timeVector[i][0].");
return;
}
napi_value unit = nullptr;
@ -1453,7 +1451,7 @@ void IntlAddon::FillInArrayElement(napi_env env, napi_value &result, napi_status
if (timeVector[i].size() > unitIndex) {
status = napi_create_string_utf8(env, timeVector[i][unitIndex].c_str(), NAPI_AUTO_LENGTH, &unit);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create string item timeVector[i][unitIndex].");
HILOG_ERROR_I18N("Failed to create string item timeVector[i][unitIndex].");
return;
}
} else {
@ -1462,7 +1460,7 @@ void IntlAddon::FillInArrayElement(napi_env env, napi_value &result, napi_status
napi_value formatInfo;
status = napi_create_object(env, &formatInfo);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create format info object.");
HILOG_ERROR_I18N("Failed to create format info object.");
return;
}
napi_set_named_property(env, formatInfo, "type", type);
@ -1470,7 +1468,7 @@ void IntlAddon::FillInArrayElement(napi_env env, napi_value &result, napi_status
napi_set_named_property(env, formatInfo, "unit", unit);
status = napi_set_element(env, result, i, formatInfo);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set array item");
HILOG_ERROR_I18N("Failed to set array item");
return;
}
}
@ -1492,7 +1490,7 @@ napi_value IntlAddon::FormatToParts(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->relativetimefmt_) {
HiLog::Error(LABEL, "FormatToParts: Get RelativeTimeFormat object failed");
HILOG_ERROR_I18N("FormatToParts: Get RelativeTimeFormat object failed");
return nullptr;
}
std::vector<std::vector<std::string>> timeVector;
@ -1500,7 +1498,7 @@ napi_value IntlAddon::FormatToParts(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_array_with_length(env, timeVector.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to create array");
HILOG_ERROR_I18N("Failed to create array");
return nullptr;
}
FillInArrayElement(env, result, status, timeVector);
@ -1528,7 +1526,7 @@ napi_value IntlAddon::CompareString(napi_env env, napi_callback_info info)
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->collator_) {
HiLog::Error(LABEL, "CompareString: Get Collator object failed");
HILOG_ERROR_I18N("CompareString: Get Collator object failed");
return nullptr;
}
@ -1536,7 +1534,7 @@ napi_value IntlAddon::CompareString(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_int32(env, compareResult, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create compare result failed");
HILOG_ERROR_I18N("Create compare result failed");
return nullptr;
}
@ -1552,7 +1550,7 @@ napi_value IntlAddon::GetCollatorResolvedOptions(napi_env env, napi_callback_inf
IntlAddon *obj = nullptr;
napi_status status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->collator_) {
HiLog::Error(LABEL, "GetCollatorResolvedOptions: Get Collator object failed");
HILOG_ERROR_I18N("GetCollatorResolvedOptions: Get Collator object failed");
return nullptr;
}
napi_value result = nullptr;
@ -1577,7 +1575,7 @@ void GetPluralRulesType(napi_env env, napi_value options, std::map<std::string,
if (it != map.end()) {
std::string type = it->second;
if (type != "cardinal" && type != "ordinal") {
HiLog::Error(LABEL, "invalid type");
HILOG_ERROR_I18N("invalid type");
return;
}
} else {
@ -1593,7 +1591,7 @@ void GetPluralRulesInteger(napi_env env, napi_value options, std::map<std::strin
std::string minimumIntegerDigits = it->second;
int n = std::stoi(minimumIntegerDigits);
if (n < 1 || n > 21) { // the valid range of minimumIntegerDigits is [1, 21]
HiLog::Error(LABEL, "invalid minimumIntegerDigits");
HILOG_ERROR_I18N("invalid minimumIntegerDigits");
return;
}
} else {
@ -1609,7 +1607,7 @@ void GetPluralRulesFractions(napi_env env, napi_value options, std::map<std::str
std::string minimumFractionDigits = it->second;
int n = std::stoi(minimumFractionDigits);
if (n < 0 || n > 20) { // the valid range of minimumFractionDigits is [0, 20]
HiLog::Error(LABEL, "invalid minimumFractionDigits");
HILOG_ERROR_I18N("invalid minimumFractionDigits");
return;
}
}
@ -1620,7 +1618,7 @@ void GetPluralRulesFractions(napi_env env, napi_value options, std::map<std::str
std::string maximumFractionDigits = it->second;
int n = std::stoi(maximumFractionDigits);
if (n < 0 || n > 20) { // the valid range of maximumFractionDigits is [0, 20]
HiLog::Error(LABEL, "invalid maximumFractionDigits");
HILOG_ERROR_I18N("invalid maximumFractionDigits");
return;
}
}
@ -1636,7 +1634,7 @@ void GetPluralRulesSignificant(napi_env env, napi_value options, std::map<std::s
int minSignificantInt = std::stoi(minSignificantStr);
// the valid range of minSignificantInt is [1, 21]
if (minSignificantInt < 1 || minSignificantInt > 21) {
HiLog::Error(LABEL, "invalid minimumSignificantDigits");
HILOG_ERROR_I18N("invalid minimumSignificantDigits");
return;
}
minSignificant = minSignificantInt;
@ -1651,7 +1649,7 @@ void GetPluralRulesSignificant(napi_env env, napi_value options, std::map<std::s
int maxSignificant = std::stoi(maxSignificantStr);
// the valid range of minSignificant is [minSignificant, 21]
if (maxSignificant < minSignificant || maxSignificant > 21) {
HiLog::Error(LABEL, "invalid maximumSignificantDigits");
HILOG_ERROR_I18N("invalid maximumSignificantDigits");
return;
}
}
@ -1677,13 +1675,13 @@ napi_value IntlAddon::InitPluralRules(napi_env env, napi_value exports)
status = napi_define_class(env, "PluralRules", NAPI_AUTO_LENGTH, PluralRulesConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitPluralRules");
HILOG_ERROR_I18N("Define class failed when InitPluralRules");
return nullptr;
}
status = napi_set_named_property(env, exports, "PluralRules", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitPluralRules");
HILOG_ERROR_I18N("Set property failed when InitPluralRules");
return nullptr;
}
return exports;
@ -1726,11 +1724,11 @@ napi_value IntlAddon::PluralRulesConstructor(napi_env env, napi_callback_info in
status =
napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), IntlAddon::Destructor, nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "PluralRulesConstructor: Wrap IntlAddon failed");
HILOG_ERROR_I18N("PluralRulesConstructor: Wrap IntlAddon failed");
return nullptr;
}
if (!obj->InitPluralRulesContext(env, info, localeTags, map)) {
HiLog::Error(LABEL, "PluralRulesConstructor: Init DateTimeFormat failed");
HILOG_ERROR_I18N("PluralRulesConstructor: Init DateTimeFormat failed");
return nullptr;
}
obj.release();
@ -1743,7 +1741,7 @@ bool IntlAddon::InitPluralRulesContext(napi_env env, napi_callback_info info, st
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "InitPluralRulesContext: Get global failed");
HILOG_ERROR_I18N("InitPluralRulesContext: Get global failed");
return false;
}
env_ = env;
@ -1769,14 +1767,14 @@ napi_value IntlAddon::Select(napi_env env, napi_callback_info info)
double number = 0;
napi_status status = napi_get_value_double(env, argv[0], &number);
if (status != napi_ok) {
HiLog::Error(LABEL, "Select: Get number failed");
HILOG_ERROR_I18N("Select: Get number failed");
return nullptr;
}
IntlAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->pluralrules_) {
HiLog::Error(LABEL, "Get PluralRules object failed");
HILOG_ERROR_I18N("Get PluralRules object failed");
return nullptr;
}
@ -1784,7 +1782,7 @@ napi_value IntlAddon::Select(napi_env env, napi_callback_info info)
napi_value result = nullptr;
status = napi_create_string_utf8(env, res.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "get select result failed");
HILOG_ERROR_I18N("get select result failed");
return nullptr;
}
return result;

View File

@ -14,7 +14,7 @@
*/
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "locale_config.h"
#include "variable_convertor.h"
#include "system_locale_manager_addon.h"
@ -22,9 +22,6 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "SystemLocaleManagerJs" };
using namespace OHOS::HiviewDFX;
SystemLocaleManagerAddon::SystemLocaleManagerAddon() : env_(nullptr) {}
SystemLocaleManagerAddon::~SystemLocaleManagerAddon()
@ -53,13 +50,13 @@ napi_value SystemLocaleManagerAddon::InitSystemLocaleManager(napi_env env, napi_
status = napi_define_class(env, "SystemLocaleManager", NAPI_AUTO_LENGTH, SystemLocaleManagerConstructor, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Define class failed when InitSystemLocaleManager");
HILOG_ERROR_I18N("Define class failed when InitSystemLocaleManager");
return nullptr;
}
status = napi_set_named_property(env, exports, "SystemLocaleManager", constructor);
if (status != napi_ok) {
HiLog::Error(LABEL, "Set property failed when InitSystemLocaleManager");
HILOG_ERROR_I18N("Set property failed when InitSystemLocaleManager");
return nullptr;
}
return exports;
@ -77,11 +74,11 @@ napi_value SystemLocaleManagerAddon::SystemLocaleManagerConstructor(napi_env env
status = napi_wrap(env, thisVar, reinterpret_cast<void *>(obj.get()), SystemLocaleManagerAddon::Destructor,
nullptr, nullptr);
if (status != napi_ok) {
HiLog::Error(LABEL, "Wrap SystemLocaleManagerAddon failed");
HILOG_ERROR_I18N("Wrap SystemLocaleManagerAddon failed");
return nullptr;
}
if (!obj->InitSystemLocaleManagerContext(env, info)) {
HiLog::Error(LABEL, "Init SystemLocaleManager failed");
HILOG_ERROR_I18N("Init SystemLocaleManager failed");
return nullptr;
}
obj.release();
@ -93,7 +90,7 @@ bool SystemLocaleManagerAddon::InitSystemLocaleManagerContext(napi_env env, napi
napi_value global = nullptr;
napi_status status = napi_get_global(env, &global);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get global failed");
HILOG_ERROR_I18N("Get global failed");
return false;
}
env_ = env;
@ -110,7 +107,7 @@ napi_value SystemLocaleManagerAddon::GetLanguageInfoArray(napi_env env, napi_cal
void *data = nullptr;
napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
if (status != napi_ok) {
HiLog::Error(LABEL, "can not obtain getLanguageInfoArray function param.");
HILOG_ERROR_I18N("can not obtain getLanguageInfoArray function param.");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
@ -124,7 +121,7 @@ napi_value SystemLocaleManagerAddon::GetLanguageInfoArray(napi_env env, napi_cal
SystemLocaleManagerAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->systemLocaleManager_) {
HiLog::Error(LABEL, "GetLanguageInfoArray: Get SystemLocaleManager object failed");
HILOG_ERROR_I18N("GetLanguageInfoArray: Get SystemLocaleManager object failed");
return nullptr;
}
std::vector<LocaleItem> localeItemList = obj->systemLocaleManager_->GetLanguageInfoArray(languageList, options);
@ -140,7 +137,7 @@ napi_value SystemLocaleManagerAddon::GetCountryInfoArray(napi_env env, napi_call
void *data = nullptr;
napi_status status = napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
if (status != napi_ok) {
HiLog::Error(LABEL, "can not obtain getCountryInfoArray function param.");
HILOG_ERROR_I18N("can not obtain getCountryInfoArray function param.");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return nullptr;
}
@ -154,7 +151,7 @@ napi_value SystemLocaleManagerAddon::GetCountryInfoArray(napi_env env, napi_call
SystemLocaleManagerAddon *obj = nullptr;
status = napi_unwrap(env, thisVar, reinterpret_cast<void **>(&obj));
if (status != napi_ok || !obj || !obj->systemLocaleManager_) {
HiLog::Error(LABEL, "GetCountryInfoArray: Get SystemLocaleManager object failed");
HILOG_ERROR_I18N("GetCountryInfoArray: Get SystemLocaleManager object failed");
return nullptr;
}
std::vector<LocaleItem> localeItemList = obj->systemLocaleManager_->GetCountryInfoArray(countryList, options);
@ -168,14 +165,14 @@ napi_value SystemLocaleManagerAddon::GetTimeZoneCityInfoArray(napi_env env, napi
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, timezoneCityItemList.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create TimeZoneCityItem array failed.");
HILOG_ERROR_I18N("create TimeZoneCityItem array failed.");
return nullptr;
}
for (size_t i = 0; i < timezoneCityItemList.size(); ++i) {
napi_value item = CreateTimeZoneCityItem(env, timezoneCityItemList[i]);
status = napi_set_element(env, result, i, item);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set TimeZoneCityItem element.");
HILOG_ERROR_I18N("Failed to set TimeZoneCityItem element.");
return nullptr;
}
}
@ -187,44 +184,44 @@ napi_value SystemLocaleManagerAddon::CreateTimeZoneCityItem(napi_env env, const
napi_value result;
napi_status status = napi_create_object(env, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "CreateTimeZoneCityItem: Create Locale Item object failed.");
HILOG_ERROR_I18N("CreateTimeZoneCityItem: Create Locale Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, result, "zoneId",
VariableConvertor::CreateString(env, timezoneCityItem.zoneId));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element zoneId.");
HILOG_ERROR_I18N("Failed to set element zoneId.");
return nullptr;
}
status = napi_set_named_property(env, result, "cityId",
VariableConvertor::CreateString(env, timezoneCityItem.cityId));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element cityId.");
HILOG_ERROR_I18N("Failed to set element cityId.");
return nullptr;
}
status = napi_set_named_property(env, result, "cityDisplayName",
VariableConvertor::CreateString(env, timezoneCityItem.cityDisplayName));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element cityDisplayName.");
HILOG_ERROR_I18N("Failed to set element cityDisplayName.");
return nullptr;
}
status = napi_set_named_property(env, result, "offset",
VariableConvertor::CreateNumber(env, timezoneCityItem.offset));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element offset.");
HILOG_ERROR_I18N("Failed to set element offset.");
return nullptr;
}
status = napi_set_named_property(env, result, "zoneDisplayName",
VariableConvertor::CreateString(env, timezoneCityItem.zoneDisplayName));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element zoneDisplayName.");
HILOG_ERROR_I18N("Failed to set element zoneDisplayName.");
return nullptr;
}
if (timezoneCityItem.rawOffset != 0) {
status = napi_set_named_property(env, result, "rawOffset",
VariableConvertor::CreateNumber(env, timezoneCityItem.rawOffset));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element rawOffset.");
HILOG_ERROR_I18N("Failed to set element rawOffset.");
return nullptr;
}
}
@ -263,14 +260,14 @@ napi_value SystemLocaleManagerAddon::CreateLocaleItemArray(napi_env env, const s
napi_value result = nullptr;
napi_status status = napi_create_array_with_length(env, localeItemList.size(), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create LocaleItem array failed.");
HILOG_ERROR_I18N("create LocaleItem array failed.");
return nullptr;
}
for (size_t i = 0; i < localeItemList.size(); ++i) {
napi_value item = CreateLocaleItem(env, localeItemList[i]);
status = napi_set_element(env, result, i, item);
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set LocaleItem element.");
HILOG_ERROR_I18N("Failed to set LocaleItem element.");
return nullptr;
}
}
@ -282,32 +279,32 @@ napi_value SystemLocaleManagerAddon::CreateLocaleItem(napi_env env, const Locale
napi_value result;
napi_status status = napi_create_object(env, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "CreateLocaleItem: Create Locale Item object failed.");
HILOG_ERROR_I18N("CreateLocaleItem: Create Locale Item object failed.");
return nullptr;
}
status = napi_set_named_property(env, result, "id", VariableConvertor::CreateString(env, localeItem.id));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element id.");
HILOG_ERROR_I18N("Failed to set element id.");
return nullptr;
}
status = napi_set_named_property(env, result, "displayName",
VariableConvertor::CreateString(env, localeItem.displayName));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element displayName.");
HILOG_ERROR_I18N("Failed to set element displayName.");
return nullptr;
}
if (localeItem.localName.length() != 0) {
status = napi_set_named_property(env, result, "localName",
VariableConvertor::CreateString(env, localeItem.localName));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element localName.");
HILOG_ERROR_I18N("Failed to set element localName.");
return nullptr;
}
}
status = napi_set_named_property(env, result, "suggestionType", CreateSuggestionType(env,
localeItem.suggestionType));
if (status != napi_ok) {
HiLog::Error(LABEL, "Failed to set element suggestionType.");
HILOG_ERROR_I18N("Failed to set element suggestionType.");
return nullptr;
}
return result;
@ -318,7 +315,7 @@ napi_value SystemLocaleManagerAddon::CreateSuggestionType(napi_env env, Suggesti
napi_value result;
napi_status status = napi_create_int32(env, static_cast<int32_t>(suggestionType), &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create SuggestionType failed.");
HILOG_ERROR_I18N("create SuggestionType failed.");
return nullptr;
}
return result;

View File

@ -14,15 +14,12 @@
*/
#include "error_util.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "variable_convertor.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "VariableConvertor" };
using namespace OHOS::HiviewDFX;
bool VariableConvertor::CheckNapiValueType(napi_env env, napi_value value)
{
if (value != nullptr) {
@ -42,7 +39,7 @@ void VariableConvertor::GetOptionValue(napi_env env, napi_value options, const s
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, options, &type);
if (status != napi_ok && type != napi_object) {
HiLog::Error(LABEL, "GetOptionValue: Get option failed, option is not an object");
HILOG_ERROR_I18N("GetOptionValue: Get option failed, option is not an object");
return;
}
bool hasProperty = false;
@ -55,7 +52,7 @@ void VariableConvertor::GetOptionValue(napi_env env, napi_value options, const s
std::vector<char> optionBuf(len + 1);
status = napi_get_value_string_utf8(env, optionValue, optionBuf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "GetOptionValue: Failed to get string item");
HILOG_ERROR_I18N("GetOptionValue: Failed to get string item");
return;
}
value = optionBuf.data();
@ -69,20 +66,20 @@ bool VariableConvertor::GetBoolOptionValue(napi_env env, napi_value &options, co
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, options, &type);
if (status != napi_ok && type != napi_object) {
HiLog::Error(LABEL, "option is not an object");
HILOG_ERROR_I18N("option is not an object");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return false;
}
bool hasProperty = false;
status = napi_has_named_property(env, options, optionName.c_str(), &hasProperty);
if (status != napi_ok || !hasProperty) {
HiLog::Info(LABEL, "option don't have property %{public}s", optionName.c_str());
HILOG_INFO_I18N("option don't have property %{public}s", optionName.c_str());
return false;
}
napi_value optionValue = nullptr;
status = napi_get_named_property(env, options, optionName.c_str(), &optionValue);
if (status != napi_ok) {
HiLog::Info(LABEL, "get option %{public}s failed", optionName.c_str());
HILOG_INFO_I18N("get option %{public}s failed", optionName.c_str());
return false;
}
napi_get_value_bool(env, optionValue, &boolVal);
@ -94,14 +91,14 @@ std::string VariableConvertor::GetString(napi_env &env, napi_value &value, int32
size_t len = 0;
napi_status status = napi_get_value_string_utf8(env, value, nullptr, 0, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Get string failed");
HILOG_ERROR_I18N("Get string failed");
code = 1;
return "";
}
std::vector<char> buf(len + 1);
status = napi_get_value_string_utf8(env, value, buf.data(), len + 1, &len);
if (status != napi_ok) {
HiLog::Error(LABEL, "Create string failed");
HILOG_ERROR_I18N("Create string failed");
code = 1;
return "";
}
@ -111,14 +108,14 @@ std::string VariableConvertor::GetString(napi_env &env, napi_value &value, int32
bool VariableConvertor::GetStringArrayFromJsParam(napi_env env, napi_value &jsArray, std::vector<std::string> &strArray)
{
if (jsArray == nullptr) {
HiLog::Error(LABEL, "js string array param not found.");
HILOG_ERROR_I18N("js string array param not found.");
ErrorUtil::NapiThrow(env, I18N_NOT_FOUND, true);
return false;
}
bool isArray = false;
napi_status status = napi_is_array(env, jsArray, &isArray);
if (status != napi_ok || !isArray) {
HiLog::Error(LABEL, "js string array is not an Array.");
HILOG_ERROR_I18N("js string array is not an Array.");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return false;
}
@ -130,7 +127,7 @@ bool VariableConvertor::GetStringArrayFromJsParam(napi_env env, napi_value &jsAr
napi_get_element(env, jsArray, i, &element);
std::string str = GetString(env, element, code);
if (code != 0) {
HiLog::Error(LABEL, "can't get string from js array param.");
HILOG_ERROR_I18N("can't get string from js array param.");
ErrorUtil::NapiThrow(env, I18N_NOT_VALID, true);
return false;
}
@ -144,7 +141,7 @@ napi_value VariableConvertor::CreateString(napi_env env, const std::string &str)
napi_value result;
napi_status status = napi_create_string_utf8(env, str.c_str(), NAPI_AUTO_LENGTH, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create string js variable failed.");
HILOG_ERROR_I18N("create string js variable failed.");
return nullptr;
}
return result;
@ -155,7 +152,7 @@ napi_value VariableConvertor::CreateNumber(napi_env env, const int32_t &num)
napi_value result;
napi_status status = napi_create_int32(env, num, &result);
if (status != napi_ok) {
HiLog::Error(LABEL, "create number js variable failed.");
HILOG_ERROR_I18N("create number js variable failed.");
return nullptr;
}
return result;

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_service_ability_load_manager.h"
#include "locale_config.h"
#include "preferred_language.h"
@ -23,21 +23,18 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nServiceAbility" };
using namespace OHOS::HiviewDFX;
REGISTER_SYSTEM_ABILITY_BY_ID(I18nServiceAbility, I18N_SA_ID, false);
static const std::string UNLOAD_TASK = "i18n_service_unload";
static const uint32_t DELAY_MILLISECONDS_FOR_UNLOAD_SA = 10000;
I18nServiceAbility::I18nServiceAbility(int32_t saId, bool runOnCreate) : SystemAbility(saId, runOnCreate)
{
HiLog::Info(LABEL, "I18nServiceAbility object init success.");
HILOG_INFO_I18N("I18nServiceAbility object init success.");
}
I18nServiceAbility::~I18nServiceAbility()
{
HiLog::Info(LABEL, "I18nServiceAbility object release.");
HILOG_INFO_I18N("I18nServiceAbility object release.");
}
I18nErrorCode I18nServiceAbility::SetSystemLanguage(const std::string &language)
@ -83,7 +80,7 @@ void I18nServiceAbility::UnloadI18nServiceAbility()
auto task = [this]() {
auto i18nSaLoadManager = DelayedSingleton<I18nServiceAbilityLoadManager>::GetInstance();
if (i18nSaLoadManager != nullptr) {
HiLog::Info(LABEL, "I18nServiceAbility::UnloadI18nServiceAbility start to unload i18n sa.");
HILOG_INFO_I18N("I18nServiceAbility::UnloadI18nServiceAbility start to unload i18n sa.");
i18nSaLoadManager->UnloadI18nService(I18N_SA_ID);
}
};
@ -94,12 +91,12 @@ void I18nServiceAbility::UnloadI18nServiceAbility()
void I18nServiceAbility::OnStart()
{
HiLog::Info(LABEL, "I18nServiceAbility start.");
HILOG_INFO_I18N("I18nServiceAbility start.");
bool status = Publish(this);
if (status) {
HiLog::Info(LABEL, "I18nServiceAbility Publish success.");
HILOG_INFO_I18N("I18nServiceAbility Publish success.");
} else {
HiLog::Info(LABEL, "I18nServiceAbility Publish failed.");
HILOG_INFO_I18N("I18nServiceAbility Publish failed.");
}
handler = std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::Create(true));
UnloadI18nServiceAbility();
@ -107,7 +104,7 @@ void I18nServiceAbility::OnStart()
void I18nServiceAbility::OnStop()
{
HiLog::Info(LABEL, "I18nServiceAbility Stop.");
HILOG_INFO_I18N("I18nServiceAbility Stop.");
}
} // namespace I18n
} // namespace Global

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_service_ability_load_manager.h"
#include "iremote_object.h"
#include "system_ability_definition.h"
@ -22,18 +22,15 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nServiceAbilityClient" };
using namespace OHOS::HiviewDFX;
sptr<II18nServiceAbility> I18nServiceAbilityClient::GetProxy(I18nErrorCode &err)
{
sptr<IRemoteObject> proxy = I18nServiceAbilityLoadManager::GetInstance()->GetI18nServiceAbility(I18N_SA_ID);
if (proxy == nullptr) {
HiLog::Error(LABEL, "I18nServiceAbilityClient::GetProxy load sa failed, try again.");
HILOG_ERROR_I18N("I18nServiceAbilityClient::GetProxy load sa failed, try again.");
proxy = I18nServiceAbilityLoadManager::GetInstance()->GetI18nServiceAbility(I18N_SA_ID);
}
if (proxy == nullptr) {
HiLog::Error(LABEL, "I18nServiceAbilityClient::GetProxy load sa failed.");
HILOG_ERROR_I18N("I18nServiceAbilityClient::GetProxy load sa failed.");
err = I18nErrorCode::LOAD_SA_FAILED;
return nullptr;
}

View File

@ -14,7 +14,7 @@
*/
#include <singleton.h>
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_service_ability_load_manager.h"
#include "iremote_object.h"
#include "i18n_service_ability_load_callback.h"
@ -22,15 +22,12 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nServiceAbilityLoadCallback" };
using namespace OHOS::HiviewDFX;
void I18nServiceAbilityLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
const sptr<IRemoteObject> &remoteObject)
{
auto loadMgr = DelayedSingleton<I18nServiceAbilityLoadManager>::GetInstance();
if (loadMgr == nullptr) {
HiLog::Error(LABEL, "I18nServiceAbilityLoadCallback::OnLoadSystemAbilitySuccess get load manager failed.");
HILOG_ERROR_I18N("I18nServiceAbilityLoadCallback::OnLoadSystemAbilitySuccess get load manager failed.");
return;
}
loadMgr->LoadSystemAbilitySuccess();
@ -40,7 +37,7 @@ void I18nServiceAbilityLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbili
{
auto loadMgr = DelayedSingleton<I18nServiceAbilityLoadManager>::GetInstance();
if (loadMgr == nullptr) {
HiLog::Error(LABEL, "I18nServiceAbilityLoadCallback::OnLoadSystemAbilityFail get load manager failed.");
HILOG_ERROR_I18N("I18nServiceAbilityLoadCallback::OnLoadSystemAbilityFail get load manager failed.");
return;
}
loadMgr->LoadSystemAbilityFail();

View File

@ -13,16 +13,13 @@
* limitations under the License.
*/
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "i18n_service_ability_load_callback.h"
#include "i18n_service_ability_load_manager.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nServiceAbilityLoadManager" };
using namespace OHOS::HiviewDFX;
static constexpr int32_t I18N_LOAD_SA_TIMEOUT_MS = 1000;
I18nServiceAbilityLoadManager::I18nServiceAbilityLoadManager()
@ -51,19 +48,19 @@ sptr<ISystemAbilityManager> I18nServiceAbilityLoadManager::LoadI18nServiceAbilit
InitLoadState();
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
HiLog::Error(LABEL, "I18nServiceAbilityLoadManager::LoadAndGetI18nServiceAbility can't get samgr");
HILOG_ERROR_I18N("I18nServiceAbilityLoadManager::LoadAndGetI18nServiceAbility can't get samgr");
return nullptr;
}
sptr<I18nServiceAbilityLoadCallback> i18nSaLoadCallback = new I18nServiceAbilityLoadCallback();
int32_t ret = samgr->LoadSystemAbility(systemAbilityId, i18nSaLoadCallback);
if (ret != ERR_OK) {
HiLog::Error(LABEL,
HILOG_ERROR_I18N(
"I18nServiceAbilityLoadManager::LoadAndGetI18nServiceAbility LoadSystemAbility failed.");
return nullptr;
}
bool status = WaitLoadStateChange(systemAbilityId);
if (!status) {
HiLog::Error(LABEL, "I18nServiceAbilityLoadManager::LoadAndGetI18nServiceAbility wait overtime.");
HILOG_ERROR_I18N("I18nServiceAbilityLoadManager::LoadAndGetI18nServiceAbility wait overtime.");
return nullptr;
}
return samgr;
@ -82,7 +79,7 @@ bool I18nServiceAbilityLoadManager::WaitLoadStateChange(int32_t systemAbilityId)
return loadState;
});
if (!isLoadSuccess) {
HiLog::Error(LABEL, "I18nServiceAbilityLoadManager::WaitLoadStateChange timeout.");
HILOG_ERROR_I18N("I18nServiceAbilityLoadManager::WaitLoadStateChange timeout.");
}
return isLoadSuccess;
}
@ -91,12 +88,12 @@ bool I18nServiceAbilityLoadManager::UnloadI18nService(int32_t systemAbilityId)
{
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgr == nullptr) {
HiLog::Error(LABEL, "I18nServiceAbilityLoadManager::UnloadI18nService can't get samgr.");
HILOG_ERROR_I18N("I18nServiceAbilityLoadManager::UnloadI18nService can't get samgr.");
return false;
}
int32_t ret = samgr->UnloadSystemAbility(systemAbilityId);
if (ret != ERR_OK) {
HiLog::Error(LABEL, "I18nServiceAbilityLoadManager::UnloadI18nService sa unload failed.");
HILOG_ERROR_I18N("I18nServiceAbilityLoadManager::UnloadI18nService sa unload failed.");
return false;
}
return true;

View File

@ -13,15 +13,13 @@
* limitations under the License.
*/
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "message_parcel.h"
#include "i18n_service_ability_proxy.h"
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nServiceAbilityProxy" };
using namespace OHOS::HiviewDFX;
static const std::u16string DESCRIPTOR = u"OHOS.global.II18nServiceAbility";
I18nServiceAbilityProxy::I18nServiceAbilityProxy(const sptr<IRemoteObject> &impl)
@ -118,7 +116,7 @@ I18nErrorCode I18nServiceAbilityProxy::ProcessReply(int32_t reply)
{
I18nErrorCode err = static_cast<I18nErrorCode>(reply);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL,
HILOG_ERROR_I18N(
"I18nServiceAbilityProxy::ProcessReply failed with errorcode=%{public}d", reply);
}
return err;

View File

@ -14,7 +14,7 @@
*/
#include "accesstoken_kit.h"
#include "hilog/log.h"
#include "i18n_hilog.h"
#include "ipc_skeleton.h"
#include "tokenid_kit.h"
#include "i18n_service_ability_stub.h"
@ -22,30 +22,27 @@
namespace OHOS {
namespace Global {
namespace I18n {
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "I18nServiceAbilityStub" };
using namespace OHOS::HiviewDFX;
I18nServiceAbilityStub::I18nServiceAbilityStub(bool serialInvokeFlag)
: IRemoteStub<II18nServiceAbility>(serialInvokeFlag)
{
InitInnerFuncMap();
HiLog::Info(LABEL, "I18nServiceAbilityStub object init success.");
HILOG_INFO_I18N("I18nServiceAbilityStub object init success.");
}
I18nServiceAbilityStub::~I18nServiceAbilityStub()
{
HiLog::Info(LABEL, "I18nServiceAbilityStub object release.");
HILOG_INFO_I18N("I18nServiceAbilityStub object release.");
}
int32_t I18nServiceAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
HiLog::Info(LABEL, "I18nServiceAbilityStub::OnRemoteRequest process request for code=%{public}u", code);
HILOG_INFO_I18N("I18nServiceAbilityStub::OnRemoteRequest process request for code=%{public}u", code);
// check whether request's descriptor is consistent with sa's descriptor
std::u16string descriptor = GetDescriptor();
std::u16string remoteDescriptor = data.ReadInterfaceToken();
if (descriptor != remoteDescriptor) {
HiLog::Error(LABEL, "I18nServiceAbilityStub client and server's descriptor are inconsistent.");
HILOG_ERROR_I18N("I18nServiceAbilityStub client and server's descriptor are inconsistent.");
reply.WriteInt32(I18nErrorCode::INCONSISTENT_DESCRIPTOR);
return 0;
}
@ -61,7 +58,7 @@ int32_t I18nServiceAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &da
}
}
if (!hasMappedInnerFunc) {
HiLog::Info(LABEL, "I18nServiceAbilityStub::OnRemoteRequest invalid request code=%{public}u", code);
HILOG_INFO_I18N("I18nServiceAbilityStub::OnRemoteRequest invalid request code=%{public}u", code);
ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
// trigger release i18n service after one request finished.
@ -100,13 +97,13 @@ I18nErrorCode I18nServiceAbilityStub::CheckPermission()
bool isShell = tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL;
bool isNative = tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE;
if (!isSystemApp && !isShell && !isNative) {
HiLog::Error(LABEL, "I18nServiceAbilityStub caller process is not System app, Shell or Native.");
HILOG_ERROR_I18N("I18nServiceAbilityStub caller process is not System app, Shell or Native.");
return I18nErrorCode::NO_PERMISSION;
}
int result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken,
"ohos.permission.UPDATE_CONFIGURATION");
if (result != Security::AccessToken::PermissionState::PERMISSION_GRANTED) {
HiLog::Error(LABEL, "I18nServiceAbilityStub caller process doesn't have UPDATE_CONFIGURATION permission.");
HILOG_ERROR_I18N("I18nServiceAbilityStub caller process doesn't have UPDATE_CONFIGURATION permission.");
return I18nErrorCode::NO_PERMISSION;
}
return I18nErrorCode::SUCCESS;
@ -122,7 +119,7 @@ int32_t I18nServiceAbilityStub::SetSystemLanguageInner(MessageParcel &data, Mess
std::string language = data.ReadString();
err = SetSystemLanguage(language);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "I18nServiceAbilityStub::SetSystemLanguageInner failed with errorCode=%{public}d",
HILOG_ERROR_I18N("I18nServiceAbilityStub::SetSystemLanguageInner failed with errorCode=%{public}d",
static_cast<int32_t>(err));
}
reply.WriteInt32(static_cast<int32_t>(err));
@ -139,7 +136,7 @@ int32_t I18nServiceAbilityStub::SetSystemRegionInner(MessageParcel &data, Messag
std::string region = data.ReadString();
err = SetSystemRegion(region);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "I18nServiceAbilityStub::SetSystemRegionInner failed with errorCode=%{public}d",
HILOG_ERROR_I18N("I18nServiceAbilityStub::SetSystemRegionInner failed with errorCode=%{public}d",
static_cast<int32_t>(err));
}
reply.WriteInt32(static_cast<int32_t>(err));
@ -156,7 +153,7 @@ int32_t I18nServiceAbilityStub::SetSystemLocaleInner(MessageParcel &data, Messag
std::string locale = data.ReadString();
err = SetSystemLocale(locale);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "I18nServiceAbilityStub::SetSystemLocaleInner failed with errorCode=%{public}d",
HILOG_ERROR_I18N("I18nServiceAbilityStub::SetSystemLocaleInner failed with errorCode=%{public}d",
static_cast<int32_t>(err));
}
reply.WriteInt32(static_cast<int32_t>(err));
@ -173,7 +170,7 @@ int32_t I18nServiceAbilityStub::Set24HourClockInner(MessageParcel &data, Message
std::string flag = data.ReadString();
err = Set24HourClock(flag);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "I18nServiceAbilityStub::Set24HourClockInner failed with errorCode=%{public}d",
HILOG_ERROR_I18N("I18nServiceAbilityStub::Set24HourClockInner failed with errorCode=%{public}d",
static_cast<int32_t>(err));
}
reply.WriteInt32(static_cast<int32_t>(err));
@ -190,7 +187,7 @@ int32_t I18nServiceAbilityStub::SetUsingLocalDigitInner(MessageParcel &data, Mes
bool flag = data.ReadBool();
err = SetUsingLocalDigit(flag);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "I18nServiceAbilityStub::SetUsingLocalDigitInner failed with errorCode=%{public}d",
HILOG_ERROR_I18N("I18nServiceAbilityStub::SetUsingLocalDigitInner failed with errorCode=%{public}d",
static_cast<int32_t>(err));
}
reply.WriteInt32(static_cast<int32_t>(err));
@ -208,7 +205,7 @@ int32_t I18nServiceAbilityStub::AddPreferredLanguageInner(MessageParcel &data, M
int32_t index = data.ReadInt32();
err = AddPreferredLanguage(language, index);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "I18nServiceAbilityStub::AddPreferredLanguageInner failed with errorCode=%{public}d",
HILOG_ERROR_I18N("I18nServiceAbilityStub::AddPreferredLanguageInner failed with errorCode=%{public}d",
static_cast<int32_t>(err));
}
reply.WriteInt32(static_cast<int32_t>(err));
@ -225,7 +222,7 @@ int32_t I18nServiceAbilityStub::RemovePreferredLanguageInner(MessageParcel &data
int32_t index = data.ReadInt32();
err = RemovePreferredLanguage(index);
if (err != I18nErrorCode::SUCCESS) {
HiLog::Error(LABEL, "I18nServiceAbilityStub::RemovePreferredLanguageInner failed with errorCode=%{public}d",
HILOG_ERROR_I18N("I18nServiceAbilityStub::RemovePreferredLanguageInner failed with errorCode=%{public}d",
static_cast<int32_t>(err));
}
reply.WriteInt32(static_cast<int32_t>(err));