locdspnm.h 7.0 KB

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