public String getLanguageOrDefault ( RouteContext routeContext ) { final String cookieName = generateLanguageCookie ( defaultLanguage ) . getName ( ) ; // Step 1: Look for a Response cookie. // The Response always has priority over the Request because it may have // been set earlier in the HandlerChain. Cookie cookie = routeContext . getResponse ( ) . getCookie ( cookieName ) ; if ( cookie != null && ! StringUtils . isNullOrEmpty ( cookie . getValue ( ) ) ) { return getLanguageOrDefault ( cookie . getValue ( ) ) ; } // Step 2: Look for a Request cookie. cookie = routeContext . getRequest ( ) . getCookie ( cookieName ) ; if ( cookie != null && ! StringUtils . isNullOrEmpty ( cookie . getValue ( ) ) ) { return getLanguageOrDefault ( cookie . getValue ( ) ) ; } // Step 3: Look for a lang parameter in the response locals if ( routeContext . getResponse ( ) . getLocals ( ) . containsKey ( PippoConstants . REQUEST_PARAMETER_LANG ) ) { String language = routeContext . getLocal ( PippoConstants . REQUEST_PARAMETER_LANG ) ; language = getLanguageOrDefault ( language ) ; return language ; } // Step 4: Look for a language in the Accept-Language header. String acceptLanguage = routeContext . getHeader ( HttpConstants . Header . ACCEPT_LANGUAGE ) ; return getLanguageOrDefault ( acceptLanguage ) ; }
Returns the language for the request . This process considers Request & Response cookies the Request ACCEPT_LANGUAGE header and finally the application default language .