LocaleUtils { public static List<String> getLocaleFallbacks( Locale locale ) { List<String> locales = new ArrayList<>(); locales.add( locale.getLanguage() ); if ( !locale.getCountry().isEmpty() ) { locales.add( locale.getLanguage() + SEP + locale.getCountry() ); } if ( !locale.getVariant().isEmpty() ) { locales.add( locale.toString() ); } return locales; }  static Locale getLocale( String localeStr ); static String getLocaleString( String language, String country, String variant ); static List<String> getLocaleFallbacks( Locale locale );  }
@Test public void testGetLocaleFallbacks() { Locale l1 = new Locale( "en", "UK", "en" ); Locale l2 = new Locale( "en", "UK" ); Locale l3 = new Locale( "en" ); List<String> locales = LocaleUtils.getLocaleFallbacks( l1 ); assertEquals( 3, locales.size() ); assertTrue( locales.contains( "en_UK_en" ) ); assertTrue( locales.contains( "en_UK" ) ); assertTrue( locales.contains( "en_UK" ) ); assertEquals( 2, LocaleUtils.getLocaleFallbacks( l2 ).size() ); assertEquals( 1, LocaleUtils.getLocaleFallbacks( l3 ).size() ); }