1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
11 * Modification History:
13 * Date Name Description
14 * 04/01/97 aliu Creation.
15 * 08/22/98 stephen JDK 1.2 sync.
16 * 12/08/98 rtg New C API for Locale
17 * 03/30/99 damiba overhaul
18 * 03/31/99 helena Javadoc for uloc functions.
19 * 04/15/99 Madhu Updated Javadoc
20 ********************************************************************************
26 #include "unicode/utypes.h"
27 #include "unicode/uenum.h"
31 * \brief C API: Locale
33 * <h2> ULoc C API for Locale </h2>
34 * A <code>Locale</code> represents a specific geographical, political,
35 * or cultural region. An operation that requires a <code>Locale</code> to perform
36 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
37 * to tailor information for the user. For example, displaying a number
38 * is a locale-sensitive operation--the number should be formatted
39 * according to the customs/conventions of the user's native country,
40 * region, or culture. In the C APIs, a locales is simply a const char string.
43 * You create a <code>Locale</code> with one of the three options listed below.
44 * Each of the component is separated by '_' in the locale string.
45 * \htmlonly<blockquote>\endhtmlonly
50 * newLanguage + newCountry
52 * newLanguage + newCountry + newVariant
55 * \htmlonly</blockquote>\endhtmlonly
56 * The first option is a valid <STRONG>ISO
57 * Language Code.</STRONG> These codes are the lower-case two-letter
58 * codes as defined by ISO-639.
59 * You can find a full list of these codes at a number of sites, such as:
60 * <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt">
61 * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</a>
64 * The second option includes an additional <STRONG>ISO Country
65 * Code.</STRONG> These codes are the upper-case two-letter codes
66 * as defined by ISO-3166.
67 * You can find a full list of these codes at a number of sites, such as:
68 * <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html">
69 * http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</a>
72 * The third option requires another additional information--the
73 * <STRONG>Variant.</STRONG>
74 * The Variant codes are vendor and browser-specific.
75 * For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
76 * Where there are two variants, separate them with an underscore, and
77 * put the most important one first. For
78 * example, a Traditional Spanish collation might be referenced, with
79 * "ES", "ES", "Traditional_WIN".
82 * Because a <code>Locale</code> is just an identifier for a region,
83 * no validity check is performed when you specify a <code>Locale</code>.
84 * If you want to see whether particular resources are available for the
85 * <code>Locale</code> you asked for, you must query those resources. For
86 * example, ask the <code>UNumberFormat</code> for the locales it supports
87 * using its <code>getAvailable</code> method.
88 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
89 * locale, you get back the best available match, not necessarily
90 * precisely what you asked for. For more information, look at
91 * <code>UResourceBundle</code>.
94 * The <code>Locale</code> provides a number of convenient constants
95 * that you can use to specify the commonly used
96 * locales. For example, the following refers to a locale
97 * for the United States:
98 * \htmlonly<blockquote>\endhtmlonly
104 * \htmlonly</blockquote>\endhtmlonly
107 * Once you've specified a locale you can query it for information about
108 * itself. Use <code>uloc_getCountry</code> to get the ISO Country Code and
109 * <code>uloc_getLanguage</code> to get the ISO Language Code. You can
110 * use <code>uloc_getDisplayCountry</code> to get the
111 * name of the country suitable for displaying to the user. Similarly,
112 * you can use <code>uloc_getDisplayLanguage</code> to get the name of
113 * the language suitable for displaying to the user. Interestingly,
114 * the <code>uloc_getDisplayXXX</code> methods are themselves locale-sensitive
115 * and have two versions: one that uses the default locale and one
116 * that takes a locale as an argument and displays the name or country in
117 * a language appropriate to that locale.
120 * The ICU provides a number of services that perform locale-sensitive
121 * operations. For example, the <code>unum_xxx</code> functions format
122 * numbers, currency, or percentages in a locale-sensitive manner.
124 * \htmlonly<blockquote>\endhtmlonly
127 * UErrorCode success = U_ZERO_ERROR;
129 * const char* myLocale = "fr_FR";
131 * nf = unum_open( UNUM_DEFAULT, NULL, success );
133 * nf = unum_open( UNUM_CURRENCY, NULL, success );
135 * nf = unum_open( UNUM_PERCENT, NULL, success );
139 * \htmlonly</blockquote>\endhtmlonly
140 * Each of these methods has two variants; one with an explicit locale
141 * and one without; the latter using the default locale.
142 * \htmlonly<blockquote>\endhtmlonly
146 * nf = unum_open( UNUM_DEFAULT, myLocale, success );
148 * nf = unum_open( UNUM_CURRENCY, myLocale, success );
150 * nf = unum_open( UNUM_PERCENT, myLocale, success );
154 * \htmlonly</blockquote>\endhtmlonly
155 * A <code>Locale</code> is the mechanism for identifying the kind of services
156 * (<code>UNumberFormat</code>) that you would like to get. The locale is
157 * <STRONG>just</STRONG> a mechanism for identifying these services.
160 * Each international service that performs locale-sensitive operations
162 * to get all the available objects of that type. You can sift
163 * through these objects by language, country, or variant,
164 * and use the display names to present a menu to the user.
165 * For example, you can create a menu of all the collation objects
166 * suitable for a given language. Such classes implement these
167 * three class methods:
168 * \htmlonly<blockquote>\endhtmlonly
171 * const char* uloc_getAvailable(int32_t index);
172 * int32_t uloc_countAvailable();
174 * uloc_getDisplayName(const char* localeID,
175 * const char* inLocaleID,
177 * int32_t maxResultSize,
182 * \htmlonly</blockquote>\endhtmlonly
184 * Concerning POSIX/RFC1766 Locale IDs,
185 * the getLanguage/getCountry/getVariant/getName functions do understand
186 * the POSIX type form of language_COUNTRY.ENCODING\@VARIANT
187 * and if there is not an ICU-stype variant, uloc_getVariant() for example
188 * will return the one listed after the \@at sign. As well, the hyphen
189 * "-" is recognized as a country/variant separator similarly to RFC1766.
190 * So for example, "en-us" will be interpreted as en_US.
191 * As a result, uloc_getName() is far from a no-op, and will have the
192 * effect of converting POSIX/RFC1766 IDs into ICU form, although it does
193 * NOT map any of the actual codes (i.e. russian->ru) in any way.
194 * Applications should call uloc_getName() at the point where a locale ID
195 * is coming from an external source (user entry, OS, web browser)
196 * and pass the resulting string to other ICU functions. For example,
197 * don't use de-de\@EURO as an argument to resourcebundle.
199 * @see UResourceBundle
202 /** Useful constant for this language. @stable ICU 2.0 */
203 #define ULOC_CHINESE "zh"
204 /** Useful constant for this language. @stable ICU 2.0 */
205 #define ULOC_ENGLISH "en"
206 /** Useful constant for this language. @stable ICU 2.0 */
207 #define ULOC_FRENCH "fr"
208 /** Useful constant for this language. @stable ICU 2.0 */
209 #define ULOC_GERMAN "de"
210 /** Useful constant for this language. @stable ICU 2.0 */
211 #define ULOC_ITALIAN "it"
212 /** Useful constant for this language. @stable ICU 2.0 */
213 #define ULOC_JAPANESE "ja"
214 /** Useful constant for this language. @stable ICU 2.0 */
215 #define ULOC_KOREAN "ko"
216 /** Useful constant for this language. @stable ICU 2.0 */
217 #define ULOC_SIMPLIFIED_CHINESE "zh_CN"
218 /** Useful constant for this language. @stable ICU 2.0 */
219 #define ULOC_TRADITIONAL_CHINESE "zh_TW"
221 /** Useful constant for this country/region. @stable ICU 2.0 */
222 #define ULOC_CANADA "en_CA"
223 /** Useful constant for this country/region. @stable ICU 2.0 */
224 #define ULOC_CANADA_FRENCH "fr_CA"
225 /** Useful constant for this country/region. @stable ICU 2.0 */
226 #define ULOC_CHINA "zh_CN"
227 /** Useful constant for this country/region. @stable ICU 2.0 */
228 #define ULOC_PRC "zh_CN"
229 /** Useful constant for this country/region. @stable ICU 2.0 */
230 #define ULOC_FRANCE "fr_FR"
231 /** Useful constant for this country/region. @stable ICU 2.0 */
232 #define ULOC_GERMANY "de_DE"
233 /** Useful constant for this country/region. @stable ICU 2.0 */
234 #define ULOC_ITALY "it_IT"
235 /** Useful constant for this country/region. @stable ICU 2.0 */
236 #define ULOC_JAPAN "ja_JP"
237 /** Useful constant for this country/region. @stable ICU 2.0 */
238 #define ULOC_KOREA "ko_KR"
239 /** Useful constant for this country/region. @stable ICU 2.0 */
240 #define ULOC_TAIWAN "zh_TW"
241 /** Useful constant for this country/region. @stable ICU 2.0 */
242 #define ULOC_UK "en_GB"
243 /** Useful constant for this country/region. @stable ICU 2.0 */
244 #define ULOC_US "en_US"
247 * Useful constant for the maximum size of the language part of a locale ID.
248 * (including the terminating NULL).
251 #define ULOC_LANG_CAPACITY 12
254 * Useful constant for the maximum size of the country part of a locale ID
255 * (including the terminating NULL).
258 #define ULOC_COUNTRY_CAPACITY 4
260 * Useful constant for the maximum size of the whole locale ID
261 * (including the terminating NULL and all keywords).
264 #define ULOC_FULLNAME_CAPACITY 157
267 * Useful constant for the maximum size of the script part of a locale ID
268 * (including the terminating NULL).
271 #define ULOC_SCRIPT_CAPACITY 6
274 * Useful constant for the maximum size of keywords in a locale
277 #define ULOC_KEYWORDS_CAPACITY 96
280 * Useful constant for the maximum total size of keywords and their values in a locale
283 #define ULOC_KEYWORD_AND_VALUES_CAPACITY 100
286 * Invariant character separating keywords from the locale string
289 #define ULOC_KEYWORD_SEPARATOR '@'
292 * Unicode code point for '@' separating keywords from the locale string.
293 * @see ULOC_KEYWORD_SEPARATOR
296 #define ULOC_KEYWORD_SEPARATOR_UNICODE 0x40
299 * Invariant character for assigning value to a keyword
302 #define ULOC_KEYWORD_ASSIGN '='
305 * Unicode code point for '=' for assigning value to a keyword.
306 * @see ULOC_KEYWORD_ASSIGN
309 #define ULOC_KEYWORD_ASSIGN_UNICODE 0x3D
312 * Invariant character separating keywords
315 #define ULOC_KEYWORD_ITEM_SEPARATOR ';'
318 * Unicode code point for ';' separating keywords
319 * @see ULOC_KEYWORD_ITEM_SEPARATOR
322 #define ULOC_KEYWORD_ITEM_SEPARATOR_UNICODE 0x3B
325 * Constants for *_getLocale()
326 * Allow user to select whether she wants information on
327 * requested, valid or actual locale.
328 * For example, a collator for "en_US_CALIFORNIA" was
329 * requested. In the current state of ICU (2.0),
330 * the requested locale is "en_US_CALIFORNIA",
331 * the valid locale is "en_US" (most specific locale supported by ICU)
332 * and the actual locale is "root" (the collation data comes unmodified
334 * The locale is considered supported by ICU if there is a core ICU bundle
335 * for that locale (although it may be empty).
339 /** This is locale the data actually comes from
342 ULOC_ACTUAL_LOCALE
= 0,
343 /** This is the most specific locale supported by ICU
346 ULOC_VALID_LOCALE
= 1,
348 #ifndef U_HIDE_DEPRECATED_API
349 /** This is the requested locale
350 * @deprecated ICU 2.8
352 ULOC_REQUESTED_LOCALE
= 2,
355 * One more than the highest normal ULocDataLocaleType value.
356 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
358 ULOC_DATA_LOCALE_TYPE_LIMIT
= 3
359 #endif // U_HIDE_DEPRECATED_API
360 } ULocDataLocaleType
;
362 #ifndef U_HIDE_SYSTEM_API
364 * Gets ICU's default locale.
365 * The returned string is a snapshot in time, and will remain valid
366 * and unchanged even when uloc_setDefault() is called.
367 * The returned storage is owned by ICU, and must not be altered or deleted
370 * @return the ICU default locale
374 U_STABLE
const char* U_EXPORT2
375 uloc_getDefault(void);
378 * Sets ICU's default locale.
379 * By default (without calling this function), ICU's default locale will be based
380 * on information obtained from the underlying system environment.
382 * Changes to ICU's default locale do not propagate back to the
383 * system environment.
385 * Changes to ICU's default locale to not affect any ICU services that
386 * may already be open based on the previous default locale value.
388 * @param localeID the new ICU default locale. A value of NULL will try to get
389 * the system's default locale.
390 * @param status the error information if the setting of default locale fails
394 U_STABLE
void U_EXPORT2
395 uloc_setDefault(const char* localeID
,
397 #endif /* U_HIDE_SYSTEM_API */
400 * Gets the language code for the specified locale.
402 * @param localeID the locale to get the ISO language code with
403 * @param language the language code for localeID
404 * @param languageCapacity the size of the language buffer to store the
406 * @param err error information if retrieving the language code failed
407 * @return the actual buffer size needed for the language code. If it's greater
408 * than languageCapacity, the returned language code will be truncated.
411 U_STABLE
int32_t U_EXPORT2
412 uloc_getLanguage(const char* localeID
,
414 int32_t languageCapacity
,
418 * Gets the script code for the specified locale.
420 * @param localeID the locale to get the ISO language code with
421 * @param script the language code for localeID
422 * @param scriptCapacity the size of the language buffer to store the
424 * @param err error information if retrieving the language code failed
425 * @return the actual buffer size needed for the language code. If it's greater
426 * than scriptCapacity, the returned language code will be truncated.
429 U_STABLE
int32_t U_EXPORT2
430 uloc_getScript(const char* localeID
,
432 int32_t scriptCapacity
,
436 * Gets the country code for the specified locale.
438 * @param localeID the locale to get the country code with
439 * @param country the country code for localeID
440 * @param countryCapacity the size of the country buffer to store the
442 * @param err error information if retrieving the country code failed
443 * @return the actual buffer size needed for the country code. If it's greater
444 * than countryCapacity, the returned country code will be truncated.
447 U_STABLE
int32_t U_EXPORT2
448 uloc_getCountry(const char* localeID
,
450 int32_t countryCapacity
,
454 * Gets the variant code for the specified locale.
456 * @param localeID the locale to get the variant code with
457 * @param variant the variant code for localeID
458 * @param variantCapacity the size of the variant buffer to store the
460 * @param err error information if retrieving the variant code failed
461 * @return the actual buffer size needed for the variant code. If it's greater
462 * than variantCapacity, the returned variant code will be truncated.
465 U_STABLE
int32_t U_EXPORT2
466 uloc_getVariant(const char* localeID
,
468 int32_t variantCapacity
,
473 * Gets the full name for the specified locale.
474 * Note: This has the effect of 'canonicalizing' the ICU locale ID to
475 * a certain extent. Upper and lower case are set as needed.
476 * It does NOT map aliased names in any way.
477 * See the top of this header file.
478 * This API supports preflighting.
480 * @param localeID the locale to get the full name with
481 * @param name fill in buffer for the name without keywords.
482 * @param nameCapacity capacity of the fill in buffer.
483 * @param err error information if retrieving the full name failed
484 * @return the actual buffer size needed for the full name. If it's greater
485 * than nameCapacity, the returned full name will be truncated.
488 U_STABLE
int32_t U_EXPORT2
489 uloc_getName(const char* localeID
,
491 int32_t nameCapacity
,
495 * Gets the full name for the specified locale.
496 * Note: This has the effect of 'canonicalizing' the string to
497 * a certain extent. Upper and lower case are set as needed,
498 * and if the components were in 'POSIX' format they are changed to
499 * ICU format. It does NOT map aliased names in any way.
500 * See the top of this header file.
502 * @param localeID the locale to get the full name with
503 * @param name the full name for localeID
504 * @param nameCapacity the size of the name buffer to store the
506 * @param err error information if retrieving the full name failed
507 * @return the actual buffer size needed for the full name. If it's greater
508 * than nameCapacity, the returned full name will be truncated.
511 U_STABLE
int32_t U_EXPORT2
512 uloc_canonicalize(const char* localeID
,
514 int32_t nameCapacity
,
518 * Gets the ISO language code for the specified locale.
520 * @param localeID the locale to get the ISO language code with
521 * @return language the ISO language code for localeID
524 U_STABLE
const char* U_EXPORT2
525 uloc_getISO3Language(const char* localeID
);
529 * Gets the ISO country code for the specified locale.
531 * @param localeID the locale to get the ISO country code with
532 * @return country the ISO country code for localeID
535 U_STABLE
const char* U_EXPORT2
536 uloc_getISO3Country(const char* localeID
);
539 * Gets the Win32 LCID value for the specified locale.
540 * If the ICU locale is not recognized by Windows, 0 will be returned.
542 * LCIDs were deprecated with Windows Vista and Microsoft recommends
543 * that developers use BCP47 style tags instead (uloc_toLanguageTag).
545 * @param localeID the locale to get the Win32 LCID value with
546 * @return country the Win32 LCID for localeID
549 U_STABLE
uint32_t U_EXPORT2
550 uloc_getLCID(const char* localeID
);
553 * Gets the language name suitable for display for the specified locale.
555 * @param locale the locale to get the ISO language code with
556 * @param displayLocale Specifies the locale to be used to display the name. In other words,
557 * if the locale's language code is "en", passing Locale::getFrench() for
558 * inLocale would result in "Anglais", while passing Locale::getGerman()
559 * for inLocale would result in "Englisch".
560 * @param language the displayable language code for localeID
561 * @param languageCapacity the size of the language buffer to store the
562 * displayable language code with
563 * @param status error information if retrieving the displayable language code failed
564 * @return the actual buffer size needed for the displayable language code. If it's greater
565 * than languageCapacity, the returned language code will be truncated.
568 U_STABLE
int32_t U_EXPORT2
569 uloc_getDisplayLanguage(const char* locale
,
570 const char* displayLocale
,
572 int32_t languageCapacity
,
576 * Gets the script name suitable for display for the specified locale.
578 * @param locale the locale to get the displayable script code with. NULL may be used to specify the default.
579 * @param displayLocale Specifies the locale to be used to display the name. In other words,
580 * if the locale's language code is "en", passing Locale::getFrench() for
581 * inLocale would result in "", while passing Locale::getGerman()
582 * for inLocale would result in "". NULL may be used to specify the default.
583 * @param script the displayable script for the localeID
584 * @param scriptCapacity the size of the script buffer to store the
585 * displayable script code with
586 * @param status error information if retrieving the displayable script code failed
587 * @return the actual buffer size needed for the displayable script code. If it's greater
588 * than scriptCapacity, the returned displayable script code will be truncated.
591 U_STABLE
int32_t U_EXPORT2
592 uloc_getDisplayScript(const char* locale
,
593 const char* displayLocale
,
595 int32_t scriptCapacity
,
599 * Gets the country name suitable for display for the specified locale.
600 * Warning: this is for the region part of a valid locale ID; it cannot just be the region code (like "FR").
601 * To get the display name for a region alone, or for other options, use ULocaleDisplayNames instead.
603 * @param locale the locale to get the displayable country code with. NULL may be used to specify the default.
604 * @param displayLocale Specifies the locale to be used to display the name. In other words,
605 * if the locale's language code is "en", passing Locale::getFrench() for
606 * inLocale would result in "Anglais", while passing Locale::getGerman()
607 * for inLocale would result in "Englisch". NULL may be used to specify the default.
608 * @param country the displayable country code for localeID
609 * @param countryCapacity the size of the country buffer to store the
610 * displayable country code with
611 * @param status error information if retrieving the displayable country code failed
612 * @return the actual buffer size needed for the displayable country code. If it's greater
613 * than countryCapacity, the returned displayable country code will be truncated.
616 U_STABLE
int32_t U_EXPORT2
617 uloc_getDisplayCountry(const char* locale
,
618 const char* displayLocale
,
620 int32_t countryCapacity
,
625 * Gets the variant name suitable for display for the specified locale.
627 * @param locale the locale to get the displayable variant code with. NULL may be used to specify the default.
628 * @param displayLocale Specifies the locale to be used to display the name. In other words,
629 * if the locale's language code is "en", passing Locale::getFrench() for
630 * inLocale would result in "Anglais", while passing Locale::getGerman()
631 * for inLocale would result in "Englisch". NULL may be used to specify the default.
632 * @param variant the displayable variant code for localeID
633 * @param variantCapacity the size of the variant buffer to store the
634 * displayable variant code with
635 * @param status error information if retrieving the displayable variant code failed
636 * @return the actual buffer size needed for the displayable variant code. If it's greater
637 * than variantCapacity, the returned displayable variant code will be truncated.
640 U_STABLE
int32_t U_EXPORT2
641 uloc_getDisplayVariant(const char* locale
,
642 const char* displayLocale
,
644 int32_t variantCapacity
,
648 * Gets the keyword name suitable for display for the specified locale.
649 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
650 * string for the keyword collation.
653 * UErrorCode status = U_ZERO_ERROR;
654 * const char* keyword =NULL;
655 * int32_t keywordLen = 0;
656 * int32_t keywordCount = 0;
657 * UChar displayKeyword[256];
658 * int32_t displayKeywordLen = 0;
659 * UEnumeration* keywordEnum = uloc_openKeywords("de_DE@collation=PHONEBOOK;calendar=TRADITIONAL", &status);
660 * for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
661 * if(U_FAILURE(status)){
662 * ...something went wrong so handle the error...
665 * // the uenum_next returns NUL terminated string
666 * keyword = uenum_next(keywordEnum, &keywordLen, &status);
667 * displayKeywordLen = uloc_getDisplayKeyword(keyword, "en_US", displayKeyword, 256);
668 * ... do something interesting .....
670 * uenum_close(keywordEnum);
672 * @param keyword The keyword whose display string needs to be returned.
673 * @param displayLocale Specifies the locale to be used to display the name. In other words,
674 * if the locale's language code is "en", passing Locale::getFrench() for
675 * inLocale would result in "Anglais", while passing Locale::getGerman()
676 * for inLocale would result in "Englisch". NULL may be used to specify the default.
677 * @param dest the buffer to which the displayable keyword should be written.
678 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
679 * dest may be NULL and the function will only return the length of the
680 * result without writing any of the result string (pre-flighting).
681 * @param status error information if retrieving the displayable string failed.
682 * Should not be NULL and should not indicate failure on entry.
683 * @return the actual buffer size needed for the displayable variant code.
684 * @see #uloc_openKeywords
687 U_STABLE
int32_t U_EXPORT2
688 uloc_getDisplayKeyword(const char* keyword
,
689 const char* displayLocale
,
691 int32_t destCapacity
,
694 * Gets the value of the keyword suitable for display for the specified locale.
695 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
696 * string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword.
698 * @param locale The locale to get the displayable variant code with. NULL may be used to specify the default.
699 * @param keyword The keyword for whose value should be used.
700 * @param displayLocale Specifies the locale to be used to display the name. In other words,
701 * if the locale's language code is "en", passing Locale::getFrench() for
702 * inLocale would result in "Anglais", while passing Locale::getGerman()
703 * for inLocale would result in "Englisch". NULL may be used to specify the default.
704 * @param dest the buffer to which the displayable keyword should be written.
705 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
706 * dest may be NULL and the function will only return the length of the
707 * result without writing any of the result string (pre-flighting).
708 * @param status error information if retrieving the displayable string failed.
709 * Should not be NULL and must not indicate failure on entry.
710 * @return the actual buffer size needed for the displayable variant code.
713 U_STABLE
int32_t U_EXPORT2
714 uloc_getDisplayKeywordValue( const char* locale
,
716 const char* displayLocale
,
718 int32_t destCapacity
,
721 * Gets the full name suitable for display for the specified locale.
723 * @param localeID the locale to get the displayable name with. NULL may be used to specify the default.
724 * @param inLocaleID Specifies the locale to be used to display the name. In other words,
725 * if the locale's language code is "en", passing Locale::getFrench() for
726 * inLocale would result in "Anglais", while passing Locale::getGerman()
727 * for inLocale would result in "Englisch". NULL may be used to specify the default.
728 * @param result the displayable name for localeID
729 * @param maxResultSize the size of the name buffer to store the
730 * displayable full name with
731 * @param err error information if retrieving the displayable name failed
732 * @return the actual buffer size needed for the displayable name. If it's greater
733 * than maxResultSize, the returned displayable name will be truncated.
736 U_STABLE
int32_t U_EXPORT2
737 uloc_getDisplayName(const char* localeID
,
738 const char* inLocaleID
,
740 int32_t maxResultSize
,
745 * Gets the specified locale from a list of all available locales.
746 * The return value is a pointer to an item of
747 * a locale name array. Both this array and the pointers
748 * it contains are owned by ICU and should not be deleted or written through
749 * by the caller. The locale name is terminated by a null pointer.
750 * @param n the specific locale name index of the available locale list
751 * @return a specified locale name of all available locales
754 U_STABLE
const char* U_EXPORT2
755 uloc_getAvailable(int32_t n
);
758 * Gets the size of the all available locale list.
760 * @return the size of the locale list
763 U_STABLE
int32_t U_EXPORT2
uloc_countAvailable(void);
767 * Gets a list of all available 2-letter language codes defined in ISO 639,
768 * plus additional 3-letter codes determined to be useful for locale generation as
769 * defined by Unicode CLDR. This is a pointer
770 * to an array of pointers to arrays of char. All of these pointers are owned
771 * by ICU-- do not delete them, and do not write through them. The array is
772 * terminated with a null pointer.
773 * @return a list of all available language codes
776 U_STABLE
const char* const* U_EXPORT2
777 uloc_getISOLanguages(void);
781 * Gets a list of all available 2-letter country codes which are valid regular
782 * region codes in CLDR; these are based on the non-deprecated alpha-2 region
783 * codes in ISO 3166-1. The return value is a pointer to an array of pointers
784 * C strings. All of these pointers are owned by ICU; do not delete them, and
785 * do not write through them. The array is terminated with a null pointer.
786 * @return a list of all available country codes
789 U_STABLE
const char* const* U_EXPORT2
790 uloc_getISOCountries(void);
793 * Truncate the locale ID string to get the parent locale ID.
794 * Copies the part of the string before the last underscore.
795 * The parent locale ID will be an empty string if there is no
796 * underscore, or if there is only one underscore at localeID[0].
798 * @param localeID Input locale ID string.
799 * @param parent Output string buffer for the parent locale ID.
800 * @param parentCapacity Size of the output buffer.
801 * @param err A UErrorCode value.
802 * @return The length of the parent locale ID.
805 U_STABLE
int32_t U_EXPORT2
806 uloc_getParent(const char* localeID
,
808 int32_t parentCapacity
,
815 * Gets the full name for the specified locale, like uloc_getName(),
816 * but without keywords.
818 * Note: This has the effect of 'canonicalizing' the string to
819 * a certain extent. Upper and lower case are set as needed,
820 * and if the components were in 'POSIX' format they are changed to
821 * ICU format. It does NOT map aliased names in any way.
822 * See the top of this header file.
824 * This API strips off the keyword part, so "de_DE\@collation=phonebook"
825 * will become "de_DE".
826 * This API supports preflighting.
828 * @param localeID the locale to get the full name with
829 * @param name fill in buffer for the name without keywords.
830 * @param nameCapacity capacity of the fill in buffer.
831 * @param err error information if retrieving the full name failed
832 * @return the actual buffer size needed for the full name. If it's greater
833 * than nameCapacity, the returned full name will be truncated.
836 U_STABLE
int32_t U_EXPORT2
837 uloc_getBaseName(const char* localeID
,
839 int32_t nameCapacity
,
843 * Gets an enumeration of keywords for the specified locale. Enumeration
844 * must get disposed of by the client using uenum_close function.
846 * @param localeID the locale to get the variant code with
847 * @param status error information if retrieving the keywords failed
848 * @return enumeration of keywords or NULL if there are no keywords.
851 U_STABLE UEnumeration
* U_EXPORT2
852 uloc_openKeywords(const char* localeID
,
856 * Get the value for a keyword. Locale name does not need to be normalized.
858 * @param localeID locale name containing the keyword ("de_DE@currency=EURO;collation=PHONEBOOK")
859 * @param keywordName name of the keyword for which we want the value; must not be
860 * NULL or empty, and must consist only of [A-Za-z0-9]. Case insensitive.
861 * @param buffer receiving buffer
862 * @param bufferCapacity capacity of receiving buffer
863 * @param status containing error code: e.g. buffer not big enough or ill-formed localeID
864 * or keywordName parameters.
865 * @return the length of keyword value
868 U_STABLE
int32_t U_EXPORT2
869 uloc_getKeywordValue(const char* localeID
,
870 const char* keywordName
,
871 char* buffer
, int32_t bufferCapacity
,
876 * Sets or removes the value of the specified keyword.
878 * For removing all keywords, use uloc_getBaseName().
880 * NOTE: Unlike almost every other ICU function which takes a
881 * buffer, this function will NOT truncate the output text, and will
882 * not update the buffer with unterminated text setting a status of
883 * U_STRING_NOT_TERMINATED_WARNING. If a BUFFER_OVERFLOW_ERROR is received,
884 * it means a terminated version of the updated locale ID would not fit
885 * in the buffer, and the original buffer is untouched. This is done to
886 * prevent incorrect or possibly even malformed locales from being generated
889 * @param keywordName name of the keyword to be set; must not be
890 * NULL or empty, and must consist only of [A-Za-z0-9]. Case insensitive.
891 * @param keywordValue value of the keyword to be set. If 0-length or
892 * NULL, will result in the keyword being removed; no error is given if
893 * that keyword does not exist. Otherwise, must consist only of
894 * [A-Za-z0-9] and [/_+-].
895 * @param buffer input buffer containing well-formed locale ID to be
897 * @param bufferCapacity capacity of receiving buffer
898 * @param status containing error code: e.g. buffer not big enough
899 * or ill-formed keywordName or keywordValue parameters, or ill-formed
900 * locale ID in buffer on input.
901 * @return the length needed for the buffer
902 * @see uloc_getKeywordValue
905 U_STABLE
int32_t U_EXPORT2
906 uloc_setKeywordValue(const char* keywordName
,
907 const char* keywordValue
,
908 char* buffer
, int32_t bufferCapacity
,
912 * Returns whether the locale's script is written right-to-left.
913 * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags().
914 * If no likely script is known, then FALSE is returned.
916 * A script is right-to-left according to the CLDR script metadata
917 * which corresponds to whether the script's letters have Bidi_Class=R or AL.
919 * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl".
921 * @param locale input locale ID
922 * @return TRUE if the locale's script is written right-to-left
925 U_STABLE UBool U_EXPORT2
926 uloc_isRightToLeft(const char *locale
);
929 * enums for the return value for the character and line orientation
934 ULOC_LAYOUT_LTR
= 0, /* left-to-right. */
935 ULOC_LAYOUT_RTL
= 1, /* right-to-left. */
936 ULOC_LAYOUT_TTB
= 2, /* top-to-bottom. */
937 ULOC_LAYOUT_BTT
= 3, /* bottom-to-top. */
942 * Get the layout character orientation for the specified locale.
944 * @param localeId locale name
945 * @param status Error status
946 * @return an enum indicating the layout orientation for characters.
949 U_STABLE ULayoutType U_EXPORT2
950 uloc_getCharacterOrientation(const char* localeId
,
954 * Get the layout line orientation for the specified locale.
956 * @param localeId locale name
957 * @param status Error status
958 * @return an enum indicating the layout orientation for lines.
961 U_STABLE ULayoutType U_EXPORT2
962 uloc_getLineOrientation(const char* localeId
,
966 * enums for the 'outResult' parameter return value
967 * @see uloc_acceptLanguageFromHTTP
968 * @see uloc_acceptLanguage
972 ULOC_ACCEPT_FAILED
= 0, /* No exact match was found. */
973 ULOC_ACCEPT_VALID
= 1, /* An exact match was found. */
974 ULOC_ACCEPT_FALLBACK
= 2 /* A fallback was found, for example,
975 Accept list contained 'ja_JP'
976 which matched available locale 'ja'. */
981 * Based on a HTTP header from a web browser and a list of available locales,
982 * determine an acceptable locale for the user.
983 * @param result - buffer to accept the result locale
984 * @param resultAvailable the size of the result buffer.
985 * @param outResult - An out parameter that contains the fallback status
986 * @param httpAcceptLanguage - "Accept-Language:" header as per HTTP.
987 * @param availableLocales - list of available locales to match
988 * @param status Error status, may be BUFFER_OVERFLOW_ERROR
989 * @return length needed for the locale.
992 U_STABLE
int32_t U_EXPORT2
993 uloc_acceptLanguageFromHTTP(char *result
, int32_t resultAvailable
,
994 UAcceptResult
*outResult
,
995 const char *httpAcceptLanguage
,
996 UEnumeration
* availableLocales
,
1000 * Based on a list of available locales,
1001 * determine an acceptable locale for the user.
1002 * @param result - buffer to accept the result locale
1003 * @param resultAvailable the size of the result buffer.
1004 * @param outResult - An out parameter that contains the fallback status
1005 * @param acceptList - list of acceptable languages
1006 * @param acceptListCount - count of acceptList items
1007 * @param availableLocales - list of available locales to match
1008 * @param status Error status, may be BUFFER_OVERFLOW_ERROR
1009 * @return length needed for the locale.
1012 U_STABLE
int32_t U_EXPORT2
1013 uloc_acceptLanguage(char *result
, int32_t resultAvailable
,
1014 UAcceptResult
*outResult
, const char **acceptList
,
1015 int32_t acceptListCount
,
1016 UEnumeration
* availableLocales
,
1017 UErrorCode
*status
);
1021 * Gets the ICU locale ID for the specified Win32 LCID value.
1023 * @param hostID the Win32 LCID to translate
1024 * @param locale the output buffer for the ICU locale ID, which will be NUL-terminated
1026 * @param localeCapacity the size of the output buffer
1027 * @param status an error is returned if the LCID is unrecognized or the output buffer
1029 * @return actual the actual size of the locale ID, not including NUL-termination
1032 U_STABLE
int32_t U_EXPORT2
1033 uloc_getLocaleForLCID(uint32_t hostID
, char *locale
, int32_t localeCapacity
,
1034 UErrorCode
*status
);
1038 * Add the likely subtags for a provided locale ID, per the algorithm described
1039 * in the following CLDR technical report:
1041 * http://www.unicode.org/reports/tr35/#Likely_Subtags
1043 * If localeID is already in the maximal form, or there is no data available
1044 * for maximization, it will be copied to the output buffer. For example,
1045 * "und-Zzzz" cannot be maximized, since there is no reasonable maximization.
1049 * "en" maximizes to "en_Latn_US"
1051 * "de" maximizes to "de_Latn_US"
1053 * "sr" maximizes to "sr_Cyrl_RS"
1055 * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.)
1057 * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.)
1059 * @param localeID The locale to maximize
1060 * @param maximizedLocaleID The maximized locale
1061 * @param maximizedLocaleIDCapacity The capacity of the maximizedLocaleID buffer
1062 * @param err Error information if maximizing the locale failed. If the length
1063 * of the localeID and the null-terminator is greater than the maximum allowed size,
1064 * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR.
1065 * @return The actual buffer size needed for the maximized locale. If it's
1066 * greater than maximizedLocaleIDCapacity, the returned ID will be truncated.
1067 * On error, the return value is -1.
1070 U_STABLE
int32_t U_EXPORT2
1071 uloc_addLikelySubtags(const char* localeID
,
1072 char* maximizedLocaleID
,
1073 int32_t maximizedLocaleIDCapacity
,
1078 * Minimize the subtags for a provided locale ID, per the algorithm described
1079 * in the following CLDR technical report:
1081 * http://www.unicode.org/reports/tr35/#Likely_Subtags
1083 * If localeID is already in the minimal form, or there is no data available
1084 * for minimization, it will be copied to the output buffer. Since the
1085 * minimization algorithm relies on proper maximization, see the comments
1086 * for uloc_addLikelySubtags for reasons why there might not be any data.
1090 * "en_Latn_US" minimizes to "en"
1092 * "de_Latn_US" minimizes to "de"
1094 * "sr_Cyrl_RS" minimizes to "sr"
1096 * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the
1097 * script, and minimizing to "zh" would imply "zh_Hans_CN".)
1099 * @param localeID The locale to minimize
1100 * @param minimizedLocaleID The minimized locale
1101 * @param minimizedLocaleIDCapacity The capacity of the minimizedLocaleID buffer
1102 * @param err Error information if minimizing the locale failed. If the length
1103 * of the localeID and the null-terminator is greater than the maximum allowed size,
1104 * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR.
1105 * @return The actual buffer size needed for the minimized locale. If it's
1106 * greater than minimizedLocaleIDCapacity, the returned ID will be truncated.
1107 * On error, the return value is -1.
1110 U_STABLE
int32_t U_EXPORT2
1111 uloc_minimizeSubtags(const char* localeID
,
1112 char* minimizedLocaleID
,
1113 int32_t minimizedLocaleIDCapacity
,
1117 * Returns a locale ID for the specified BCP47 language tag string.
1118 * If the specified language tag contains any ill-formed subtags,
1119 * the first such subtag and all following subtags are ignored.
1121 * This implements the 'Language-Tag' production of BCP47, and so
1122 * supports grandfathered (regular and irregular) as well as private
1123 * use language tags. Private use tags are represented as 'x-whatever',
1124 * and grandfathered tags are converted to their canonical replacements
1125 * where they exist. Note that a few grandfathered tags have no modern
1126 * replacement, these will be converted using the fallback described in
1127 * the first paragraph, so some information might be lost.
1128 * @param langtag the input BCP47 language tag.
1129 * @param localeID the output buffer receiving a locale ID for the
1130 * specified BCP47 language tag.
1131 * @param localeIDCapacity the size of the locale ID output buffer.
1132 * @param parsedLength if not NULL, successfully parsed length
1133 * for the input language tag is set.
1134 * @param err error information if receiving the locald ID
1136 * @return the length of the locale ID.
1139 U_STABLE
int32_t U_EXPORT2
1140 uloc_forLanguageTag(const char* langtag
,
1142 int32_t localeIDCapacity
,
1143 int32_t* parsedLength
,
1147 * Returns a well-formed language tag for this locale ID.
1149 * <b>Note</b>: When <code>strict</code> is FALSE, any locale
1150 * fields which do not satisfy the BCP47 syntax requirement will
1151 * be omitted from the result. When <code>strict</code> is
1152 * TRUE, this function sets U_ILLEGAL_ARGUMENT_ERROR to the
1153 * <code>err</code> if any locale fields do not satisfy the
1154 * BCP47 syntax requirement.
1155 * @param localeID the input locale ID
1156 * @param langtag the output buffer receiving BCP47 language
1157 * tag for the locale ID.
1158 * @param langtagCapacity the size of the BCP47 language tag
1160 * @param strict boolean value indicating if the function returns
1161 * an error for an ill-formed input locale ID.
1162 * @param err error information if receiving the language
1164 * @return The length of the BCP47 language tag.
1167 U_STABLE
int32_t U_EXPORT2
1168 uloc_toLanguageTag(const char* localeID
,
1170 int32_t langtagCapacity
,
1175 * Converts the specified keyword (legacy key, or BCP 47 Unicode locale
1176 * extension key) to the equivalent BCP 47 Unicode locale extension key.
1177 * For example, BCP 47 Unicode locale extension key "co" is returned for
1178 * the input keyword "collation".
1180 * When the specified keyword is unknown, but satisfies the BCP syntax,
1181 * then the pointer to the input keyword itself will be returned.
1183 * <code>uloc_toUnicodeLocaleKey("ZZ")</code> returns "ZZ".
1185 * @param keyword the input locale keyword (either legacy key
1186 * such as "collation" or BCP 47 Unicode locale extension
1187 * key such as "co").
1188 * @return the well-formed BCP 47 Unicode locale extension key,
1189 * or NULL if the specified locale keyword cannot be
1190 * mapped to a well-formed BCP 47 Unicode locale extension
1192 * @see uloc_toLegacyKey
1195 U_STABLE
const char* U_EXPORT2
1196 uloc_toUnicodeLocaleKey(const char* keyword
);
1199 * Converts the specified keyword value (legacy type, or BCP 47
1200 * Unicode locale extension type) to the well-formed BCP 47 Unicode locale
1201 * extension type for the specified keyword (category). For example, BCP 47
1202 * Unicode locale extension type "phonebk" is returned for the input
1203 * keyword value "phonebook", with the keyword "collation" (or "co").
1205 * When the specified keyword is not recognized, but the specified value
1206 * satisfies the syntax of the BCP 47 Unicode locale extension type,
1207 * or when the specified keyword allows 'variable' type and the specified
1208 * value satisfies the syntax, then the pointer to the input type value itself
1211 * <code>uloc_toUnicodeLocaleType("Foo", "Bar")</code> returns "Bar",
1212 * <code>uloc_toUnicodeLocaleType("variableTop", "00A4")</code> returns "00A4".
1214 * @param keyword the locale keyword (either legacy key such as
1215 * "collation" or BCP 47 Unicode locale extension
1216 * key such as "co").
1217 * @param value the locale keyword value (either legacy type
1218 * such as "phonebook" or BCP 47 Unicode locale extension
1219 * type such as "phonebk").
1220 * @return the well-formed BCP47 Unicode locale extension type,
1221 * or NULL if the locale keyword value cannot be mapped to
1222 * a well-formed BCP 47 Unicode locale extension type.
1223 * @see uloc_toLegacyType
1226 U_STABLE
const char* U_EXPORT2
1227 uloc_toUnicodeLocaleType(const char* keyword
, const char* value
);
1230 * Converts the specified keyword (BCP 47 Unicode locale extension key, or
1231 * legacy key) to the legacy key. For example, legacy key "collation" is
1232 * returned for the input BCP 47 Unicode locale extension key "co".
1234 * @param keyword the input locale keyword (either BCP 47 Unicode locale
1235 * extension key or legacy key).
1236 * @return the well-formed legacy key, or NULL if the specified
1237 * keyword cannot be mapped to a well-formed legacy key.
1238 * @see toUnicodeLocaleKey
1241 U_STABLE
const char* U_EXPORT2
1242 uloc_toLegacyKey(const char* keyword
);
1245 * Converts the specified keyword value (BCP 47 Unicode locale extension type,
1246 * or legacy type or type alias) to the canonical legacy type. For example,
1247 * the legacy type "phonebook" is returned for the input BCP 47 Unicode
1248 * locale extension type "phonebk" with the keyword "collation" (or "co").
1250 * When the specified keyword is not recognized, but the specified value
1251 * satisfies the syntax of legacy key, or when the specified keyword
1252 * allows 'variable' type and the specified value satisfies the syntax,
1253 * then the pointer to the input type value itself will be returned.
1255 * <code>uloc_toLegacyType("Foo", "Bar")</code> returns "Bar",
1256 * <code>uloc_toLegacyType("vt", "00A4")</code> returns "00A4".
1258 * @param keyword the locale keyword (either legacy keyword such as
1259 * "collation" or BCP 47 Unicode locale extension
1260 * key such as "co").
1261 * @param value the locale keyword value (either BCP 47 Unicode locale
1262 * extension type such as "phonebk" or legacy keyword value
1263 * such as "phonebook").
1264 * @return the well-formed legacy type, or NULL if the specified
1265 * keyword value cannot be mapped to a well-formed legacy
1267 * @see toUnicodeLocaleType
1270 U_STABLE
const char* U_EXPORT2
1271 uloc_toLegacyType(const char* keyword
, const char* value
);