Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4101316

getDisplayName for Locale "de" returns German (Germany) rather than German

XMLWordPrintable

    • 1.1.6
    • generic, sparc
    • solaris_2.5, solaris_2.5.1
    • Verified

        If you create a custom Locale using an atypical language,country
        combination -- the displayName is not properly rendered
        for that locale. For example, the following snippet
        creates a locale for the German language, country Canada.
        Yet the display name comes out as German(Germany)

        Locale locale = new Locale( "de", "CA" );
        String name = locale.getDisplayName();
        System.out.println( name ); // outputs 'German (Germany)' instead of 'German (Canada)' as would be expected

        The problem is two-fold. The first part is that the getDisplayCountry method, in this case,
        ends up using the 'de' LocaleElements bundle, which only lists Germany countries. This part of the problem is filed as bug 4092475 and is not the topic of this bug report.

        The second part of the problem is that the language-only LocaleElements bundles should not be listing any countries since they are bundles for language only!



        import java.util.Locale;

        public class LocaleTest
        {
            public static void main( String[] args )
            {
                Locale typicalLocale = Locale.GERMANY; // German-speaking Ger
        mans
                Locale atypicalLocale = new Locale( "de", "CA" ); // German-speaking Can
        adians

                System.out.println( "'German (Germany)' DisplayName renders " + typicalL
        ocale.getDisplayName() );
                System.out.println( "'German (Germany)' DisplayCountry renders " + typic
        alLocale.getDisplayCountry() );
                System.out.println( "'German (Germany)' DisplayLanguage renders " + typi
        calLocale.getDisplayLanguage() );
                System.out.println( "'German (Canada)' DisplayName renders " + atypicalL
        ocale.getDisplayName() );
                System.out.println( "'German (Canada)' DisplayCountry renders " + atypic
        alLocale.getDisplayCountry() );
                System.out.println( "'German (Canada)' DisplayLanguage renders " + atypi
        calLocale.getDisplayLanguage() );
            }
        }
        (Review ID: 19671)
        ======================================================================

              joconnersunw John Oconner (Inactive)
              bcbeck Brian Beck (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: