當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。