uldnames.h 10 KB

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