in locales-utils/src/main/java/com/spotify/i18n/locales/utils/hierarchy/LocalesHierarchyUtils.java [195:214]
private static Optional<ULocale> getParentLocaleBasedOnFallback(final ULocale locale) {
if (isSameLocale(locale, ULocale.ROOT)) {
return Optional.empty();
} else if (isSameLocale(locale.getFallback(), ULocale.ROOT)) {
return Optional.of(ULocale.ROOT);
} else if (scriptIsMajorLanguageDifferentiator(locale)) {
// When we know the script is a major differentiator, we assess the parent locale based on it.
return getParentLocaleBasedOnLocaleAndScript(locale);
} else {
// When the script isn't a major differentiator, we can confidently return the fallback
// property of the given locale as parent locale, as long as it doesn't contain any script
// code. Otherwise, we assess the parent locale based on the locale script, to prevent
// unavailable yet valid locales like es-Arab from being considered.
if (locale.getScript().isEmpty()) {
return Optional.of(locale.getFallback());
} else {
return getParentLocaleBasedOnLocaleAndScript(locale);
}
}
}