public static Locale makeLocale ( final String val ) throws Throwable { String lang = null ; String country = "" ; // NOT null for Locale String variant = "" ; if ( val == null ) { throw new Exception ( "Bad Locale: NULL" ) ; } if ( val . length ( ) == 2 ) { lang = val ; } else { int pos = val . indexOf ( ' ' ) ; if ( pos != 2 ) { throw new Exception ( "Bad Locale: " + val ) ; } lang = val . substring ( 0 , 2 ) ; pos = val . indexOf ( "_" , 3 ) ; if ( pos < 0 ) { if ( val . length ( ) != 5 ) { throw new Exception ( "Bad Locale: " + val ) ; } country = val . substring ( 3 ) ; } else { country = val . substring ( 3 , 5 ) ; if ( val . length ( ) > 6 ) { variant = val . substring ( 6 ) ; } } } return new Locale ( lang , country , variant ) ; }
make a locale from the standard underscore separated parts - no idea why this isn t in Locale