locdspnm.h 7.1 KB

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