当前位置: 首页>>代码示例>>Java>>正文


Java LocaleProviderAdapter.getLocaleNameProvider方法代码示例

本文整理汇总了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());
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:73,代码来源:LocaleProviders.java


注:本文中的sun.util.locale.provider.LocaleProviderAdapter.getLocaleNameProvider方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。