private ULocale mitigateParsedLocaleUndefinedCodes()

in locales-common/src/main/java/com/spotify/i18n/locales/common/impl/LocalesResolverBaseImpl.java [276:293]


  private ULocale mitigateParsedLocaleUndefinedCodes(ULocale supportedLocale, ULocale locale) {
    if (!locale.getCountry().isBlank()) {
      // If the country is defined, we need to mitigate the language and the script only.
      return new ULocale.Builder()
          .setLanguage(getMitigatedValue(locale.getLanguage(), supportedLocale.getLanguage()))
          .setScript(getMitigatedValue(locale.getScript(), supportedLocale.getScript()))
          .setRegion(locale.getCountry())
          .build();
    } else {
      // The script has to be defined, as the range would have been ignored in the first place
      // otherwise. In this case, only the language needs to be mitigated, the country/region can
      // safely be ignored.
      return new ULocale.Builder()
          .setLanguage(getMitigatedValue(locale.getLanguage(), supportedLocale.getLanguage()))
          .setScript(locale.getScript())
          .build();
    }
  }