src/java.base/share/classes/sun/util/locale/provider/CalendarNameProviderImpl.java

Print this page

        

@@ -61,10 +61,18 @@
         String name = null;
         String key = getResourceKey(calendarType, field, style, javatime);
         if (key != null) {
             LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
             String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
+
+            // If standalone names are requested and no "standalone." resources are found,
+            // try the default ones instead.
+            if (strings == null && key.indexOf("standalone.") != -1) {
+                key = key.replaceFirst("standalone.", "");
+                strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
+            }
+
             if (strings != null && strings.length > 0) {
                 if (field == DAY_OF_WEEK || field == YEAR) {
                     --value;
                 }
                 if (value < 0 || value >= strings.length) {

@@ -116,10 +124,18 @@
         String key = getResourceKey(calendarType, field, style, javatime);
         Map<String, Integer> map = new TreeMap<>(LengthBasedComparator.INSTANCE);
         if (key != null) {
             LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
             String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
+
+            // If standalone names are requested and no "standalone." resources are found,
+            // try the default ones instead.
+            if (strings == null && key.indexOf("standalone.") != -1) {
+                key = key.replaceFirst("standalone.", "");
+                strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
+            }
+
             if (strings != null) {
                 if (!hasDuplicates(strings)) {
                     if (field == YEAR) {
                         if (strings.length > 0) {
                             map.put(strings[0], 1);

@@ -279,12 +295,12 @@
             }
             key.append("Month").append(toStyleName(baseStyle));
             break;
 
         case DAY_OF_WEEK:
-            // support standalone narrow day names
-            if (isStandalone && isNarrow) {
+            // support standalone day names
+            if (isStandalone) {
                 key.append("standalone.");
             }
             key.append("Day").append(toStyleName(baseStyle));
             break;