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


Java Locale.lookup方法代码示例

本文整理汇总了Java中java.util.Locale.lookup方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.lookup方法的具体用法?Java Locale.lookup怎么用?Java Locale.lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Locale的用法示例。


在下文中一共展示了Locale.lookup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: chooseForLocale

import java.util.Locale; //导入方法依赖的package包/类
private static IProperty chooseForLocale(
    final @NotNull List<Locale.LanguageRange> priorityList,
    final @NotNull List<IProperty> properties
) {
    if (properties.isEmpty()) {
        return null;
    }
    IProperty first = properties.get(0);
    if (properties.size() == 1) {
        return first;
    }
    final Map<Locale, IProperty> map = new HashMap<>();
    final List<Locale> locales = new LinkedList<>();
    for (IProperty nextProperty : properties) {
        Locale nextLocale = safeGetLocale(nextProperty);
        if (nextLocale != null) {
            map.put(nextLocale, nextProperty);
            locales.add(nextLocale);
        }
    }

    Locale best = Locale.lookup(priorityList, locales);
    //System.err.println("found locales: " + locales + ", best: " + best + ", result: " + map.get(best));
    return Optional.ofNullable(best).map(map::get).orElse(first);
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:26,代码来源:JspPropertyFoldingBuilder.java

示例2: getImplicitLocale

import java.util.Locale; //导入方法依赖的package包/类
/**
 * Gets the locale to use if one was not explicitly provided.
 *
 * @return the implicit locale to use, not null
 */
@Nonnull
protected Locale getImplicitLocale() {
  Locale locale = null;

  if (getLocaleSupplier().isPresent()) {
    locale = getLocaleSupplier().get().get();
  } else if (getLanguageRangesSupplier().isPresent()) {
    List<LanguageRange> languageRanges = getLanguageRangesSupplier().get().get();

    if (languageRanges != null)
      locale = Locale.lookup(languageRanges, getLocalizedStringsByLocale().keySet());
  }

  return locale == null ? getFallbackLocale() : locale;
}
 
开发者ID:lokalized,项目名称:lokalized-java,代码行数:21,代码来源:DefaultStrings.java

示例3: checkLookup

import java.util.Locale; //导入方法依赖的package包/类
private static void checkLookup(String ranges, String tags,
        String expectedLocale) {

    List<Locale.LanguageRange> priorityList = Locale.LanguageRange
            .parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    Locale loc = Locale.lookup(priorityList, localeList);
    String actualLocale
            = loc.toLanguageTag();

    if (!actualLocale.equals(expectedLocale)) {
        System.err.println("Locale.lookup failed with ranges: " + ranges
                + " Expected: " + expectedLocale
                + " Actual: " + actualLocale);
        err = true;
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Bug8035133.java

示例4: testLookup

import java.util.Locale; //导入方法依赖的package包/类
private static void testLookup() {
    boolean error = false;
    String ranges = "hi-IN, itc-Ital";
    String tags = "hi-IN, itc-Ital";
    List<LanguageRange> priorityList = LanguageRange.parse(ranges);
    List<Locale> localeList = generateLocales(tags);
    Locale actualLocale
            = Locale.lookup(priorityList, localeList);
    String actualLocaleString = "";

    if (actualLocale != null) {
        actualLocaleString = actualLocale.toLanguageTag();
    } else {
        error = true;
    }

    String expectedLocale = "hi-IN";

    if (!expectedLocale.equals(actualLocaleString)) {
        error = true;
    }

    if (error) {
        System.err.println("testLookup() failed on language ranges:"
                + " [" + ranges + "] and language tags: [" + tags + "]");
        err = true;
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:Bug8159420.java


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