code: private static String toLanguageTag(String locale) {
          if (locale == null) {
              return null;
          }
          // assume we are already a language tag
          if (!locale.contains("_")) {
              return locale;
          }
  
          // language can be missing, in which case we don't even bother
          if (locale.startsWith("_")) {
              return locale;
          }
  
          // Java 6 does "lang_country_variant". If country is missing, then "lang__variant". If no
          // variant, then just "lang_country".
          String [] parts = locale.split("_", 3);
  
          String lang = parts[0];
          String country = parts[1];
          String variant = parts.length == 3 ? parts[2] : "";
  
          return toLanguageTag(new Locale(lang, country, variant));
      }
docs: formats to the new one.