private static void validateLocaleForTranslationsFallbacks()

in locales-common/src/main/java/com/spotify/i18n/locales/common/model/ResolvedLocale.java [219:271]


    private static void validateLocaleForTranslationsFallbacks(ResolvedLocale resolvedLocale) {
      if (resolvedLocale.localeForTranslationsFallbacks().isEmpty()) {
        return;
      }

      Preconditions.checkState(
          !resolvedLocale.localeForTranslationsFallbacks().stream()
              .anyMatch(locale -> LocalesHierarchyUtils.isSameLocale(locale, ULocale.ROOT)),
          "The given fallbackLocalesForTranslations cannot contain the root.");

      Preconditions.checkState(
          !resolvedLocale.localeForTranslationsFallbacks().stream()
              .anyMatch(
                  locale ->
                      LocalesHierarchyUtils.isSameLocale(
                          locale, resolvedLocale.localeForTranslations())),
          "The given fallbackLocalesForTranslations cannot contain the localeForTranslations [%s].",
          resolvedLocale.localeForTranslations().toLanguageTag());

      List<ULocale> nonCldrFallbackLocalesForTranslations =
          resolvedLocale.localeForTranslationsFallbacks().stream()
              .filter(Predicate.not(SupportedLocale.ALL_AVAILABLE_LOCALES::contains))
              .collect(Collectors.toList());

      Preconditions.checkState(
          nonCldrFallbackLocalesForTranslations.isEmpty(),
          "The given fallbackLocalesForTranslations %s must be canonical and available in CLDR.",
          nonCldrFallbackLocalesForTranslations.stream()
              .map(ULocale::toLanguageTag)
              .sorted()
              .collect(Collectors.joining(",")));

      ULocale localeForTranslationsHighestAncestor =
          LocalesHierarchyUtils.getHighestAncestorLocale(resolvedLocale.localeForTranslations());

      List<ULocale> incompatibleFallbackLocalesForTranslations =
          resolvedLocale.localeForTranslationsFallbacks().stream()
              .filter(
                  locale ->
                      !LocalesHierarchyUtils.isSameLocale(
                          localeForTranslationsHighestAncestor,
                          LocalesHierarchyUtils.getHighestAncestorLocale(locale)))
              .collect(Collectors.toList());

      Preconditions.checkState(
          incompatibleFallbackLocalesForTranslations.isEmpty(),
          "The given fallbackLocaleForTranslations [%s] are not compatible fallbacks for the localeForTranslations [%s].",
          incompatibleFallbackLocalesForTranslations.stream()
              .map(ULocale::toLanguageTag)
              .sorted()
              .collect(Collectors.joining(",")),
          resolvedLocale.localeForTranslations().toLanguageTag());
    }