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

The following examples show how to use java.util.Locale#lookup() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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 2
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;
    }

}
 
Example 3
@Override
public Locale resolve(RoutingContext context, List<Locale> availableLocales) {
  String accept = context.request().getHeader(ACCEPT_LANGUAGE.toString());
  if (accept == null) {
    return null;
  }
  List<LanguageRange> ranges = LanguageRange.parse(accept);
  if (ranges.isEmpty()) {
    return null;
  }
  return Locale.lookup(ranges, availableLocales);
}
 
Example 4
Source Project: tutorials   File: SimpleController.java    License: MIT License 5 votes vote down vote up
@GetMapping("/slf4j-guide-locale-request")
public String clientLocaleRequest(@RequestHeader("Accept-Language") String localeHeader) {
    List<Locale.LanguageRange> list = Locale.LanguageRange.parse(localeHeader);
    Locale locale = Locale.lookup(list, Arrays.asList(Locale.getAvailableLocales()));
    IMessageConveyor messageConveyor = new MessageConveyor(locale);
    LocLoggerFactory llFactory = new LocLoggerFactory(messageConveyor);
    LocLogger locLogger = llFactory.getLocLogger(this.getClass());
    locLogger.info(Messages.CLIENT_REQUEST, "parametrizedClientId", localeHeader);
    locLogger.debug(Messages.REQUEST_STARTED);
    locLogger.info(Messages.REQUEST_FINISHED);
    return "finished";
}
 
Example 5
/** Returns whether the language supports any language in the given ranges. */
boolean isAnyLanguageSupported(List<Locale.LanguageRange> languageRanges) {
    return mLanguageIndependent || Locale.lookup(languageRanges, mSupportedLocales) != null;
}