code: private static String toLanguageTag(Locale locale) {
          if (locale == null) {
              return null;
          }
          StringBuilder tag = new StringBuilder();
  
          tag.append(locale.getLanguage().toLowerCase());
  
          if (!locale.getCountry().isEmpty()) {
              tag.append("-");
              tag.append(locale.getCountry().toUpperCase());
          }
  
          return tag.toString();
      }
docs: Available in Java 7, but not in Java 6. Do a hacky version of it here.