in locales-common/src/main/java/com/spotify/i18n/locales/common/model/ResolvedLocale.java [75:109]
public static ResolvedLocale fromLanguageTags(
final String languageTagForTranslations,
final List<String> languageTagForTranslationsFallbacks,
final String languageTagForFormatting) {
Preconditions.checkNotNull(languageTagForTranslations, "Given input cannot be null");
Preconditions.checkNotNull(languageTagForTranslationsFallbacks, "Given input cannot be null");
Preconditions.checkNotNull(languageTagForFormatting, "Given input cannot be null");
ULocale localeForTranslations = ULocale.forLanguageTag(languageTagForTranslations);
ULocale localeForFormatting = ULocale.forLanguageTag(languageTagForFormatting);
List<ULocale> localeForTranslationsFallbacks =
languageTagForTranslationsFallbacks.stream()
.map(ULocale::forLanguageTag)
.collect(Collectors.toList());
Preconditions.checkState(
SupportedLocale.ALL_AVAILABLE_LOCALES.contains(localeForTranslations),
"Given parameter languageTagForTranslations could not be matched with a locale available in CLDR: %s",
languageTagForTranslations);
Preconditions.checkState(
localeForTranslationsFallbacks.stream()
.allMatch(SupportedLocale.ALL_AVAILABLE_LOCALES::contains),
"Given parameter languageTagForTranslationsFallbacks contains entries that could not be matched with a locale available in CLDR: %s",
languageTagForTranslationsFallbacks);
Preconditions.checkState(
SupportedLocale.ALL_AVAILABLE_LOCALES.contains(localeForFormatting),
"Given parameter languageTagForFormatting could not be matched with a locale available in CLDR: %s",
languageTagForFormatting);
return ResolvedLocale.builder()
.localeForTranslations(localeForTranslations)
.localeForTranslationsFallbacks(localeForTranslationsFallbacks)
.localeForFormatting(localeForFormatting)
.build();
}