< prev index next >

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

Print this page




  55      */
  56     @Override
  57     public Locale[] getAvailableLocales() {
  58         return LocaleProviderAdapter.toLocaleArray(langtags);
  59     }
  60 
  61     @Override
  62     public boolean isSupportedLocale(Locale locale) {
  63         return LocaleProviderAdapter.isSupportedLocale(locale, type, langtags);
  64     }
  65 
  66     /**
  67      * Returns a localized name for the given ISO 639 language code and the
  68      * given locale that is appropriate for display to the user.
  69      * For example, if <code>languageCode</code> is "fr" and <code>locale</code>
  70      * is en_US, getDisplayLanguage() will return "French"; if <code>languageCode</code>
  71      * is "en" and <code>locale</code> is fr_FR, getDisplayLanguage() will return "anglais".
  72      * If the name returned cannot be localized according to <code>locale</code>,
  73      * (say, the provider does not have a Japanese name for Croatian),
  74      * this method returns null.
  75      * @param languageCode the ISO 639 language code string in the form of two
  76      *     lower-case letters between 'a' (U+0061) and 'z' (U+007A)
  77      * @param locale the desired locale
  78      * @return the name of the given language code for the specified locale, or null if it's not
  79      *     available.
  80      * @exception NullPointerException if <code>languageCode</code> or <code>locale</code> is null
  81      * @exception IllegalArgumentException if <code>languageCode</code> is not in the form of
  82      *     two lower-case letters, or <code>locale</code> isn't
  83      *     one of the locales returned from
  84      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
  85      *     getAvailableLocales()}.
  86      * @see java.util.Locale#getDisplayLanguage(java.util.Locale)
  87      */
  88     @Override
  89     public String getDisplayLanguage(String lang, Locale locale) {
  90         return getDisplayString(lang, locale);
  91     }
  92 
  93     /**
  94      * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
  95      * IETF BCP47</a> script code and the given locale that is appropriate for


 112      *     four title case letters, or <code>locale</code> isn't
 113      *     one of the locales returned from
 114      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 115      *     getAvailableLocales()}.
 116      * @see java.util.Locale#getDisplayScript(java.util.Locale)
 117      */
 118     @Override
 119     public String getDisplayScript(String scriptCode, Locale locale) {
 120         return getDisplayString(scriptCode, locale);
 121     }
 122 
 123     /**
 124      * Returns a localized name for the given ISO 3166 country code and the
 125      * given locale that is appropriate for display to the user.
 126      * For example, if <code>countryCode</code> is "FR" and <code>locale</code>
 127      * is en_US, getDisplayCountry() will return "France"; if <code>countryCode</code>
 128      * is "US" and <code>locale</code> is fr_FR, getDisplayCountry() will return "Etats-Unis".
 129      * If the name returned cannot be localized according to <code>locale</code>,
 130      * (say, the provider does not have a Japanese name for Croatia),
 131      * this method returns null.
 132      * @param countryCode the ISO 3166 country code string in the form of two
 133      *     upper-case letters between 'A' (U+0041) and 'Z' (U+005A)
 134      * @param locale the desired locale
 135      * @return the name of the given country code for the specified locale, or null if it's not
 136      *     available.
 137      * @exception NullPointerException if <code>countryCode</code> or <code>locale</code> is null
 138      * @exception IllegalArgumentException if <code>countryCode</code> is not in the form of
 139      *     two upper-case letters, or <code>locale</code> isn't
 140      *     one of the locales returned from
 141      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 142      *     getAvailableLocales()}.
 143      * @see java.util.Locale#getDisplayCountry(java.util.Locale)
 144      */
 145     @Override
 146     public String getDisplayCountry(String ctry, Locale locale) {
 147         return getDisplayString(ctry, locale);
 148     }
 149 
 150     /**
 151      * Returns a localized name for the given variant code and the given locale that
 152      * is appropriate for display to the user.
 153      * If the name returned cannot be localized according to <code>locale</code>,
 154      * this method returns null.
 155      * @param variant the variant string
 156      * @param locale the desired locale
 157      * @return the name of the given variant string for the specified locale, or null if it's not
 158      *     available.
 159      * @exception NullPointerException if <code>variant</code> or <code>locale</code> is null
 160      * @exception IllegalArgumentException if <code>locale</code> isn't
 161      *     one of the locales returned from
 162      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 163      *     getAvailableLocales()}.
 164      * @see java.util.Locale#getDisplayVariant(java.util.Locale)
 165      */
 166     @Override
 167     public String getDisplayVariant(String vrnt, Locale locale) {
 168         return getDisplayString("%%"+vrnt, locale);
 169     }
 170 
 171     private String getDisplayString(String key, Locale locale) {
 172         if (key == null || locale == null) {
 173             throw new NullPointerException();
 174         }
 175 


  55      */
  56     @Override
  57     public Locale[] getAvailableLocales() {
  58         return LocaleProviderAdapter.toLocaleArray(langtags);
  59     }
  60 
  61     @Override
  62     public boolean isSupportedLocale(Locale locale) {
  63         return LocaleProviderAdapter.isSupportedLocale(locale, type, langtags);
  64     }
  65 
  66     /**
  67      * Returns a localized name for the given ISO 639 language code and the
  68      * given locale that is appropriate for display to the user.
  69      * For example, if <code>languageCode</code> is "fr" and <code>locale</code>
  70      * is en_US, getDisplayLanguage() will return "French"; if <code>languageCode</code>
  71      * is "en" and <code>locale</code> is fr_FR, getDisplayLanguage() will return "anglais".
  72      * If the name returned cannot be localized according to <code>locale</code>,
  73      * (say, the provider does not have a Japanese name for Croatian),
  74      * this method returns null.
  75      * @param lang the ISO 639 language code string in the form of two
  76      *     lower-case letters between 'a' (U+0061) and 'z' (U+007A)
  77      * @param locale the desired locale
  78      * @return the name of the given language code for the specified locale, or null if it's not
  79      *     available.
  80      * @exception NullPointerException if <code>languageCode</code> or <code>locale</code> is null
  81      * @exception IllegalArgumentException if <code>languageCode</code> is not in the form of
  82      *     two lower-case letters, or <code>locale</code> isn't
  83      *     one of the locales returned from
  84      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
  85      *     getAvailableLocales()}.
  86      * @see java.util.Locale#getDisplayLanguage(java.util.Locale)
  87      */
  88     @Override
  89     public String getDisplayLanguage(String lang, Locale locale) {
  90         return getDisplayString(lang, locale);
  91     }
  92 
  93     /**
  94      * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
  95      * IETF BCP47</a> script code and the given locale that is appropriate for


 112      *     four title case letters, or <code>locale</code> isn't
 113      *     one of the locales returned from
 114      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 115      *     getAvailableLocales()}.
 116      * @see java.util.Locale#getDisplayScript(java.util.Locale)
 117      */
 118     @Override
 119     public String getDisplayScript(String scriptCode, Locale locale) {
 120         return getDisplayString(scriptCode, locale);
 121     }
 122 
 123     /**
 124      * Returns a localized name for the given ISO 3166 country code and the
 125      * given locale that is appropriate for display to the user.
 126      * For example, if <code>countryCode</code> is "FR" and <code>locale</code>
 127      * is en_US, getDisplayCountry() will return "France"; if <code>countryCode</code>
 128      * is "US" and <code>locale</code> is fr_FR, getDisplayCountry() will return "Etats-Unis".
 129      * If the name returned cannot be localized according to <code>locale</code>,
 130      * (say, the provider does not have a Japanese name for Croatia),
 131      * this method returns null.
 132      * @param ctry the ISO 3166 country code string in the form of two
 133      *     upper-case letters between 'A' (U+0041) and 'Z' (U+005A)
 134      * @param locale the desired locale
 135      * @return the name of the given country code for the specified locale, or null if it's not
 136      *     available.
 137      * @exception NullPointerException if <code>countryCode</code> or <code>locale</code> is null
 138      * @exception IllegalArgumentException if <code>countryCode</code> is not in the form of
 139      *     two upper-case letters, or <code>locale</code> isn't
 140      *     one of the locales returned from
 141      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 142      *     getAvailableLocales()}.
 143      * @see java.util.Locale#getDisplayCountry(java.util.Locale)
 144      */
 145     @Override
 146     public String getDisplayCountry(String ctry, Locale locale) {
 147         return getDisplayString(ctry, locale);
 148     }
 149 
 150     /**
 151      * Returns a localized name for the given variant code and the given locale that
 152      * is appropriate for display to the user.
 153      * If the name returned cannot be localized according to <code>locale</code>,
 154      * this method returns null.
 155      * @param vrnt the variant string
 156      * @param locale the desired locale
 157      * @return the name of the given variant string for the specified locale, or null if it's not
 158      *     available.
 159      * @exception NullPointerException if <code>variant</code> or <code>locale</code> is null
 160      * @exception IllegalArgumentException if <code>locale</code> isn't
 161      *     one of the locales returned from
 162      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 163      *     getAvailableLocales()}.
 164      * @see java.util.Locale#getDisplayVariant(java.util.Locale)
 165      */
 166     @Override
 167     public String getDisplayVariant(String vrnt, Locale locale) {
 168         return getDisplayString("%%"+vrnt, locale);
 169     }
 170 
 171     private String getDisplayString(String key, Locale locale) {
 172         if (key == null || locale == null) {
 173             throw new NullPointerException();
 174         }
 175 
< prev index next >