Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
f1282514
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f1282514
编写于
10月 18, 2010
作者:
N
naoto
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6992272: I18N: Locale.getDisplayName() and toString() return empty if just script is set
Reviewed-by: srl Contributed-by: y.umaoka@gmail.com
上级
31ae8005
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
80 addition
and
15 deletion
+80
-15
src/share/classes/java/util/Locale.java
src/share/classes/java/util/Locale.java
+31
-15
test/java/util/Locale/LocaleEnhanceTest.java
test/java/util/Locale/LocaleEnhanceTest.java
+49
-0
未找到文件。
src/share/classes/java/util/Locale.java
浏览文件 @
f1282514
...
...
@@ -1715,6 +1715,7 @@ public final class Locale implements Cloneable, Serializable {
OpenListResourceBundle
bundle
=
LocaleData
.
getLocaleNames
(
inLocale
);
String
languageName
=
getDisplayLanguage
(
inLocale
);
String
scriptName
=
getDisplayScript
(
inLocale
);
String
countryName
=
getDisplayCountry
(
inLocale
);
String
[]
variantNames
=
getDisplayVariantArray
(
bundle
,
inLocale
);
...
...
@@ -1735,25 +1736,40 @@ public final class Locale implements Cloneable, Serializable {
String
mainName
=
null
;
String
[]
qualifierNames
=
null
;
// The main name is the language, or if there is no language, the
country.
//
If there is neither language nor country (an anomalous situation) then
//
the display name is simply the variant's display name.
if
(
languageName
.
length
()
!=
0
)
{
mainName
=
languageName
;
if
(
countryName
.
length
()
!
=
0
)
{
qualifierNames
=
new
String
[
variantNames
.
length
+
1
]
;
System
.
arraycopy
(
variantNames
,
0
,
qualifierNames
,
1
,
variantNames
.
length
);
qualifierNames
[
0
]
=
countryName
;
// The main name is the language, or if there is no language, the
script,
//
then if no script, the country. If there is no language/script/country
//
(an anomalous situation) then the display name is simply the variant's
// display name.
if
(
languageName
.
length
()
==
0
&&
scriptName
.
length
()
==
0
&&
countryName
.
length
()
==
0
)
{
if
(
variantNames
.
length
=
=
0
)
{
return
""
;
}
else
{
return
formatList
(
variantNames
,
listPattern
,
listCompositionPattern
)
;
}
else
qualifierNames
=
variantNames
;
}
else
if
(
countryName
.
length
()
!=
0
)
{
mainName
=
countryName
;
qualifierNames
=
variantNames
;
ArrayList
<
String
>
names
=
new
ArrayList
<
String
>(
4
);
if
(
languageName
.
length
()
!=
0
)
{
names
.
add
(
languageName
)
;
}
else
{
return
formatList
(
variantNames
,
listPattern
,
listCompositionPattern
);
if
(
scriptName
.
length
()
!=
0
)
{
names
.
add
(
scriptName
);
}
if
(
countryName
.
length
()
!=
0
)
{
names
.
add
(
countryName
);
}
if
(
variantNames
.
length
!=
0
)
{
for
(
String
var
:
variantNames
)
{
names
.
add
(
var
);
}
}
// The first one in the main name
mainName
=
names
.
get
(
0
);
// Others are qualifiers
int
numNames
=
names
.
size
();
qualifierNames
=
(
numNames
>
1
)
?
names
.
subList
(
1
,
numNames
).
toArray
(
new
String
[
numNames
-
1
])
:
new
String
[
0
];
// Create an array whose first element is the number of remaining
// elements. This serves as a selector into a ChoiceFormat pattern from
...
...
test/java/util/Locale/LocaleEnhanceTest.java
浏览文件 @
f1282514
...
...
@@ -614,6 +614,55 @@ public class LocaleEnhanceTest extends LocaleTestFmwk {
assertEquals
(
"hans DE"
,
"Simplified Han"
,
hansLocale
.
getDisplayScript
(
Locale
.
GERMANY
));
}
public
void
testGetDisplayName
()
{
final
Locale
[]
testLocales
=
{
Locale
.
ROOT
,
new
Locale
(
"en"
),
new
Locale
(
"en"
,
"US"
),
new
Locale
(
""
,
"US"
),
new
Locale
(
"no"
,
"NO"
,
"NY"
),
new
Locale
(
""
,
""
,
"NY"
),
Locale
.
forLanguageTag
(
"zh-Hans"
),
Locale
.
forLanguageTag
(
"zh-Hant"
),
Locale
.
forLanguageTag
(
"zh-Hans-CN"
),
Locale
.
forLanguageTag
(
"und-Hans"
),
};
final
String
[]
displayNameEnglish
=
{
""
,
"English"
,
"English (United States)"
,
"United States"
,
"Norwegian (Norway,Nynorsk)"
,
"Nynorsk"
,
"Chinese (Simplified Han)"
,
"Chinese (Traditional Han)"
,
"Chinese (Simplified Han,China)"
,
"Simplified Han"
,
};
final
String
[]
displayNameSimplifiedChinese
=
{
""
,
"\u82f1\u6587"
,
"\u82f1\u6587 (\u7f8e\u56fd)"
,
"\u7f8e\u56fd"
,
"\u632a\u5a01\u6587 (\u632a\u5a01,Nynorsk)"
,
"Nynorsk"
,
"\u4e2d\u6587 (\u7b80\u4f53\u4e2d\u6587)"
,
"\u4e2d\u6587 (\u7e41\u4f53\u4e2d\u6587)"
,
"\u4e2d\u6587 (\u7b80\u4f53\u4e2d\u6587,\u4e2d\u56fd)"
,
"\u7b80\u4f53\u4e2d\u6587"
,
};
for
(
int
i
=
0
;
i
<
testLocales
.
length
;
i
++)
{
Locale
loc
=
testLocales
[
i
];
assertEquals
(
"English display name for "
+
loc
.
toLanguageTag
(),
displayNameEnglish
[
i
],
loc
.
getDisplayName
(
Locale
.
ENGLISH
));
assertEquals
(
"Simplified Chinese display name for "
+
loc
.
toLanguageTag
(),
displayNameSimplifiedChinese
[
i
],
loc
.
getDisplayName
(
Locale
.
CHINA
));
}
}
///
/// Builder tests
///
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录