- locNameLen = uloc_getParent(parentLocale, parentLocale,
- ULOC_FULLNAME_CAPACITY,&status);
- } while ( locNameLen > 0 );
+ // Find the name of the appropriate parent locale (from %%Parent if present, else
+ // uloc_getParent on the actual locale name)
+ // (It would be nice to have a ures function that did this...)
+ int32_t locNameLen;
+ const UChar * parentUName = ures_getStringByKey(rb, "%%Parent", &locNameLen, &status);
+ if (U_SUCCESS(status) && status != U_USING_FALLBACK_WARNING && locNameLen < ULOC_FULLNAME_CAPACITY) {
+ u_UCharsToChars(parentUName, parentLocale, locNameLen + 1);
+ } else {
+ status = U_ZERO_ERROR;
+ // Get the actual name of the current locale being used
+ const char *curLocaleName=ures_getLocaleByType(rb, ULOC_ACTUAL_LOCALE, &status);
+ if ( U_FAILURE(status) ) {
+ curLocaleName = parentLocale;
+ status = U_ZERO_ERROR;
+ }
+ uloc_getParent(curLocaleName, parentLocale, ULOC_FULLNAME_CAPACITY, &status);
+ if (U_FAILURE(err) || err == U_STRING_NOT_TERMINATED_WARNING) {
+ parentLocale[0] = 0; // just fallback to root, will cause us to stop
+ status = U_ZERO_ERROR;
+ }
+ }
+ // Now we can close the current locale bundle
+ ures_close(rb);
+ // If the new current locale is root, then stop
+ // (unlike for DateTimePatternGenerator, DateIntervalFormat does not go all the way up
+ // to root to find additional data for non-root locales)
+ } while ( parentLocale[0] != 0 && uprv_strcmp(parentLocale,"root")!=0 );