class Util {

  public static @PolyNull String normalizeLanguageCode(@PolyNull String language) {
    if (language == null) {
      return null;
    }
    try {
      Locale locale = getLocaleForLanguageTag(language);
      int localeLanguageLength = locale.getLanguage().length();
      String normLanguage = locale.getISO3Language();
      if (normLanguage.isEmpty()) {
        return toLowerInvariant(language);
      }
      String normTag = getLocaleLanguageTag(locale);
      return toLowerInvariant(normLanguage + normTag.substring(localeLanguageLength));
    } catch (MissingResourceException e) {
      return toLowerInvariant(language);
    }
  }

  private  Util();

}