Java Code Examples for java.util.Locale.lookup()

The following are Jave code examples for showing how to use lookup() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: hybris-integration-intellij-idea-plugin   File: JspPropertyFoldingBuilder.java   View Source Code Vote up 6 votes
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);
}
 
Example 2
Project: lokalized-java   File: DefaultStrings.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 3
Project: openjdk-jdk10   File: Bug8035133.java   View Source Code Vote up 6 votes
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;
    }

}
 
Example 4
Project: openjdk-jdk10   File: Bug8159420.java   View Source Code Vote up 5 votes
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;
    }

}