78 |
* @author Jochen Hoenicke |
* @author Jochen Hoenicke |
79 |
* @author Paul Fisher |
* @author Paul Fisher |
80 |
* @author Eric Blake (ebb9@email.byu.edu) |
* @author Eric Blake (ebb9@email.byu.edu) |
81 |
|
* @author Andrew John Hughes (gnu_andrew@member.fsf.org) |
82 |
* @since 1.1 |
* @since 1.1 |
83 |
* @status updated to 1.4 |
* @status updated to 1.4 |
84 |
*/ |
*/ |
591 |
} |
} |
592 |
|
|
593 |
/** |
/** |
594 |
* Gets the language name suitable for display to the user, formatted |
* <p> |
595 |
* for a specified locale. |
* Gets the name of the language specified by this locale, in a form suitable |
596 |
|
* for display to the user. If possible, the display name will be localized |
597 |
|
* to the specified locale. For example, if the locale instance is |
598 |
|
* <code>Locale.GERMANY</code>, and the specified locale is <code>Locale.UK</code>, |
599 |
|
* the result would be 'German'. Using the German locale would instead give |
600 |
|
* 'Deutsch'. If the display name can not be localized to the supplied |
601 |
|
* locale, it will fall back on other output in the following order: |
602 |
|
* </p> |
603 |
|
* <ul> |
604 |
|
* <li>the display name in the default locale</li> |
605 |
|
* <li>the display name in English</li> |
606 |
|
* <li>the ISO code</li> |
607 |
|
* </ul> |
608 |
|
* <p> |
609 |
|
* If the language is unspecified by this locale, then the empty string is |
610 |
|
* returned. |
611 |
|
* </p> |
612 |
* |
* |
613 |
* @param locale locale to use for formatting |
* @param inLocale the locale to use for formatting the display string. |
614 |
* @return the language name of this locale localized to the given locale, |
* @return the language name of this locale localized to the given locale, |
615 |
* with the ISO code as backup |
* with the default locale, English and the ISO code as backups. |
616 |
|
* @throws NullPointerException if the supplied locale is null. |
617 |
*/ |
*/ |
618 |
public String getDisplayLanguage(Locale locale) |
public String getDisplayLanguage(Locale inLocale) |
619 |
{ |
{ |
620 |
try |
return getDisplayString(inLocale, language, "languages"); |
|
{ |
|
|
ResourceBundle bundle |
|
|
= ResourceBundle.getBundle("java.util.iso639", locale); |
|
|
return bundle.getString(language); |
|
|
} |
|
|
catch (MissingResourceException ex) |
|
|
{ |
|
|
return language; |
|
|
} |
|
621 |
} |
} |
622 |
|
|
623 |
/** |
/** |
637 |
} |
} |
638 |
|
|
639 |
/** |
/** |
640 |
* Gets the country name suitable for display to the user, formatted |
* <p> |
641 |
* for a specified locale. |
* Gets the name of the country specified by this locale, in a form suitable |
642 |
|
* for display to the user. If possible, the display name will be localized |
643 |
|
* to the specified locale. For example, if the locale instance is |
644 |
|
* <code>Locale.GERMANY</code>, and the specified locale is <code>Locale.UK</code>, |
645 |
|
* the result would be 'Germany'. Using the German locale would instead give |
646 |
|
* 'Deutschland'. If the display name can not be localized to the supplied |
647 |
|
* locale, it will fall back on other output in the following order: |
648 |
|
* </p> |
649 |
|
* <ul> |
650 |
|
* <li>the display name in the default locale</li> |
651 |
|
* <li>the display name in English</li> |
652 |
|
* <li>the ISO code</li> |
653 |
|
* </ul> |
654 |
|
* <p> |
655 |
|
* If the country is unspecified by this locale, then the empty string is |
656 |
|
* returned. |
657 |
|
* </p> |
658 |
* |
* |
659 |
* @param locale locale to use for formatting |
* @param inLocale the locale to use for formatting the display string. |
660 |
* @return the country name of this locale localized to the given locale, |
* @return the country name of this locale localized to the given locale, |
661 |
* with the ISO code as backup |
* with the default locale, English and the ISO code as backups. |
662 |
|
* @throws NullPointerException if the supplied locale is null. |
663 |
*/ |
*/ |
664 |
public String getDisplayCountry(Locale locale) |
public String getDisplayCountry(Locale inLocale) |
665 |
{ |
{ |
666 |
try |
return getDisplayString(inLocale, country, "territories"); |
|
{ |
|
|
ResourceBundle bundle = |
|
|
ResourceBundle.getBundle("java.util.iso3166", locale); |
|
|
return bundle.getString(country); |
|
|
} |
|
|
catch (MissingResourceException ex) |
|
|
{ |
|
|
return country; |
|
|
} |
|
667 |
} |
} |
668 |
|
|
669 |
/** |
/** |
682 |
return getDisplayVariant(defaultLocale); |
return getDisplayVariant(defaultLocale); |
683 |
} |
} |
684 |
|
|
685 |
|
|
686 |
/** |
/** |
687 |
* Returns the variant name of this locale localized to the |
* <p> |
688 |
* given locale. If the localized is not found, the variant code |
* Gets the name of the variant specified by this locale, in a form suitable |
689 |
* itself is returned. |
* for display to the user. If possible, the display name will be localized |
690 |
* |
* to the specified locale. For example, if the locale instance is a revised |
691 |
* @param locale locale to use for formatting |
* variant, and the specified locale is <code>Locale.UK</code>, the result would be |
692 |
* @return the variant code of this locale localized to the given locale, |
* 'REVISED'. Using the German locale would instead give 'Revidiert'. If the |
693 |
* with the ISO code as backup |
* display name can not be localized to the supplied locale, it will fall back on |
694 |
|
* other output in the following order: |
695 |
|
* </p> |
696 |
|
* <ul> |
697 |
|
* <li>the display name in the default locale</li> |
698 |
|
* <li>the display name in English</li> |
699 |
|
* <li>the ISO code</li> |
700 |
|
* </ul> |
701 |
|
* <p> |
702 |
|
* If the variant is unspecified by this locale, then the empty string is |
703 |
|
* returned. |
704 |
|
* </p> |
705 |
|
* |
706 |
|
* @param inLocale the locale to use for formatting the display string. |
707 |
|
* @return the variant name of this locale localized to the given locale, |
708 |
|
* with the default locale, English and the ISO code as backups. |
709 |
|
* @throws NullPointerException if the supplied locale is null. |
710 |
|
*/ |
711 |
|
public String getDisplayVariant(Locale inLocale) |
712 |
|
{ |
713 |
|
return getDisplayString(inLocale, variant, "variants"); |
714 |
|
} |
715 |
|
|
716 |
|
/** |
717 |
|
* This method is used by the display name lookup methods to retrieve |
718 |
|
* the localized name of a particular piece of locale data. |
719 |
|
* If the display name can not be localized to the supplied |
720 |
|
* locale, it will fall back on other output in the following order: |
721 |
|
* </p> |
722 |
|
* <ul> |
723 |
|
* <li>the display name in the default locale</li> |
724 |
|
* <li>the display name in English</li> |
725 |
|
* <li>the ISO code</li> |
726 |
|
* </ul> |
727 |
|
* <p> |
728 |
|
* If the language is unspecified by this locale, then the empty string is |
729 |
|
* returned. |
730 |
|
* </p> |
731 |
|
* |
732 |
|
* @param inLocale the locale to use for formatting the display string. |
733 |
|
* @param key the locale data used as a key to the localized lookup tables. |
734 |
|
* @param tableName the name of the hashtable containing the localized data. |
735 |
*/ |
*/ |
736 |
public String getDisplayVariant(Locale locale) |
private String getDisplayString(Locale inLocale, String key, String tableName) |
737 |
{ |
{ |
738 |
// XXX - load a bundle? |
String displayString; |
739 |
return variant; |
Hashtable table; |
740 |
|
|
741 |
|
if (key.equals("")) |
742 |
|
{ |
743 |
|
return ""; |
744 |
|
} |
745 |
|
/* Display in inLocale */ |
746 |
|
try |
747 |
|
{ |
748 |
|
table = (Hashtable) |
749 |
|
ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", |
750 |
|
inLocale).getObject(tableName); |
751 |
|
displayString = (String) table.get(key); |
752 |
|
} |
753 |
|
catch (MissingResourceException exception) |
754 |
|
{ |
755 |
|
displayString = null; |
756 |
|
} |
757 |
|
/* Display in default locale */ |
758 |
|
if (displayString == null) |
759 |
|
{ |
760 |
|
try |
761 |
|
{ |
762 |
|
ResourceBundle bundle; |
763 |
|
|
764 |
|
bundle = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation"); |
765 |
|
table = (Hashtable) bundle.getObject(tableName); |
766 |
|
displayString = (String) table.get(key); |
767 |
|
} |
768 |
|
catch (MissingResourceException exception) |
769 |
|
{ |
770 |
|
displayString = null; |
771 |
|
} |
772 |
|
} |
773 |
|
/* Display in English */ |
774 |
|
if (displayString == null) |
775 |
|
{ |
776 |
|
try |
777 |
|
{ |
778 |
|
table = (Hashtable) |
779 |
|
ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", |
780 |
|
Locale.ENGLISH).getObject(tableName); |
781 |
|
displayString= (String) table.get(key); |
782 |
|
} |
783 |
|
catch (MissingResourceException exception) |
784 |
|
{ |
785 |
|
displayString = null; |
786 |
|
} |
787 |
|
} |
788 |
|
/* Display ISO code */ |
789 |
|
if (displayString == null) |
790 |
|
{ |
791 |
|
displayString = key; |
792 |
|
} |
793 |
|
return displayString; |
794 |
} |
} |
795 |
|
|
796 |
/** |
/** |