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

The following examples show how to use java.util.Locale#lookup() . 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
Source File: Bug8035133.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: Bug8159420.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: AcceptLanguageLocaleResolver.java    From nubes with Apache License 2.0 5 votes vote down vote up
@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 File: SimpleController.java    From tutorials with 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
Source File: TextClassifierImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/** Returns whether the language supports any language in the given ranges. */
boolean isAnyLanguageSupported(List<Locale.LanguageRange> languageRanges) {
    return mLanguageIndependent || Locale.lookup(languageRanges, mSupportedLocales) != null;
}