locdspnm.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. ******************************************************************************
  3. * Copyright (C) 2010-2016, International Business Machines Corporation and
  4. * others. All Rights Reserved.
  5. ******************************************************************************
  6. */
  7. #ifndef LOCDSPNM_H
  8. #define LOCDSPNM_H
  9. #include "unicode/utypes.h"
  10. /**
  11. * \file
  12. * \brief C++ API: Provides display names of Locale and its components.
  13. */
  14. #if !UCONFIG_NO_FORMATTING
  15. #include "unicode/locid.h"
  16. #include "unicode/uscript.h"
  17. #include "unicode/uldnames.h"
  18. #include "unicode/udisplaycontext.h"
  19. U_NAMESPACE_BEGIN
  20. /**
  21. * Returns display names of Locales and components of Locales. For
  22. * more information on language, script, region, variant, key, and
  23. * values, see Locale.
  24. * @stable ICU 4.4
  25. */
  26. class U_COMMON_API LocaleDisplayNames : public UObject {
  27. public:
  28. /**
  29. * Destructor.
  30. * @stable ICU 4.4
  31. */
  32. virtual ~LocaleDisplayNames();
  33. /**
  34. * Convenience overload of
  35. * {@link #createInstance(const Locale& locale, UDialectHandling dialectHandling)}
  36. * that specifies STANDARD dialect handling.
  37. * @param locale the display locale
  38. * @return a LocaleDisplayNames instance
  39. * @stable ICU 4.4
  40. */
  41. static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale);
  42. /**
  43. * Returns an instance of LocaleDisplayNames that returns names
  44. * formatted for the provided locale, using the provided
  45. * dialectHandling.
  46. *
  47. * @param locale the display locale
  48. * @param dialectHandling how to select names for locales
  49. * @return a LocaleDisplayNames instance
  50. * @stable ICU 4.4
  51. */
  52. static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
  53. UDialectHandling dialectHandling);
  54. /**
  55. * Returns an instance of LocaleDisplayNames that returns names formatted
  56. * for the provided locale, using the provided UDisplayContext settings.
  57. *
  58. * @param locale the display locale
  59. * @param contexts List of one or more context settings (e.g. for dialect
  60. * handling, capitalization, etc.
  61. * @param length Number of items in the contexts list
  62. * @return a LocaleDisplayNames instance
  63. * @stable ICU 51
  64. */
  65. static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
  66. UDisplayContext *contexts, int32_t length);
  67. // getters for state
  68. /**
  69. * Returns the locale used to determine the display names. This is
  70. * not necessarily the same locale passed to {@link #createInstance}.
  71. * @return the display locale
  72. * @stable ICU 4.4
  73. */
  74. virtual const Locale& getLocale() const = 0;
  75. /**
  76. * Returns the dialect handling used in the display names.
  77. * @return the dialect handling enum
  78. * @stable ICU 4.4
  79. */
  80. virtual UDialectHandling getDialectHandling() const = 0;
  81. /**
  82. * Returns the UDisplayContext value for the specified UDisplayContextType.
  83. * @param type the UDisplayContextType whose value to return
  84. * @return the UDisplayContext for the specified type.
  85. * @stable ICU 51
  86. */
  87. virtual UDisplayContext getContext(UDisplayContextType type) const = 0;
  88. // names for entire locales
  89. /**
  90. * Returns the display name of the provided locale.
  91. * @param locale the locale whose display name to return
  92. * @param result receives the locale's display name
  93. * @return the display name of the provided locale
  94. * @stable ICU 4.4
  95. */
  96. virtual UnicodeString& localeDisplayName(const Locale& locale,
  97. UnicodeString& result) const = 0;
  98. /**
  99. * Returns the display name of the provided locale id.
  100. * @param localeId the id of the locale whose display name to return
  101. * @param result receives the locale's display name
  102. * @return the display name of the provided locale
  103. * @stable ICU 4.4
  104. */
  105. virtual UnicodeString& localeDisplayName(const char* localeId,
  106. UnicodeString& result) const = 0;
  107. // names for components of a locale id
  108. /**
  109. * Returns the display name of the provided language code.
  110. * @param lang the language code
  111. * @param result receives the language code's display name
  112. * @return the display name of the provided language code
  113. * @stable ICU 4.4
  114. */
  115. virtual UnicodeString& languageDisplayName(const char* lang,
  116. UnicodeString& result) const = 0;
  117. /**
  118. * Returns the display name of the provided script code.
  119. * @param script the script code
  120. * @param result receives the script code's display name
  121. * @return the display name of the provided script code
  122. * @stable ICU 4.4
  123. */
  124. virtual UnicodeString& scriptDisplayName(const char* script,
  125. UnicodeString& result) const = 0;
  126. /**
  127. * Returns the display name of the provided script code.
  128. * @param scriptCode the script code number
  129. * @param result receives the script code's display name
  130. * @return the display name of the provided script code
  131. * @stable ICU 4.4
  132. */
  133. virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
  134. UnicodeString& result) const = 0;
  135. /**
  136. * Returns the display name of the provided region code.
  137. * @param region the region code
  138. * @param result receives the region code's display name
  139. * @return the display name of the provided region code
  140. * @stable ICU 4.4
  141. */
  142. virtual UnicodeString& regionDisplayName(const char* region,
  143. UnicodeString& result) const = 0;
  144. /**
  145. * Returns the display name of the provided variant.
  146. * @param variant the variant string
  147. * @param result receives the variant's display name
  148. * @return the display name of the provided variant
  149. * @stable ICU 4.4
  150. */
  151. virtual UnicodeString& variantDisplayName(const char* variant,
  152. UnicodeString& result) const = 0;
  153. /**
  154. * Returns the display name of the provided locale key.
  155. * @param key the locale key name
  156. * @param result receives the locale key's display name
  157. * @return the display name of the provided locale key
  158. * @stable ICU 4.4
  159. */
  160. virtual UnicodeString& keyDisplayName(const char* key,
  161. UnicodeString& result) const = 0;
  162. /**
  163. * Returns the display name of the provided value (used with the provided key).
  164. * @param key the locale key name
  165. * @param value the locale key's value
  166. * @param result receives the value's display name
  167. * @return the display name of the provided value
  168. * @stable ICU 4.4
  169. */
  170. virtual UnicodeString& keyValueDisplayName(const char* key, const char* value,
  171. UnicodeString& result) const = 0;
  172. };
  173. inline LocaleDisplayNames* LocaleDisplayNames::createInstance(const Locale& locale) {
  174. return LocaleDisplayNames::createInstance(locale, ULDN_STANDARD_NAMES);
  175. }
  176. U_NAMESPACE_END
  177. #endif
  178. #endif