2 **********************************************************************
3 * Copyright (C) 1997-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
9 * Modification History:
11 * Date Name Description
12 * 04/01/97 aliu Creation.
13 * 08/22/98 stephen JDK 1.2 sync.
14 * 12/08/98 rtg New C API for Locale
15 * 03/30/99 damiba overhaul
16 * 03/31/99 helena Javadoc for uloc functions.
17 * 04/15/99 Madhu Updated Javadoc
18 ********************************************************************************
24 #include "unicode/utypes.h"
25 #include "unicode/uenum.h"
29 * \brief C API: Locale
31 * <h2> ULoc C API for Locale </h2>
32 * A <code>Locale</code> represents a specific geographical, political,
33 * or cultural region. An operation that requires a <code>Locale</code> to perform
34 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
35 * to tailor information for the user. For example, displaying a number
36 * is a locale-sensitive operation--the number should be formatted
37 * according to the customs/conventions of the user's native country,
38 * region, or culture. In the C APIs, a locales is simply a const char string.
41 * You create a <code>Locale</code> with one of the three options listed below.
42 * Each of the component is separated by '_' in the locale string.
43 * \htmlonly<blockquote>\endhtmlonly
48 * newLanguage + newCountry
50 * newLanguage + newCountry + newVariant
53 * \htmlonly</blockquote>\endhtmlonly
54 * The first option is a valid <STRONG>ISO
55 * Language Code.</STRONG> These codes are the lower-case two-letter
56 * codes as defined by ISO-639.
57 * You can find a full list of these codes at a number of sites, such as:
58 * <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt">
59 * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</a>
62 * The second option includes an additonal <STRONG>ISO Country
63 * Code.</STRONG> These codes are the upper-case two-letter codes
64 * as defined by ISO-3166.
65 * You can find a full list of these codes at a number of sites, such as:
66 * <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html">
67 * http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</a>
70 * The third option requires another additonal information--the
71 * <STRONG>Variant.</STRONG>
72 * The Variant codes are vendor and browser-specific.
73 * For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
74 * Where there are two variants, separate them with an underscore, and
75 * put the most important one first. For
76 * example, a Traditional Spanish collation might be referenced, with
77 * "ES", "ES", "Traditional_WIN".
80 * Because a <code>Locale</code> is just an identifier for a region,
81 * no validity check is performed when you specify a <code>Locale</code>.
82 * If you want to see whether particular resources are available for the
83 * <code>Locale</code> you asked for, you must query those resources. For
84 * example, ask the <code>UNumberFormat</code> for the locales it supports
85 * using its <code>getAvailable</code> method.
86 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
87 * locale, you get back the best available match, not necessarily
88 * precisely what you asked for. For more information, look at
89 * <code>UResourceBundle</code>.
92 * The <code>Locale</code> provides a number of convenient constants
93 * that you can use to specify the commonly used
94 * locales. For example, the following refers to a locale
95 * for the United States:
96 * \htmlonly<blockquote>\endhtmlonly
102 * \htmlonly</blockquote>\endhtmlonly
105 * Once you've specified a locale you can query it for information about
106 * itself. Use <code>uloc_getCountry</code> to get the ISO Country Code and
107 * <code>uloc_getLanguage</code> to get the ISO Language Code. You can
108 * use <code>uloc_getDisplayCountry</code> to get the
109 * name of the country suitable for displaying to the user. Similarly,
110 * you can use <code>uloc_getDisplayLanguage</code> to get the name of
111 * the language suitable for displaying to the user. Interestingly,
112 * the <code>uloc_getDisplayXXX</code> methods are themselves locale-sensitive
113 * and have two versions: one that uses the default locale and one
114 * that takes a locale as an argument and displays the name or country in
115 * a language appropriate to that locale.
118 * The ICU provides a number of services that perform locale-sensitive
119 * operations. For example, the <code>unum_xxx</code> functions format
120 * numbers, currency, or percentages in a locale-sensitive manner.
122 * \htmlonly<blockquote>\endhtmlonly
125 * UErrorCode success = U_ZERO_ERROR;
127 * const char* myLocale = "fr_FR";
129 * nf = unum_open( UNUM_DEFAULT, NULL, success );
131 * nf = unum_open( UNUM_CURRENCY, NULL, success );
133 * nf = unum_open( UNUM_PERCENT, NULL, success );
137 * \htmlonly</blockquote>\endhtmlonly
138 * Each of these methods has two variants; one with an explicit locale
139 * and one without; the latter using the default locale.
140 * \htmlonly<blockquote>\endhtmlonly
144 * nf = unum_open( UNUM_DEFAULT, myLocale, success );
146 * nf = unum_open( UNUM_CURRENCY, myLocale, success );
148 * nf = unum_open( UNUM_PERCENT, myLocale, success );
152 * \htmlonly</blockquote>\endhtmlonly
153 * A <code>Locale</code> is the mechanism for identifying the kind of services
154 * (<code>UNumberFormat</code>) that you would like to get. The locale is
155 * <STRONG>just</STRONG> a mechanism for identifying these services.
158 * Each international serivce that performs locale-sensitive operations
160 * to get all the available objects of that type. You can sift
161 * through these objects by language, country, or variant,
162 * and use the display names to present a menu to the user.
163 * For example, you can create a menu of all the collation objects
164 * suitable for a given language. Such classes implement these
165 * three class methods:
166 * \htmlonly<blockquote>\endhtmlonly
169 * const char* uloc_getAvailable(int32_t index);
170 * int32_t uloc_countAvailable();
172 * uloc_getDisplayName(const char* localeID,
173 * const char* inLocaleID,
175 * int32_t maxResultSize,
180 * \htmlonly</blockquote>\endhtmlonly
182 * Concerning POSIX/RFC1766 Locale IDs,
183 * the getLanguage/getCountry/getVariant/getName functions do understand
184 * the POSIX type form of language_COUNTRY.ENCODING\@VARIANT
185 * and if there is not an ICU-stype variant, uloc_getVariant() for example
186 * will return the one listed after the \@at sign. As well, the hyphen
187 * "-" is recognized as a country/variant separator similarly to RFC1766.
188 * So for example, "en-us" will be interpreted as en_US.
189 * As a result, uloc_getName() is far from a no-op, and will have the
190 * effect of converting POSIX/RFC1766 IDs into ICU form, although it does
191 * NOT map any of the actual codes (i.e. russian->ru) in any way.
192 * Applications should call uloc_getName() at the point where a locale ID
193 * is coming from an external source (user entry, OS, web browser)
194 * and pass the resulting string to other ICU functions. For example,
195 * don't use de-de\@EURO as an argument to resourcebundle.
197 * @see UResourceBundle
200 /** Useful constant for this language. @stable ICU 2.0 */
201 #define ULOC_CHINESE "zh"
202 /** Useful constant for this language. @stable ICU 2.0 */
203 #define ULOC_ENGLISH "en"
204 /** Useful constant for this language. @stable ICU 2.0 */
205 #define ULOC_FRENCH "fr"
206 /** Useful constant for this language. @stable ICU 2.0 */
207 #define ULOC_GERMAN "de"
208 /** Useful constant for this language. @stable ICU 2.0 */
209 #define ULOC_ITALIAN "it"
210 /** Useful constant for this language. @stable ICU 2.0 */
211 #define ULOC_JAPANESE "ja"
212 /** Useful constant for this language. @stable ICU 2.0 */
213 #define ULOC_KOREAN "ko"
214 /** Useful constant for this language. @stable ICU 2.0 */
215 #define ULOC_SIMPLIFIED_CHINESE "zh_CN"
216 /** Useful constant for this language. @stable ICU 2.0 */
217 #define ULOC_TRADITIONAL_CHINESE "zh_TW"
219 /** Useful constant for this country/region. @stable ICU 2.0 */
220 #define ULOC_CANADA "en_CA"
221 /** Useful constant for this country/region. @stable ICU 2.0 */
222 #define ULOC_CANADA_FRENCH "fr_CA"
223 /** Useful constant for this country/region. @stable ICU 2.0 */
224 #define ULOC_CHINA "zh_CN"
225 /** Useful constant for this country/region. @stable ICU 2.0 */
226 #define ULOC_PRC "zh_CN"
227 /** Useful constant for this country/region. @stable ICU 2.0 */
228 #define ULOC_FRANCE "fr_FR"
229 /** Useful constant for this country/region. @stable ICU 2.0 */
230 #define ULOC_GERMANY "de_DE"
231 /** Useful constant for this country/region. @stable ICU 2.0 */
232 #define ULOC_ITALY "it_IT"
233 /** Useful constant for this country/region. @stable ICU 2.0 */
234 #define ULOC_JAPAN "ja_JP"
235 /** Useful constant for this country/region. @stable ICU 2.0 */
236 #define ULOC_KOREA "ko_KR"
237 /** Useful constant for this country/region. @stable ICU 2.0 */
238 #define ULOC_TAIWAN "zh_TW"
239 /** Useful constant for this country/region. @stable ICU 2.0 */
240 #define ULOC_UK "en_GB"
241 /** Useful constant for this country/region. @stable ICU 2.0 */
242 #define ULOC_US "en_US"
245 * Useful constant for the maximum size of the language part of a locale ID.
246 * (including the terminating NULL).
249 #define ULOC_LANG_CAPACITY 12
252 * Useful constant for the maximum size of the country part of a locale ID
253 * (including the terminating NULL).
256 #define ULOC_COUNTRY_CAPACITY 4
258 * Useful constant for the maximum size of the whole locale ID
259 * (including the terminating NULL).
262 #define ULOC_FULLNAME_CAPACITY 56
265 #ifndef U_HIDE_DRAFT_API
268 * Useful constant for the maximum size of the script part of a locale ID
269 * (including the terminating NULL).
272 #define ULOC_SCRIPT_CAPACITY 6
275 * Useful constant for the maximum size of keywords in a locale
278 #define ULOC_KEYWORDS_CAPACITY 50
281 * Useful constant for the maximum size of keywords in a locale
284 #define ULOC_KEYWORD_AND_VALUES_CAPACITY 100
287 * Character separating keywords from the locale string
288 * different for EBCDIC - TODO
291 #define ULOC_KEYWORD_SEPARATOR '@'
293 * Character for assigning value to a keyword
296 #define ULOC_KEYWORD_ASSIGN '='
298 * Character separating keywords
301 #define ULOC_KEYWORD_ITEM_SEPARATOR ';'
303 #endif /*U_HIDE_DRAFT_API*/
306 * Constants for *_getLocale()
307 * Allow user to select whether she wants information on
308 * requested, valid or actual locale.
309 * For example, a collator for "en_US_CALIFORNIA" was
310 * requested. In the current state of ICU (2.0),
311 * the requested locale is "en_US_CALIFORNIA",
312 * the valid locale is "en_US" (most specific locale supported by ICU)
313 * and the actual locale is "root" (the collation data comes unmodified
315 * The locale is considered supported by ICU if there is a core ICU bundle
316 * for that locale (although it may be empty).
320 /** This is locale the data actually comes from
323 ULOC_ACTUAL_LOCALE
= 0,
324 /** This is the most specific locale supported by ICU
327 ULOC_VALID_LOCALE
= 1,
329 #ifndef U_HIDE_DEPRECATED_API
330 /** This is the requested locale
331 * @deprecated ICU 2.8
333 ULOC_REQUESTED_LOCALE
= 2,
334 #endif /* U_HIDE_DEPRECATED_API */
336 ULOC_DATA_LOCALE_TYPE_LIMIT
337 } ULocDataLocaleType
;
341 * Gets ICU's default locale.
342 * The returned string is a snapshot in time, and will remain valid
343 * and unchanged even when uloc_setDefault() is called.
344 * The returned storage is owned by ICU, and must not be altered or deleted
347 * @return the ICU default locale
351 U_STABLE
const char* U_EXPORT2
352 uloc_getDefault(void);
355 * Sets ICU's default locale.
356 * By default (without calling this function), ICU's default locale will be based
357 * on information obtained from the underlying system environment.
359 * Changes to ICU's default locale do not propagate back to the
360 * system environment.
362 * Changes to ICU's default locale to not affect any ICU services that
363 * may already be open based on the previous default locale value.
365 * @param localeID the new ICU default locale. A value of NULL will try to get
366 * the system's default locale.
367 * @param status the error information if the setting of default locale fails
371 U_STABLE
void U_EXPORT2
372 uloc_setDefault(const char* localeID
,
376 * Gets the language code for the specified locale.
378 * @param localeID the locale to get the ISO language code with
379 * @param language the language code for localeID
380 * @param languageCapacity the size of the language buffer to store the
382 * @param err error information if retrieving the language code failed
383 * @return the actual buffer size needed for the language code. If it's greater
384 * than languageCapacity, the returned language code will be truncated.
387 U_STABLE
int32_t U_EXPORT2
388 uloc_getLanguage(const char* localeID
,
390 int32_t languageCapacity
,
394 * Gets the script code for the specified locale.
396 * @param localeID the locale to get the ISO language code with
397 * @param script the language code for localeID
398 * @param scriptCapacity the size of the language buffer to store the
400 * @param err error information if retrieving the language code failed
401 * @return the actual buffer size needed for the language code. If it's greater
402 * than scriptCapacity, the returned language code will be truncated.
405 U_DRAFT
int32_t U_EXPORT2
406 uloc_getScript(const char* localeID
,
408 int32_t scriptCapacity
,
412 * Gets the country code for the specified locale.
414 * @param localeID the locale to get the country code with
415 * @param country the country code for localeID
416 * @param countryCapacity the size of the country buffer to store the
418 * @param err error information if retrieving the country code failed
419 * @return the actual buffer size needed for the country code. If it's greater
420 * than countryCapacity, the returned country code will be truncated.
423 U_DRAFT
int32_t U_EXPORT2
424 uloc_getCountry(const char* localeID
,
426 int32_t countryCapacity
,
430 * Gets the variant code for the specified locale.
432 * @param localeID the locale to get the variant code with
433 * @param variant the variant code for localeID
434 * @param variantCapacity the size of the variant buffer to store the
436 * @param err error information if retrieving the variant code failed
437 * @return the actual buffer size needed for the variant code. If it's greater
438 * than variantCapacity, the returned variant code will be truncated.
441 U_STABLE
int32_t U_EXPORT2
442 uloc_getVariant(const char* localeID
,
444 int32_t variantCapacity
,
449 * Gets the full name for the specified locale.
450 * Note: This has the effect of 'canonicalizing' the ICU locale ID to
451 * a certain extent. Upper and lower case are set as needed.
452 * It does NOT map aliased names in any way.
453 * See the top of this header file.
454 * This API supports preflighting.
456 * @param localeID the locale to get the full name with
457 * @param name fill in buffer for the name without keywords.
458 * @param nameCapacity capacity of the fill in buffer.
459 * @param err error information if retrieving the full name failed
460 * @return the actual buffer size needed for the full name. If it's greater
461 * than nameCapacity, the returned full name will be truncated.
464 U_STABLE
int32_t U_EXPORT2
465 uloc_getName(const char* localeID
,
467 int32_t nameCapacity
,
471 * Gets the full name for the specified locale.
472 * Note: This has the effect of 'canonicalizing' the string to
473 * a certain extent. Upper and lower case are set as needed,
474 * and if the components were in 'POSIX' format they are changed to
475 * ICU format. It does NOT map aliased names in any way.
476 * See the top of this header file.
478 * @param localeID the locale to get the full name with
479 * @param name the full name for localeID
480 * @param nameCapacity the size of the name buffer to store the
482 * @param err error information if retrieving the full name failed
483 * @return the actual buffer size needed for the full name. If it's greater
484 * than nameCapacity, the returned full name will be truncated.
487 U_DRAFT
int32_t U_EXPORT2
488 uloc_canonicalize(const char* localeID
,
490 int32_t nameCapacity
,
494 * Gets the ISO language code for the specified locale.
496 * @param localeID the locale to get the ISO language code with
497 * @return language the ISO language code for localeID
500 U_STABLE
const char* U_EXPORT2
501 uloc_getISO3Language(const char* localeID
);
505 * Gets the ISO country code for the specified locale.
507 * @param localeID the locale to get the ISO country code with
508 * @return country the ISO country code for localeID
511 U_STABLE
const char* U_EXPORT2
512 uloc_getISO3Country(const char* localeID
);
515 * Gets the Win32 LCID value for the specified locale.
516 * If the ICU locale is not recognized by Windows, 0 will be returned.
518 * @param localeID the locale to get the Win32 LCID value with
519 * @return country the Win32 LCID for localeID
522 U_STABLE
uint32_t U_EXPORT2
523 uloc_getLCID(const char* localeID
);
526 * Gets the language name suitable for display for the specified locale.
528 * @param locale the locale to get the ISO language code with
529 * @param displayLocale Specifies the locale to be used to display the name. In other words,
530 * if the locale's language code is "en", passing Locale::getFrench() for
531 * inLocale would result in "Anglais", while passing Locale::getGerman()
532 * for inLocale would result in "Englisch".
533 * @param language the displayable language code for localeID
534 * @param languageCapacity the size of the language buffer to store the
535 * displayable language code with
536 * @param status error information if retrieving the displayable language code failed
537 * @return the actual buffer size needed for the displayable language code. If it's greater
538 * than languageCapacity, the returned language code will be truncated.
541 U_STABLE
int32_t U_EXPORT2
542 uloc_getDisplayLanguage(const char* locale
,
543 const char* displayLocale
,
545 int32_t languageCapacity
,
549 * Gets the script name suitable for display for the specified locale.
551 * @param locale the locale to get the displayable script code with. NULL may be used to specify the default.
552 * @param displayLocale Specifies the locale to be used to display the name. In other words,
553 * if the locale's language code is "en", passing Locale::getFrench() for
554 * inLocale would result in "", while passing Locale::getGerman()
555 * for inLocale would result in "". NULL may be used to specify the default.
556 * @param script the displayable country code for localeID
557 * @param scriptCapacity the size of the script buffer to store the
558 * displayable script code with
559 * @param status error information if retrieving the displayable script code failed
560 * @return the actual buffer size needed for the displayable script code. If it's greater
561 * than scriptCapacity, the returned displayable script code will be truncated.
564 U_DRAFT
int32_t U_EXPORT2
565 uloc_getDisplayScript(const char* locale
,
566 const char* displayLocale
,
568 int32_t scriptCapacity
,
572 * Gets the country name suitable for display for the specified locale.
574 * @param locale the locale to get the displayable country code with. NULL may be used to specify the default.
575 * @param displayLocale Specifies the locale to be used to display the name. In other words,
576 * if the locale's language code is "en", passing Locale::getFrench() for
577 * inLocale would result in "Anglais", while passing Locale::getGerman()
578 * for inLocale would result in "Englisch". NULL may be used to specify the default.
579 * @param country the displayable country code for localeID
580 * @param countryCapacity the size of the country buffer to store the
581 * displayable country code with
582 * @param status error information if retrieving the displayable country code failed
583 * @return the actual buffer size needed for the displayable country code. If it's greater
584 * than countryCapacity, the returned displayable country code will be truncated.
587 U_STABLE
int32_t U_EXPORT2
588 uloc_getDisplayCountry(const char* locale
,
589 const char* displayLocale
,
591 int32_t countryCapacity
,
596 * Gets the variant name suitable for display for the specified locale.
598 * @param locale the locale to get the displayable variant code with. NULL may be used to specify the default.
599 * @param displayLocale Specifies the locale to be used to display the name. In other words,
600 * if the locale's language code is "en", passing Locale::getFrench() for
601 * inLocale would result in "Anglais", while passing Locale::getGerman()
602 * for inLocale would result in "Englisch". NULL may be used to specify the default.
603 * @param variant the displayable variant code for localeID
604 * @param variantCapacity the size of the variant buffer to store the
605 * displayable variant code with
606 * @param status error information if retrieving the displayable variant code failed
607 * @return the actual buffer size needed for the displayable variant code. If it's greater
608 * than variantCapacity, the returned displayable variant code will be truncated.
611 U_STABLE
int32_t U_EXPORT2
612 uloc_getDisplayVariant(const char* locale
,
613 const char* displayLocale
,
615 int32_t variantCapacity
,
619 * Gets the keyword name suitable for display for the specified locale.
620 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
621 * string for the keyword collation.
624 * UErrorCode status = U_ZERO_ERROR;
625 * const char* keyword =NULL;
626 * int32_t keywordLen = 0;
627 * int32_t keywordCount = 0;
628 * UChar displayKeyword[256];
629 * int32_t displayKeywordLen = 0;
630 * UEnumeration* keywordEnum = uloc_openKeywords("de_DE@collation=PHONEBOOK;calendar=TRADITIONAL", &status);
631 * for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
632 * if(U_FAILURE(status)){
633 * ...something went wrong so handle the error...
636 * // the uenum_next returns NUL terminated string
637 * keyword = uenum_next(keywordEnum, &keywordLen, &status);
638 * displayKeywordLen = uloc_getDisplayKeyword(keyword, "en_US", displayKeyword, 256);
639 * ... do something interesting .....
641 * uenum_close(keywordEnum);
643 * @param keyword The keyword whose display string needs to be returned.
644 * @param displayLocale Specifies the locale to be used to display the name. In other words,
645 * if the locale's language code is "en", passing Locale::getFrench() for
646 * inLocale would result in "Anglais", while passing Locale::getGerman()
647 * for inLocale would result in "Englisch". NULL may be used to specify the default.
648 * @param dest the buffer to which the displayable keyword should be written.
649 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
650 * dest may be NULL and the function will only return the length of the
651 * result without writing any of the result string (pre-flighting).
652 * @param status error information if retrieving the displayable string failed.
653 * Should not be NULL and should not indicate failure on entry.
654 * @return the actual buffer size needed for the displayable variant code.
655 * @see #uloc_openKeywords
658 U_DRAFT
int32_t U_EXPORT2
659 uloc_getDisplayKeyword(const char* keyword
,
660 const char* displayLocale
,
662 int32_t destCapacity
,
665 * Gets the value of the keyword suitable for display for the specified locale.
666 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
667 * string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword.
669 * @param locale The locale to get the displayable variant code with. NULL may be used to specify the default.
670 * @param keyword The keyword for whose value should be used.
671 * @param displayLocale Specifies the locale to be used to display the name. In other words,
672 * if the locale's language code is "en", passing Locale::getFrench() for
673 * inLocale would result in "Anglais", while passing Locale::getGerman()
674 * for inLocale would result in "Englisch". NULL may be used to specify the default.
675 * @param dest the buffer to which the displayable keyword should be written.
676 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
677 * dest may be NULL and the function will only return the length of the
678 * result without writing any of the result string (pre-flighting).
679 * @param status error information if retrieving the displayable string failed.
680 * Should not be NULL and must not indicate failure on entry.
681 * @return the actual buffer size needed for the displayable variant code.
684 U_DRAFT
int32_t U_EXPORT2
685 uloc_getDisplayKeywordValue( const char* locale
,
687 const char* displayLocale
,
689 int32_t destCapacity
,
692 * Gets the full name suitable for display for the specified locale.
694 * @param localeID the locale to get the displayable name with. NULL may be used to specify the default.
695 * @param inLocaleID Specifies the locale to be used to display the name. In other words,
696 * if the locale's language code is "en", passing Locale::getFrench() for
697 * inLocale would result in "Anglais", while passing Locale::getGerman()
698 * for inLocale would result in "Englisch". NULL may be used to specify the default.
699 * @param result the displayable name for localeID
700 * @param maxResultSize the size of the name buffer to store the
701 * displayable full name with
702 * @param err error information if retrieving the displayable name failed
703 * @return the actual buffer size needed for the displayable name. If it's greater
704 * than maxResultSize, the returned displayable name will be truncated.
707 U_STABLE
int32_t U_EXPORT2
708 uloc_getDisplayName(const char* localeID
,
709 const char* inLocaleID
,
711 int32_t maxResultSize
,
716 * Gets the specified locale from a list of all available locales.
717 * The return value is a pointer to an item of
718 * a locale name array. Both this array and the pointers
719 * it contains are owned by ICU and should not be deleted or written through
720 * by the caller. The locale name is terminated by a null pointer.
721 * @param n the specific locale name index of the available locale list
722 * @return a specified locale name of all available locales
725 U_STABLE
const char* U_EXPORT2
726 uloc_getAvailable(int32_t n
);
729 * Gets the size of the all available locale list.
731 * @return the size of the locale list
734 U_STABLE
int32_t U_EXPORT2
uloc_countAvailable(void);
738 * Gets a list of all available language codes defined in ISO 639. This is a pointer
739 * to an array of pointers to arrays of char. All of these pointers are owned
740 * by ICU-- do not delete them, and do not write through them. The array is
741 * terminated with a null pointer.
742 * @return a list of all available language codes
745 U_STABLE
const char* const* U_EXPORT2
746 uloc_getISOLanguages(void);
750 * Gets a list of all available 2-letter country codes defined in ISO 639. This is a
751 * pointer to an array of pointers to arrays of char. All of these pointers are
752 * owned by ICU-- do not delete them, and do not write through them. The array is
753 * terminated with a null pointer.
754 * @return a list of all available country codes
757 U_STABLE
const char* const* U_EXPORT2
758 uloc_getISOCountries(void);
761 * Truncate the locale ID string to get the parent locale ID.
762 * Copies the part of the string before the last underscore.
763 * The parent locale ID will be an empty string if there is no
764 * underscore, or if there is only one underscore at localeID[0].
766 * @param localeID Input locale ID string.
767 * @param parent Output string buffer for the parent locale ID.
768 * @param parentCapacity Size of the output buffer.
769 * @param err A UErrorCode value.
770 * @return The length of the parent locale ID.
773 U_STABLE
int32_t U_EXPORT2
774 uloc_getParent(const char* localeID
,
776 int32_t parentCapacity
,
783 * Gets the full name for the specified locale.
784 * Note: This has the effect of 'canonicalizing' the string to
785 * a certain extent. Upper and lower case are set as needed,
786 * and if the components were in 'POSIX' format they are changed to
787 * ICU format. It does NOT map aliased names in any way.
788 * See the top of this header file.
789 * This API strips off the keyword part, so "de_DE\@collation=phonebook"
790 * will become "de_DE".
791 * This API supports preflighting.
793 * @param localeID the locale to get the full name with
794 * @param name fill in buffer for the name without keywords.
795 * @param nameCapacity capacity of the fill in buffer.
796 * @param err error information if retrieving the full name failed
797 * @return the actual buffer size needed for the full name. If it's greater
798 * than nameCapacity, the returned full name will be truncated.
801 U_DRAFT
int32_t U_EXPORT2
802 uloc_getBaseName(const char* localeID
,
804 int32_t nameCapacity
,
808 * Gets an enumeration of keywords for the specified locale. Enumeration
809 * must get disposed of by the client using uenum_close function.
811 * @param localeID the locale to get the variant code with
812 * @param status error information if retrieving the keywords failed
813 * @return enumeration of keywords or NULL if there are no keywords.
816 U_DRAFT UEnumeration
* U_EXPORT2
817 uloc_openKeywords(const char* localeID
,
821 * Get the value for a keyword. Locale name does not need to be normalized.
823 * @param localeID locale name containing the keyword ("de_DE@currency=EURO;collation=PHONEBOOK")
824 * @param keywordName name of the keyword for which we want the value. Case insensitive.
825 * @param buffer receiving buffer
826 * @param bufferCapacity capacity of receiving buffer
827 * @param status containing error code - buffer not big enough.
828 * @return the length of keyword value
831 U_DRAFT
int32_t U_EXPORT2
832 uloc_getKeywordValue(const char* localeID
,
833 const char* keywordName
,
834 char* buffer
, int32_t bufferCapacity
,
839 * Set the value of the specified keyword.
840 * NOTE: Unlike almost every other ICU function which takes a
841 * buffer, this function will NOT truncate the output text. If a
842 * BUFFER_OVERFLOW_ERROR is received, it means that the original
843 * buffer is untouched. This is done to prevent incorrect or possibly
844 * even malformed locales from being generated and used.
846 * @param keywordName name of the keyword to be set. Case insensitive.
847 * @param keywordValue value of the keyword to be set. If 0-length or
848 * NULL, will result in the keyword being removed. No error is given if
849 * that keyword does not exist.
850 * @param buffer input buffer containing locale to be modified.
851 * @param bufferCapacity capacity of receiving buffer
852 * @param status containing error code - buffer not big enough.
853 * @return the length needed for the buffer
854 * @see uloc_getKeywordValue
857 U_DRAFT
int32_t U_EXPORT2
858 uloc_setKeywordValue(const char* keywordName
,
859 const char* keywordValue
,
860 char* buffer
, int32_t bufferCapacity
,
864 * enums for the 'outResult' parameter return value
865 * @see uloc_acceptLanguageFromHTTP
866 * @see uloc_acceptLanguage
870 ULOC_ACCEPT_FAILED
= 0, /* No exact match was found. */
871 ULOC_ACCEPT_VALID
= 1, /* An exact match was found. */
872 ULOC_ACCEPT_FALLBACK
= 2 /* A fallback was found, for example,
873 Accept list contained 'ja_JP'
874 which matched available locale 'ja'. */
879 * @param httpAcceptLanguage - "Accept-Language:" header as per HTTP.
880 * @param result - buffer to accept the result locale
881 * @param resultAvailable the size of the result buffer.
882 * @param availableLocales - list of available locales to match
883 * @param status Error status, may be BUFFER_OVERFLOW_ERROR
884 * @return length needed for the locale.
887 U_DRAFT
int32_t U_EXPORT2
888 uloc_acceptLanguageFromHTTP(char *result
, int32_t resultAvailable
,
889 UAcceptResult
*outResult
,
890 const char *httpAcceptLanguage
,
891 UEnumeration
* availableLocales
,
895 * @param acceptList -list of acceptable languages
896 * @param acceptListCount - count of acceptList items
897 * @param result - buffer to accept the result locale
898 * @param resultAvailable the size of the result buffer.
899 * @param availableLocales - list of available locales to match
900 * @param status Error status, may be BUFFER_OVERFLOW_ERROR
901 * @return length needed for the locale.
904 U_DRAFT
int32_t U_EXPORT2
905 uloc_acceptLanguage(char *result
, int32_t resultAvailable
,
906 UAcceptResult
*outResult
, const char **acceptList
,
907 int32_t acceptListCount
,
908 UEnumeration
* availableLocales
,