uldnames.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 __ULDNAMES_H__
  10. #define __ULDNAMES_H__
  11. /**
  12. * \file
  13. * \brief C API: Provides display names of Locale ids and their components.
  14. */
  15. #include "unicode/utypes.h"
  16. #include "unicode/localpointer.h"
  17. #include "unicode/uscript.h"
  18. #include "unicode/udisplaycontext.h"
  19. /**
  20. * Enum used in LocaleDisplayNames::createInstance.
  21. * @stable ICU 4.4
  22. */
  23. typedef enum {
  24. /**
  25. * Use standard names when generating a locale name,
  26. * e.g. en_GB displays as 'English (United Kingdom)'.
  27. * @stable ICU 4.4
  28. */
  29. ULDN_STANDARD_NAMES = 0,
  30. /**
  31. * Use dialect names, when generating a locale name,
  32. * e.g. en_GB displays as 'British English'.
  33. * @stable ICU 4.4
  34. */
  35. ULDN_DIALECT_NAMES
  36. } UDialectHandling;
  37. /**
  38. * Opaque C service object type for the locale display names API
  39. * @stable ICU 4.4
  40. */
  41. struct ULocaleDisplayNames;
  42. /**
  43. * C typedef for struct ULocaleDisplayNames.
  44. * @stable ICU 4.4
  45. */
  46. typedef struct ULocaleDisplayNames ULocaleDisplayNames;
  47. #if !UCONFIG_NO_FORMATTING
  48. /**
  49. * Returns an instance of LocaleDisplayNames that returns names
  50. * formatted for the provided locale, using the provided
  51. * dialectHandling. The usual value for dialectHandling is
  52. * ULOC_STANDARD_NAMES.
  53. *
  54. * @param locale the display locale
  55. * @param dialectHandling how to select names for locales
  56. * @return a ULocaleDisplayNames instance
  57. * @param pErrorCode the status code
  58. * @stable ICU 4.4
  59. */
  60. U_STABLE ULocaleDisplayNames * U_EXPORT2
  61. uldn_open(const char * locale,
  62. UDialectHandling dialectHandling,
  63. UErrorCode *pErrorCode);
  64. /**
  65. * Closes a ULocaleDisplayNames instance obtained from uldn_open().
  66. * @param ldn the ULocaleDisplayNames instance to be closed
  67. * @stable ICU 4.4
  68. */
  69. U_STABLE void U_EXPORT2
  70. uldn_close(ULocaleDisplayNames *ldn);
  71. #if U_SHOW_CPLUSPLUS_API
  72. U_NAMESPACE_BEGIN
  73. /**
  74. * \class LocalULocaleDisplayNamesPointer
  75. * "Smart pointer" class, closes a ULocaleDisplayNames via uldn_close().
  76. * For most methods see the LocalPointerBase base class.
  77. *
  78. * @see LocalPointerBase
  79. * @see LocalPointer
  80. * @stable ICU 4.4
  81. */
  82. U_DEFINE_LOCAL_OPEN_POINTER(LocalULocaleDisplayNamesPointer, ULocaleDisplayNames, uldn_close);
  83. U_NAMESPACE_END
  84. #endif
  85. /* getters for state */
  86. /**
  87. * Returns the locale used to determine the display names. This is
  88. * not necessarily the same locale passed to {@link #uldn_open}.
  89. * @param ldn the LocaleDisplayNames instance
  90. * @return the display locale
  91. * @stable ICU 4.4
  92. */
  93. U_STABLE const char * U_EXPORT2
  94. uldn_getLocale(const ULocaleDisplayNames *ldn);
  95. /**
  96. * Returns the dialect handling used in the display names.
  97. * @param ldn the LocaleDisplayNames instance
  98. * @return the dialect handling enum
  99. * @stable ICU 4.4
  100. */
  101. U_STABLE UDialectHandling U_EXPORT2
  102. uldn_getDialectHandling(const ULocaleDisplayNames *ldn);
  103. /* names for entire locales */
  104. /**
  105. * Returns the display name of the provided locale.
  106. * @param ldn the LocaleDisplayNames instance
  107. * @param locale the locale whose display name to return
  108. * @param result receives the display name
  109. * @param maxResultSize the size of the result buffer
  110. * @param pErrorCode the status code
  111. * @return the actual buffer size needed for the display name. If it's
  112. * greater than maxResultSize, the returned name will be truncated.
  113. * @stable ICU 4.4
  114. */
  115. U_STABLE int32_t U_EXPORT2
  116. uldn_localeDisplayName(const ULocaleDisplayNames *ldn,
  117. const char *locale,
  118. UChar *result,
  119. int32_t maxResultSize,
  120. UErrorCode *pErrorCode);
  121. /* names for components of a locale */
  122. /**
  123. * Returns the display name of the provided language code.
  124. * @param ldn the LocaleDisplayNames instance
  125. * @param lang the language code whose display name to return
  126. * @param result receives the display name
  127. * @param maxResultSize the size of the result buffer
  128. * @param pErrorCode the status code
  129. * @return the actual buffer size needed for the display name. If it's
  130. * greater than maxResultSize, the returned name will be truncated.
  131. * @stable ICU 4.4
  132. */
  133. U_STABLE int32_t U_EXPORT2
  134. uldn_languageDisplayName(const ULocaleDisplayNames *ldn,
  135. const char *lang,
  136. UChar *result,
  137. int32_t maxResultSize,
  138. UErrorCode *pErrorCode);
  139. /**
  140. * Returns the display name of the provided script.
  141. * @param ldn the LocaleDisplayNames instance
  142. * @param script the script whose display name to return
  143. * @param result receives the display name
  144. * @param maxResultSize the size of the result buffer
  145. * @param pErrorCode the status code
  146. * @return the actual buffer size needed for the display name. If it's
  147. * greater than maxResultSize, the returned name will be truncated.
  148. * @stable ICU 4.4
  149. */
  150. U_STABLE int32_t U_EXPORT2
  151. uldn_scriptDisplayName(const ULocaleDisplayNames *ldn,
  152. const char *script,
  153. UChar *result,
  154. int32_t maxResultSize,
  155. UErrorCode *pErrorCode);
  156. /**
  157. * Returns the display name of the provided script code.
  158. * @param ldn the LocaleDisplayNames instance
  159. * @param scriptCode the script code whose display name to return
  160. * @param result receives the display name
  161. * @param maxResultSize the size of the result buffer
  162. * @param pErrorCode the status code
  163. * @return the actual buffer size needed for the display name. If it's
  164. * greater than maxResultSize, the returned name will be truncated.
  165. * @stable ICU 4.4
  166. */
  167. U_STABLE int32_t U_EXPORT2
  168. uldn_scriptCodeDisplayName(const ULocaleDisplayNames *ldn,
  169. UScriptCode scriptCode,
  170. UChar *result,
  171. int32_t maxResultSize,
  172. UErrorCode *pErrorCode);
  173. /**
  174. * Returns the display name of the provided region code.
  175. * @param ldn the LocaleDisplayNames instance
  176. * @param region the region code whose display name to return
  177. * @param result receives the display name
  178. * @param maxResultSize the size of the result buffer
  179. * @param pErrorCode the status code
  180. * @return the actual buffer size needed for the display name. If it's
  181. * greater than maxResultSize, the returned name will be truncated.
  182. * @stable ICU 4.4
  183. */
  184. U_STABLE int32_t U_EXPORT2
  185. uldn_regionDisplayName(const ULocaleDisplayNames *ldn,
  186. const char *region,
  187. UChar *result,
  188. int32_t maxResultSize,
  189. UErrorCode *pErrorCode);
  190. /**
  191. * Returns the display name of the provided variant
  192. * @param ldn the LocaleDisplayNames instance
  193. * @param variant the variant whose display name to return
  194. * @param result receives the display name
  195. * @param maxResultSize the size of the result buffer
  196. * @param pErrorCode the status code
  197. * @return the actual buffer size needed for the display name. If it's
  198. * greater than maxResultSize, the returned name will be truncated.
  199. * @stable ICU 4.4
  200. */
  201. U_STABLE int32_t U_EXPORT2
  202. uldn_variantDisplayName(const ULocaleDisplayNames *ldn,
  203. const char *variant,
  204. UChar *result,
  205. int32_t maxResultSize,
  206. UErrorCode *pErrorCode);
  207. /**
  208. * Returns the display name of the provided locale key
  209. * @param ldn the LocaleDisplayNames instance
  210. * @param key the locale key whose display name to return
  211. * @param result receives the display name
  212. * @param maxResultSize the size of the result buffer
  213. * @param pErrorCode the status code
  214. * @return the actual buffer size needed for the display name. If it's
  215. * greater than maxResultSize, the returned name will be truncated.
  216. * @stable ICU 4.4
  217. */
  218. U_STABLE int32_t U_EXPORT2
  219. uldn_keyDisplayName(const ULocaleDisplayNames *ldn,
  220. const char *key,
  221. UChar *result,
  222. int32_t maxResultSize,
  223. UErrorCode *pErrorCode);
  224. /**
  225. * Returns the display name of the provided value (used with the provided key).
  226. * @param ldn the LocaleDisplayNames instance
  227. * @param key the locale key
  228. * @param value the locale key's value
  229. * @param result receives the display name
  230. * @param maxResultSize the size of the result buffer
  231. * @param pErrorCode the status code
  232. * @return the actual buffer size needed for the display name. If it's
  233. * greater than maxResultSize, the returned name will be truncated.
  234. * @stable ICU 4.4
  235. */
  236. U_STABLE int32_t U_EXPORT2
  237. uldn_keyValueDisplayName(const ULocaleDisplayNames *ldn,
  238. const char *key,
  239. const char *value,
  240. UChar *result,
  241. int32_t maxResultSize,
  242. UErrorCode *pErrorCode);
  243. /**
  244. * Returns an instance of LocaleDisplayNames that returns names formatted
  245. * for the provided locale, using the provided UDisplayContext settings.
  246. *
  247. * @param locale The display locale
  248. * @param contexts List of one or more context settings (e.g. for dialect
  249. * handling, capitalization, etc.
  250. * @param length Number of items in the contexts list
  251. * @param pErrorCode Pointer to UErrorCode input/output status. If at entry this indicates
  252. * a failure status, the function will do nothing; otherwise this will be
  253. * updated with any new status from the function.
  254. * @return a ULocaleDisplayNames instance
  255. * @stable ICU 51
  256. */
  257. U_STABLE ULocaleDisplayNames * U_EXPORT2
  258. uldn_openForContext(const char * locale, UDisplayContext *contexts,
  259. int32_t length, UErrorCode *pErrorCode);
  260. /**
  261. * Returns the UDisplayContext value for the specified UDisplayContextType.
  262. * @param ldn the ULocaleDisplayNames instance
  263. * @param type the UDisplayContextType whose value to return
  264. * @param pErrorCode Pointer to UErrorCode input/output status. If at entry this indicates
  265. * a failure status, the function will do nothing; otherwise this will be
  266. * updated with any new status from the function.
  267. * @return the UDisplayContextValue for the specified type.
  268. * @stable ICU 51
  269. */
  270. U_STABLE UDisplayContext U_EXPORT2
  271. uldn_getContext(const ULocaleDisplayNames *ldn, UDisplayContextType type,
  272. UErrorCode *pErrorCode);
  273. #endif /* !UCONFIG_NO_FORMATTING */
  274. #endif /* __ULDNAMES_H__ */