code: public static Locale parseLocale( final String header )
      {
          //        String header = "en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2";
  
          if ( header == null || header.trim()
                                       .length() < 1 )
          {
              return Locale.getDefault( Category.FORMAT );
          }
  
          final Map<Double, String> prefs = parseQualityHeader( header );
  
          final List<Double> sortedKeys = new ArrayList<Double>( prefs.keySet() );
          Collections.sort( sortedKeys );
          Collections.reverse( sortedKeys );
  
          final Locale[] available = Locale.getAvailableLocales();
          Locale result = null;
          for ( final Double key : sortedKeys )
          {
              final String[] parts = prefs.get( key )
                                          .split( "_" );
  
              for ( final Locale l : available )
              {
                  if ( !parts[0].equals( l.getISO3Language() ) )
                  {
                      continue;
                  }
  
                  if ( parts.length > 1 && !parts[1].equals( l.getISO3Country() ) )
                  {
                      continue;
                  }
  
                  if ( parts.length > 2 && !parts[2].equals( l.getVariant() ) )
                  {
                      continue;
                  }
  
                  result = l;
              }
          }
  
          return result == null ? Locale.getDefault( Category.FORMAT ) : result;
      }
docs: Shamelessly copied from: http://stackoverflow.com/questions/6824157/parse-accept-language-header-in-java