1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2010-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
10 #ifndef __ULDNAMES_H__
11 #define __ULDNAMES_H__
15 * \brief C API: Provides display names of Locale ids and their components.
18 #include "unicode/utypes.h"
19 #include "unicode/localpointer.h"
20 #include "unicode/uscript.h"
21 #include "unicode/udisplaycontext.h"
24 * Enum used in LocaleDisplayNames::createInstance.
29 * Use standard names when generating a locale name,
30 * e.g. en_GB displays as 'English (United Kingdom)'.
33 ULDN_STANDARD_NAMES
= 0,
35 * Use dialect names, when generating a locale name,
36 * e.g. en_GB displays as 'British English'.
43 * Opaque C service object type for the locale display names API
46 struct ULocaleDisplayNames
;
49 * C typedef for struct ULocaleDisplayNames.
52 typedef struct ULocaleDisplayNames ULocaleDisplayNames
;
54 #if !UCONFIG_NO_FORMATTING
57 * Returns an instance of LocaleDisplayNames that returns names
58 * formatted for the provided locale, using the provided
59 * dialectHandling. The usual value for dialectHandling is
60 * ULDN_STANDARD_NAMES.
62 * @param locale the display locale
63 * @param dialectHandling how to select names for locales
64 * @return a ULocaleDisplayNames instance
65 * @param pErrorCode the status code
68 U_STABLE ULocaleDisplayNames
* U_EXPORT2
69 uldn_open(const char * locale
,
70 UDialectHandling dialectHandling
,
71 UErrorCode
*pErrorCode
);
74 * Closes a ULocaleDisplayNames instance obtained from uldn_open().
75 * @param ldn the ULocaleDisplayNames instance to be closed
78 U_STABLE
void U_EXPORT2
79 uldn_close(ULocaleDisplayNames
*ldn
);
81 #if U_SHOW_CPLUSPLUS_API
86 * \class LocalULocaleDisplayNamesPointer
87 * "Smart pointer" class, closes a ULocaleDisplayNames via uldn_close().
88 * For most methods see the LocalPointerBase base class.
90 * @see LocalPointerBase
94 U_DEFINE_LOCAL_OPEN_POINTER(LocalULocaleDisplayNamesPointer
, ULocaleDisplayNames
, uldn_close
);
100 /* getters for state */
103 * Returns the locale used to determine the display names. This is
104 * not necessarily the same locale passed to {@link #uldn_open}.
105 * @param ldn the LocaleDisplayNames instance
106 * @return the display locale
109 U_STABLE
const char * U_EXPORT2
110 uldn_getLocale(const ULocaleDisplayNames
*ldn
);
113 * Returns the dialect handling used in the display names.
114 * @param ldn the LocaleDisplayNames instance
115 * @return the dialect handling enum
118 U_STABLE UDialectHandling U_EXPORT2
119 uldn_getDialectHandling(const ULocaleDisplayNames
*ldn
);
121 /* names for entire locales */
124 * Returns the display name of the provided locale.
125 * @param ldn the LocaleDisplayNames instance
126 * @param locale the locale whose display name to return
127 * @param result receives the display name
128 * @param maxResultSize the size of the result buffer
129 * @param pErrorCode the status code
130 * @return the actual buffer size needed for the display name. If it's
131 * greater than maxResultSize, the returned name will be truncated.
134 U_STABLE
int32_t U_EXPORT2
135 uldn_localeDisplayName(const ULocaleDisplayNames
*ldn
,
138 int32_t maxResultSize
,
139 UErrorCode
*pErrorCode
);
141 /* names for components of a locale */
144 * Returns the display name of the provided language code.
145 * @param ldn the LocaleDisplayNames instance
146 * @param lang the language code whose display name to return
147 * @param result receives the display name
148 * @param maxResultSize the size of the result buffer
149 * @param pErrorCode the status code
150 * @return the actual buffer size needed for the display name. If it's
151 * greater than maxResultSize, the returned name will be truncated.
154 U_STABLE
int32_t U_EXPORT2
155 uldn_languageDisplayName(const ULocaleDisplayNames
*ldn
,
158 int32_t maxResultSize
,
159 UErrorCode
*pErrorCode
);
162 * Returns the display name of the provided script.
163 * @param ldn the LocaleDisplayNames instance
164 * @param script the script whose display name to return
165 * @param result receives the display name
166 * @param maxResultSize the size of the result buffer
167 * @param pErrorCode the status code
168 * @return the actual buffer size needed for the display name. If it's
169 * greater than maxResultSize, the returned name will be truncated.
172 U_STABLE
int32_t U_EXPORT2
173 uldn_scriptDisplayName(const ULocaleDisplayNames
*ldn
,
176 int32_t maxResultSize
,
177 UErrorCode
*pErrorCode
);
180 * Returns the display name of the provided script code.
181 * @param ldn the LocaleDisplayNames instance
182 * @param scriptCode the script code whose display name to return
183 * @param result receives the display name
184 * @param maxResultSize the size of the result buffer
185 * @param pErrorCode the status code
186 * @return the actual buffer size needed for the display name. If it's
187 * greater than maxResultSize, the returned name will be truncated.
190 U_STABLE
int32_t U_EXPORT2
191 uldn_scriptCodeDisplayName(const ULocaleDisplayNames
*ldn
,
192 UScriptCode scriptCode
,
194 int32_t maxResultSize
,
195 UErrorCode
*pErrorCode
);
198 * Returns the display name of the provided region code.
199 * @param ldn the LocaleDisplayNames instance
200 * @param region the region code whose display name to return
201 * @param result receives the display name
202 * @param maxResultSize the size of the result buffer
203 * @param pErrorCode the status code
204 * @return the actual buffer size needed for the display name. If it's
205 * greater than maxResultSize, the returned name will be truncated.
208 U_STABLE
int32_t U_EXPORT2
209 uldn_regionDisplayName(const ULocaleDisplayNames
*ldn
,
212 int32_t maxResultSize
,
213 UErrorCode
*pErrorCode
);
216 * Returns the display name of the provided variant
217 * @param ldn the LocaleDisplayNames instance
218 * @param variant the variant whose display name to return
219 * @param result receives the display name
220 * @param maxResultSize the size of the result buffer
221 * @param pErrorCode the status code
222 * @return the actual buffer size needed for the display name. If it's
223 * greater than maxResultSize, the returned name will be truncated.
226 U_STABLE
int32_t U_EXPORT2
227 uldn_variantDisplayName(const ULocaleDisplayNames
*ldn
,
230 int32_t maxResultSize
,
231 UErrorCode
*pErrorCode
);
234 * Returns the display name of the provided locale key
235 * @param ldn the LocaleDisplayNames instance
236 * @param key the locale key whose display name to return
237 * @param result receives the display name
238 * @param maxResultSize the size of the result buffer
239 * @param pErrorCode the status code
240 * @return the actual buffer size needed for the display name. If it's
241 * greater than maxResultSize, the returned name will be truncated.
244 U_STABLE
int32_t U_EXPORT2
245 uldn_keyDisplayName(const ULocaleDisplayNames
*ldn
,
248 int32_t maxResultSize
,
249 UErrorCode
*pErrorCode
);
252 * Returns the display name of the provided value (used with the provided key).
253 * @param ldn the LocaleDisplayNames instance
254 * @param key the locale key
255 * @param value the locale key's value
256 * @param result receives the display name
257 * @param maxResultSize the size of the result buffer
258 * @param pErrorCode the status code
259 * @return the actual buffer size needed for the display name. If it's
260 * greater than maxResultSize, the returned name will be truncated.
263 U_STABLE
int32_t U_EXPORT2
264 uldn_keyValueDisplayName(const ULocaleDisplayNames
*ldn
,
268 int32_t maxResultSize
,
269 UErrorCode
*pErrorCode
);
272 * Returns an instance of LocaleDisplayNames that returns names formatted
273 * for the provided locale, using the provided UDisplayContext settings.
275 * @param locale The display locale
276 * @param contexts List of one or more context settings (e.g. for dialect
277 * handling, capitalization, etc.
278 * @param length Number of items in the contexts list
279 * @param pErrorCode Pointer to UErrorCode input/output status. If at entry this indicates
280 * a failure status, the function will do nothing; otherwise this will be
281 * updated with any new status from the function.
282 * @return a ULocaleDisplayNames instance
285 U_STABLE ULocaleDisplayNames
* U_EXPORT2
286 uldn_openForContext(const char * locale
, UDisplayContext
*contexts
,
287 int32_t length
, UErrorCode
*pErrorCode
);
290 * Returns the UDisplayContext value for the specified UDisplayContextType.
291 * @param ldn the ULocaleDisplayNames instance
292 * @param type the UDisplayContextType whose value to return
293 * @param pErrorCode Pointer to UErrorCode input/output status. If at entry this indicates
294 * a failure status, the function will do nothing; otherwise this will be
295 * updated with any new status from the function.
296 * @return the UDisplayContextValue for the specified type.
299 U_STABLE UDisplayContext U_EXPORT2
300 uldn_getContext(const ULocaleDisplayNames
*ldn
, UDisplayContextType type
,
301 UErrorCode
*pErrorCode
);
303 #endif /* !UCONFIG_NO_FORMATTING */
304 #endif /* __ULDNAMES_H__ */