private Optional getBestMatch()

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


  private Optional<ResolvedLocale> getBestMatch(
      final List<LanguageRange> languageRanges,
      final LocaleMatcher localeMatcherForTranslations,
      final Map<ULocale, Set<ULocale>> supportedLocalesMap) {
    List<LanguageRange> overriddenAcceptLanguageEntries =
        getAcceptLanguageEntriesWithBestMatchingAvailableLocaleOverride(languageRanges);
    final String normalizedAcceptLanguage = languageRangesToValue(overriddenAcceptLanguageEntries);
    return Optional.ofNullable(localeMatcherForTranslations.getBestMatch(normalizedAcceptLanguage))
        .map(
            localeForTranslations ->
                ResolvedLocale.builder()
                    .localeForTranslations(localeForTranslations)
                    .localeForTranslationsFallbacks(
                        getRecommendedLocaleForTranslationsFallbacks(
                            localeForTranslations, supportedLocalesMap.keySet()))
                    .localeForFormatting(
                        getLocaleForFormatting(
                            supportedLocalesMap, normalizedAcceptLanguage, localeForTranslations))
                    .build());
  }