Java Code Examples for io.undertow.util.LocaleUtils

The following examples show how to use io.undertow.util.LocaleUtils. 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
Source Project: mangooio   Source File: LocaleHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    Locale locale = Locale.forLanguageTag(this.config.getApplicationLanguage());
    Attachment attachment = exchange.getAttachment(RequestUtils.getAttachmentKey());

    Cookie i18nCookie = exchange.getRequestCookies().get(this.config.getI18nCookieName());
    if (i18nCookie == null) {
        final HeaderValues headerValues = exchange.getRequestHeaders().get(Header.ACCEPT_LANGUAGE.toHttpString());
        if (headerValues != null) {
            String acceptLanguage = headerValues.element();
            if (StringUtils.isNotBlank(acceptLanguage)) {
                locale = LocaleUtils.getLocaleFromString(acceptLanguage);
            }
        }
    } else {
        locale = LocaleUtils.getLocaleFromString(i18nCookie.getValue());
    }

    attachment.getMessages().reload(locale);
    attachment.withLocale(locale);
    
    exchange.putAttachment(RequestUtils.getAttachmentKey(), attachment);
    nextHandler(exchange);
}
 
Example 2
Source Project: quarkus-http   Source File: HttpServletRequestImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Enumeration<Locale> getLocales() {
    final List<String> acceptLanguage = exchange.getRequestHeaders(HttpHeaderNames.ACCEPT_LANGUAGE);
    List<Locale> ret = LocaleUtils.getLocalesFromHeader(acceptLanguage);
    if (ret.isEmpty()) {
        return new IteratorEnumeration<>(Collections.singletonList(Locale.getDefault()).iterator());
    }
    return new IteratorEnumeration<>(ret.iterator());
}
 
Example 3
Source Project: lams   Source File: HttpServletRequestImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Enumeration<Locale> getLocales() {
    final List<String> acceptLanguage = exchange.getRequestHeaders().get(Headers.ACCEPT_LANGUAGE);
    List<Locale> ret = LocaleUtils.getLocalesFromHeader(acceptLanguage);
    if(ret.isEmpty()) {
        return new IteratorEnumeration<>(Collections.singletonList(Locale.getDefault()).iterator());
    }
    return new IteratorEnumeration<>(ret.iterator());
}