public String getLanguageOrDefault ( String language ) { if ( ! StringUtils . isNullOrEmpty ( language ) ) { // Check if we get a registered mapping for the language input // string. The language may be either 'language-country' or // 'language'. String [ ] languages = language . toLowerCase ( ) . split ( "," ) ; for ( String lang : languages ) { // Ignore the relative quality factor in Accept-Language header if ( lang . contains ( ";" ) ) { lang = lang . split ( ";" ) [ 0 ] ; } if ( isSupportedLanguage ( lang ) ) { return lang ; } } } return defaultLanguage ; }
Returns a registered language if one can be matched from the input string OR returns the default language . The input string may be a simple language or locale value or may be as complex as an ACCEPT - LANGUAGE header .