本文整理汇总了Java中sun.util.locale.provider.LocaleProviderAdapter.getLocaleNameProvider方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleProviderAdapter.getLocaleNameProvider方法的具体用法?Java LocaleProviderAdapter.getLocaleNameProvider怎么用?Java LocaleProviderAdapter.getLocaleNameProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.util.locale.provider.LocaleProviderAdapter
的用法示例。
在下文中一共展示了LocaleProviderAdapter.getLocaleNameProvider方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bug8010666Test
import sun.util.locale.provider.LocaleProviderAdapter; //导入方法依赖的package包/类
static void bug8010666Test() {
if (System.getProperty("os.name").startsWith("Windows")) {
NumberFormat nf = NumberFormat.getInstance(Locale.US);
try {
double ver = nf.parse(System.getProperty("os.version"))
.doubleValue();
System.out.printf("Windows version: %.1f\n", ver);
if (ver >= 6.0) {
LocaleProviderAdapter lda =
LocaleProviderAdapter.getAdapter(
LocaleNameProvider.class, Locale.ENGLISH);
LocaleProviderAdapter.Type type = lda.getAdapterType();
if (type == LocaleProviderAdapter.Type.HOST) {
LocaleNameProvider lnp = lda.getLocaleNameProvider();
Locale mkmk = Locale.forLanguageTag("mk-MK");
String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
String hostResult =
lnp.getDisplayLanguage(mkmk.getLanguage(),
Locale.ENGLISH);
System.out.printf(" Display language name for" +
" (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
hostResult, result);
if (result == null ||
hostResult != null &&
!result.equals(hostResult)) {
throw new RuntimeException("Display language name" +
" mismatch for \"mk\". Returned name was" +
" \"" + result + "\", result(HOST): \"" +
hostResult + "\"");
}
result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
hostResult =
lnp.getDisplayLanguage(Locale.US.getLanguage(),
Locale.ENGLISH);
System.out.printf(" Display language name for" +
" (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
hostResult, result);
if (result == null ||
hostResult != null &&
!result.equals(hostResult)) {
throw new RuntimeException("Display language name" +
" mismatch for \"en\". Returned name was" +
" \"" + result + "\", result(HOST): \"" +
hostResult + "\"");
}
if (ver >= 6.1) {
result = Locale.US.getDisplayCountry(Locale.ENGLISH);
hostResult = lnp.getDisplayCountry(
Locale.US.getCountry(), Locale.ENGLISH);
System.out.printf(" Display country name for" +
" (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
hostResult, result);
if (result == null ||
hostResult != null &&
!result.equals(hostResult)) {
throw new RuntimeException("Display country name" +
" mismatch for \"US\". Returned name was" +
" \"" + result + "\", result(HOST): \"" +
hostResult + "\"");
}
}
} else {
throw new RuntimeException("Windows Host" +
" LocaleProviderAdapter was not selected for" +
" English locale.");
}
}
} catch (ParseException pe) {
throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
}
}
}