uldnames.h 10 KB

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