Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Global I18n Standard
提交
b21edd30
G
Global I18n Standard
项目概览
OpenHarmony
/
Global I18n Standard
大约 1 年 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Global I18n Standard
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b21edd30
编写于
9月 15, 2021
作者:
M
meaty-bag-and-wangwang-meat
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issues
Signed-off-by:
N
meaty-bag-and-wangwang-meat
<
zouzhexi@huawei.com
>
上级
a1cee298
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
100 addition
and
22 deletion
+100
-22
frameworks/intl/include/locale_info.h
frameworks/intl/include/locale_info.h
+2
-2
frameworks/intl/src/locale_info.cpp
frameworks/intl/src/locale_info.cpp
+6
-6
frameworks/intl/src/number_format.cpp
frameworks/intl/src/number_format.cpp
+1
-1
frameworks/intl/test/unittest/intl_test.cpp
frameworks/intl/test/unittest/intl_test.cpp
+2
-6
interfaces/js/kits/include/intl_addon.h
interfaces/js/kits/include/intl_addon.h
+2
-0
interfaces/js/kits/src/intl_addon.cpp
interfaces/js/kits/src/intl_addon.cpp
+87
-7
未找到文件。
frameworks/intl/include/locale_info.h
浏览文件 @
b21edd30
...
...
@@ -36,8 +36,8 @@ public:
std
::
string
GetCollation
()
const
;
std
::
string
GetHourCycle
()
const
;
std
::
string
GetNumberingSystem
()
const
;
LocaleInfo
*
Maximize
();
LocaleInfo
*
Minimize
();
std
::
string
Maximize
();
std
::
string
Minimize
();
std
::
string
GetNumeric
()
const
;
std
::
string
GetCaseFirst
()
const
;
std
::
string
ToString
()
const
;
...
...
frameworks/intl/src/locale_info.cpp
浏览文件 @
b21edd30
...
...
@@ -220,7 +220,7 @@ Locale LocaleInfo::GetLocale() const
return
locale
;
}
LocaleInfo
*
LocaleInfo
::
Maximize
()
std
::
string
LocaleInfo
::
Maximize
()
{
UErrorCode
status
=
U_ZERO_ERROR
;
Locale
curLocale
=
locale
;
...
...
@@ -230,12 +230,12 @@ LocaleInfo *LocaleInfo::Maximize()
std
::
string
curBaseName
=
(
curLocale
.
getBaseName
()
==
nullptr
)
?
""
:
curLocale
.
getBaseName
();
std
::
replace
(
curBaseName
.
begin
(),
curBaseName
.
end
(),
'_'
,
'-'
);
std
::
string
localeTag
=
curBaseName
+
restConfigs
;
return
new
LocaleInfo
(
localeTag
,
configs
)
;
return
localeTag
;
}
return
this
;
return
finalLocaleTag
;
}
LocaleInfo
*
LocaleInfo
::
Minimize
()
std
::
string
LocaleInfo
::
Minimize
()
{
UErrorCode
status
=
U_ZERO_ERROR
;
Locale
curLocale
=
locale
;
...
...
@@ -245,9 +245,9 @@ LocaleInfo *LocaleInfo::Minimize()
std
::
string
curBaseName
=
(
curLocale
.
getBaseName
()
==
nullptr
)
?
""
:
curLocale
.
getBaseName
();
std
::
replace
(
curBaseName
.
begin
(),
curBaseName
.
end
(),
'_'
,
'-'
);
std
::
string
localeTag
=
curBaseName
+
restConfigs
;
return
new
LocaleInfo
(
localeTag
,
configs
)
;
return
localeTag
;
}
return
this
;
return
finalLocaleTag
;
}
bool
LocaleInfo
::
Init
()
...
...
frameworks/intl/src/number_format.cpp
浏览文件 @
b21edd30
...
...
@@ -260,7 +260,7 @@ void NumberFormat::GetResolvedOptions(std::map<std::string, std::string> &map)
map
.
insert
(
std
::
make_pair
(
"currencyDisplay"
,
currencyDisplayString
));
}
if
(
!
signDisplayString
.
empty
())
{
map
.
insert
(
std
::
make_pair
(
"signDisplay
signDisplay
"
,
signDisplayString
));
map
.
insert
(
std
::
make_pair
(
"signDisplay"
,
signDisplayString
));
}
if
(
!
compactDisplay
.
empty
())
{
map
.
insert
(
std
::
make_pair
(
"compactDisplay"
,
compactDisplay
));
...
...
frameworks/intl/test/unittest/intl_test.cpp
浏览文件 @
b21edd30
...
...
@@ -109,15 +109,11 @@ HWTEST_F(IntlTest, IntlFuncTest002, TestSize.Level1)
EXPECT_EQ
(
loc
->
GetCalendar
(),
"japanese"
);
EXPECT_EQ
(
loc
->
GetHourCycle
(),
"h11"
);
EXPECT_EQ
(
loc
->
GetNumberingSystem
(),
"jpan"
);
LocaleInfo
*
minLoc
=
loc
->
Minimize
();
EXPECT_EQ
(
minLoc
->
GetScript
(),
""
);
LocaleInfo
*
maxLoc
=
loc
->
Maximize
();
EXPECT_EQ
(
maxLoc
->
GetScript
(),
"Jpan"
);
EXPECT_EQ
(
loc
->
Minimize
(),
"ja-u-hc-h11-nu-jpan-ca-japanese-co-emoji-kn-true"
);
EXPECT_EQ
(
loc
->
Maximize
(),
"ja-Jpan-JP-u-hc-h11-nu-jpan-ca-japanese-co-emoji-kn-true"
);
EXPECT_EQ
(
loc
->
GetNumeric
(),
"true"
);
EXPECT_EQ
(
loc
->
GetCaseFirst
(),
""
);
delete
loc
;
delete
minLoc
;
delete
maxLoc
;
}
/**
...
...
interfaces/js/kits/include/intl_addon.h
浏览文件 @
b21edd30
...
...
@@ -68,6 +68,8 @@ private:
static
napi_value
GetNumeric
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
GetCaseFirst
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
ToString
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
Maximize
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
Minimize
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
FormatDateTime
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
FormatDateTimeRange
(
napi_env
env
,
napi_callback_info
info
);
...
...
interfaces/js/kits/src/intl_addon.cpp
浏览文件 @
b21edd30
...
...
@@ -32,6 +32,7 @@ namespace I18n {
static
constexpr
OHOS
::
HiviewDFX
::
HiLogLabel
LABEL
=
{
LOG_CORE
,
0xD001E00
,
"IntlJs"
};
using
namespace
OHOS
::
HiviewDFX
;
static
napi_ref
*
g_constructor
=
nullptr
;
IntlAddon
::
IntlAddon
()
:
env_
(
nullptr
),
wrapper_
(
nullptr
)
{}
...
...
@@ -63,6 +64,8 @@ napi_value IntlAddon::InitLocale(napi_env env, napi_value exports)
DECLARE_NAPI_GETTER
(
"numeric"
,
GetNumeric
),
DECLARE_NAPI_GETTER
(
"caseFirst"
,
GetCaseFirst
),
DECLARE_NAPI_FUNCTION
(
"toString"
,
ToString
),
DECLARE_NAPI_FUNCTION
(
"minimize"
,
Minimize
),
DECLARE_NAPI_FUNCTION
(
"maximize"
,
Maximize
),
};
napi_value
constructor
;
...
...
@@ -78,6 +81,16 @@ napi_value IntlAddon::InitLocale(napi_env env, napi_value exports)
HiLog
::
Error
(
LABEL
,
"Set property failed when InitLocale"
);
return
nullptr
;
}
g_constructor
=
new
(
std
::
nothrow
)
napi_ref
;
if
(
g_constructor
==
nullptr
)
{
HiLog
::
Error
(
LABEL
,
"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"
);
return
nullptr
;
}
return
exports
;
}
...
...
@@ -137,7 +150,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
,
"
S
et option failed, option is not an object"
);
HiLog
::
Error
(
LABEL
,
"
G
et option failed, option is not an object"
);
return
;
}
bool
hasProperty
=
false
;
...
...
@@ -867,11 +880,11 @@ napi_value IntlAddon::GetNumeric(napi_env env, napi_callback_info info)
return
nullptr
;
}
std
::
string
value
=
obj
->
locale_
->
GetNumeric
();
bool
optionBoolValue
=
(
value
==
"true"
);
napi_value
result
;
status
=
napi_
create_string_utf8
(
env
,
value
.
c_str
(),
NAPI_AUTO_LENGTH
,
&
result
);
status
=
napi_
get_boolean
(
env
,
optionBoolValue
,
&
result
);
if
(
status
!=
napi_ok
)
{
HiLog
::
Error
(
LABEL
,
"Create
base name string
failed"
);
HiLog
::
Error
(
LABEL
,
"Create
numeric boolean value
failed"
);
return
nullptr
;
}
return
result
;
...
...
@@ -889,11 +902,10 @@ napi_value IntlAddon::GetCaseFirst(napi_env env, napi_callback_info info)
return
nullptr
;
}
std
::
string
value
=
obj
->
locale_
->
GetCaseFirst
();
bool
optionBoolValue
=
(
value
==
"true"
);
napi_value
result
;
status
=
napi_
get_boolean
(
env
,
optionBoolValue
,
&
result
);
status
=
napi_
create_string_utf8
(
env
,
value
.
c_str
(),
NAPI_AUTO_LENGTH
,
&
result
);
if
(
status
!=
napi_ok
)
{
HiLog
::
Error
(
LABEL
,
"Create case
first boolean value
failed"
);
HiLog
::
Error
(
LABEL
,
"Create case
First string
failed"
);
return
nullptr
;
}
return
result
;
...
...
@@ -921,6 +933,74 @@ napi_value IntlAddon::ToString(napi_env env, napi_callback_info info)
return
result
;
}
napi_value
IntlAddon
::
Maximize
(
napi_env
env
,
napi_callback_info
info
)
{
// No parameters are needed to get the language.
GET_PARAMS
(
env
,
info
,
0
);
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
std
::
string
localeTag
=
obj
->
locale_
->
Maximize
();
napi_value
constructor
;
status
=
napi_get_reference_value
(
env
,
*
g_constructor
,
&
constructor
);
if
(
status
!=
napi_ok
)
{
HiLog
::
Error
(
LABEL
,
"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
,
"Create localeTag string failed"
);
return
nullptr
;
}
status
=
napi_new_instance
(
env
,
constructor
,
1
,
&
arg
,
&
result
);
if
(
status
!=
napi_ok
)
{
HiLog
::
Error
(
LABEL
,
"Create new locale instance failed"
);
return
nullptr
;
}
return
result
;
}
napi_value
IntlAddon
::
Minimize
(
napi_env
env
,
napi_callback_info
info
)
{
// No parameters are needed to get the language.
GET_PARAMS
(
env
,
info
,
0
);
IntlAddon
*
obj
=
nullptr
;
napi_status
status
=
napi_unwrap
(
env
,
thisVar
,
reinterpret_cast
<
void
**>
(
&
obj
));
if
(
status
!=
napi_ok
||
obj
==
nullptr
||
obj
->
locale_
==
nullptr
)
{
HiLog
::
Error
(
LABEL
,
"Get Locale object failed"
);
return
nullptr
;
}
std
::
string
localeTag
=
obj
->
locale_
->
Minimize
();
napi_value
constructor
;
status
=
napi_get_reference_value
(
env
,
*
g_constructor
,
&
constructor
);
if
(
status
!=
napi_ok
)
{
HiLog
::
Error
(
LABEL
,
"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
,
"Create localeTag string failed"
);
return
nullptr
;
}
status
=
napi_new_instance
(
env
,
constructor
,
1
,
&
arg
,
&
result
);
if
(
status
!=
napi_ok
)
{
HiLog
::
Error
(
LABEL
,
"Create new locale instance failed"
);
return
nullptr
;
}
return
result
;
}
void
SetOptionProperties
(
napi_env
env
,
napi_value
&
result
,
std
::
map
<
std
::
string
,
std
::
string
>
&
options
,
const
std
::
string
&
option
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录