1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ********************************************************************** 5 * Copyright (C) 1997-2016, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ********************************************************************** 8 * 9 * File ULOC.H 10 * 11 * Modification History: 12 * 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 ******************************************************************************** 21 */ 22 23 #ifndef ULOC_H 24 #define ULOC_H 25 26 #include "unicode/utypes.h" 27 #include "unicode/uenum.h" 28 29 /** 30 * \file 31 * \brief C API: Locale ID functionality similar to C++ class Locale 32 * 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. 41 * 42 * <P> 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 46 * <pre> 47 * \code 48 * newLanguage 49 * 50 * newLanguage + newCountry 51 * 52 * newLanguage + newCountry + newVariant 53 * \endcode 54 * </pre> 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> 62 * 63 * <P> 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> 70 * 71 * <P> 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". 80 * 81 * <P> 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>. 92 * 93 * <P> 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 99 * <pre> 100 * \code 101 * ULOC_US 102 * \endcode 103 * </pre> 104 * \htmlonly</blockquote>\endhtmlonly 105 * 106 * <P> 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. 118 * 119 * <P> 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. 123 * </P> 124 * \htmlonly<blockquote>\endhtmlonly 125 * <pre> 126 * \code 127 * UErrorCode success = U_ZERO_ERROR; 128 * UNumberFormat *nf; 129 * const char* myLocale = "fr_FR"; 130 * 131 * nf = unum_open( UNUM_DEFAULT, NULL, success ); 132 * unum_close(nf); 133 * nf = unum_open( UNUM_CURRENCY, NULL, success ); 134 * unum_close(nf); 135 * nf = unum_open( UNUM_PERCENT, NULL, success ); 136 * unum_close(nf); 137 * \endcode 138 * </pre> 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 143 * <pre> 144 * \code 145 * 146 * nf = unum_open( UNUM_DEFAULT, myLocale, success ); 147 * unum_close(nf); 148 * nf = unum_open( UNUM_CURRENCY, myLocale, success ); 149 * unum_close(nf); 150 * nf = unum_open( UNUM_PERCENT, myLocale, success ); 151 * unum_close(nf); 152 * \endcode 153 * </pre> 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. 158 * 159 * <P> 160 * Each international service that performs locale-sensitive operations 161 * allows you 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 169 * <pre> 170 * \code 171 * const char* uloc_getAvailable(int32_t index); 172 * int32_t uloc_countAvailable(); 173 * int32_t 174 * uloc_getDisplayName(const char* localeID, 175 * const char* inLocaleID, 176 * UChar* result, 177 * int32_t maxResultSize, 178 * UErrorCode* err); 179 * 180 * \endcode 181 * </pre> 182 * \htmlonly</blockquote>\endhtmlonly 183 * <P> 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. 198 * 199 * @see UResourceBundle 200 */ 201 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" 220 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" 245 246 /** 247 * Useful constant for the maximum size of the language part of a locale ID. 248 * (including the terminating NULL). 249 * @stable ICU 2.0 250 */ 251 #define ULOC_LANG_CAPACITY 12 252 253 /** 254 * Useful constant for the maximum size of the country part of a locale ID 255 * (including the terminating NULL). 256 * @stable ICU 2.0 257 */ 258 #define ULOC_COUNTRY_CAPACITY 4 259 /** 260 * Useful constant for the maximum size of the whole locale ID 261 * (including the terminating NULL and all keywords). 262 * @stable ICU 2.0 263 */ 264 #define ULOC_FULLNAME_CAPACITY 157 265 266 /** 267 * Useful constant for the maximum size of the script part of a locale ID 268 * (including the terminating NULL). 269 * @stable ICU 2.8 270 */ 271 #define ULOC_SCRIPT_CAPACITY 6 272 273 /** 274 * Useful constant for the maximum size of keywords in a locale 275 * @stable ICU 2.8 276 */ 277 #define ULOC_KEYWORDS_CAPACITY 96 278 279 /** 280 * Useful constant for the maximum total size of keywords and their values in a locale 281 * @stable ICU 2.8 282 */ 283 #define ULOC_KEYWORD_AND_VALUES_CAPACITY 100 284 285 /** 286 * Invariant character separating keywords from the locale string 287 * @stable ICU 2.8 288 */ 289 #define ULOC_KEYWORD_SEPARATOR '@' 290 291 /** 292 * Unicode code point for '@' separating keywords from the locale string. 293 * @see ULOC_KEYWORD_SEPARATOR 294 * @stable ICU 4.6 295 */ 296 #define ULOC_KEYWORD_SEPARATOR_UNICODE 0x40 297 298 /** 299 * Invariant character for assigning value to a keyword 300 * @stable ICU 2.8 301 */ 302 #define ULOC_KEYWORD_ASSIGN '=' 303 304 /** 305 * Unicode code point for '=' for assigning value to a keyword. 306 * @see ULOC_KEYWORD_ASSIGN 307 * @stable ICU 4.6 308 */ 309 #define ULOC_KEYWORD_ASSIGN_UNICODE 0x3D 310 311 /** 312 * Invariant character separating keywords 313 * @stable ICU 2.8 314 */ 315 #define ULOC_KEYWORD_ITEM_SEPARATOR ';' 316 317 /** 318 * Unicode code point for ';' separating keywords 319 * @see ULOC_KEYWORD_ITEM_SEPARATOR 320 * @stable ICU 4.6 321 */ 322 #define ULOC_KEYWORD_ITEM_SEPARATOR_UNICODE 0x3B 323 324 /** 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 333 * from the UCA) 334 * The locale is considered supported by ICU if there is a core ICU bundle 335 * for that locale (although it may be empty). 336 * @stable ICU 2.1 337 */ 338 typedef enum { 339 /** This is locale the data actually comes from 340 * @stable ICU 2.1 341 */ 342 ULOC_ACTUAL_LOCALE = 0, 343 /** This is the most specific locale supported by ICU 344 * @stable ICU 2.1 345 */ 346 ULOC_VALID_LOCALE = 1, 347 348 #ifndef U_HIDE_DEPRECATED_API 349 /** This is the requested locale 350 * @deprecated ICU 2.8 351 */ 352 ULOC_REQUESTED_LOCALE = 2, 353 354 /** 355 * One more than the highest normal ULocDataLocaleType value. 356 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 357 */ 358 ULOC_DATA_LOCALE_TYPE_LIMIT = 3 359 #endif // U_HIDE_DEPRECATED_API 360 } ULocDataLocaleType; 361 362 #ifndef U_HIDE_SYSTEM_API 363 /** 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 368 * by the caller. 369 * 370 * @return the ICU default locale 371 * @system 372 * @stable ICU 2.0 373 */ 374 U_CAPI const char* U_EXPORT2 375 uloc_getDefault(void); 376 377 /** 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. 381 * <p> 382 * Changes to ICU's default locale do not propagate back to the 383 * system environment. 384 * <p> 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. 387 * 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 391 * @system 392 * @stable ICU 2.0 393 */ 394 U_CAPI void U_EXPORT2 395 uloc_setDefault(const char* localeID, 396 UErrorCode* status); 397 #endif /* U_HIDE_SYSTEM_API */ 398 399 /** 400 * Gets the language code for the specified locale. 401 * 402 * This function may return with a failure error code for certain kinds of inputs 403 * but does not fully check for well-formed locale IDs / language tags. 404 * 405 * @param localeID the locale to get the ISO language code with 406 * @param language the language code for localeID 407 * @param languageCapacity the size of the language buffer to store the 408 * language code with 409 * @param err error information if retrieving the language code failed 410 * @return the actual buffer size needed for the language code. If it's greater 411 * than languageCapacity, the returned language code will be truncated. 412 * @stable ICU 2.0 413 */ 414 U_CAPI int32_t U_EXPORT2 415 uloc_getLanguage(const char* localeID, 416 char* language, 417 int32_t languageCapacity, 418 UErrorCode* err); 419 420 /** 421 * Gets the script code for the specified locale. 422 * 423 * This function may return with a failure error code for certain kinds of inputs 424 * but does not fully check for well-formed locale IDs / language tags. 425 * 426 * @param localeID the locale to get the ISO language code with 427 * @param script the language code for localeID 428 * @param scriptCapacity the size of the language buffer to store the 429 * language code with 430 * @param err error information if retrieving the language code failed 431 * @return the actual buffer size needed for the language code. If it's greater 432 * than scriptCapacity, the returned language code will be truncated. 433 * @stable ICU 2.8 434 */ 435 U_CAPI int32_t U_EXPORT2 436 uloc_getScript(const char* localeID, 437 char* script, 438 int32_t scriptCapacity, 439 UErrorCode* err); 440 441 /** 442 * Gets the country code for the specified locale. 443 * 444 * This function may return with a failure error code for certain kinds of inputs 445 * but does not fully check for well-formed locale IDs / language tags. 446 * 447 * @param localeID the locale to get the country code with 448 * @param country the country code for localeID 449 * @param countryCapacity the size of the country buffer to store the 450 * country code with 451 * @param err error information if retrieving the country code failed 452 * @return the actual buffer size needed for the country code. If it's greater 453 * than countryCapacity, the returned country code will be truncated. 454 * @stable ICU 2.0 455 */ 456 U_CAPI int32_t U_EXPORT2 457 uloc_getCountry(const char* localeID, 458 char* country, 459 int32_t countryCapacity, 460 UErrorCode* err); 461 462 /** 463 * Gets the variant code for the specified locale. 464 * 465 * This function may return with a failure error code for certain kinds of inputs 466 * but does not fully check for well-formed locale IDs / language tags. 467 * 468 * @param localeID the locale to get the variant code with 469 * @param variant the variant code for localeID 470 * @param variantCapacity the size of the variant buffer to store the 471 * variant code with 472 * @param err error information if retrieving the variant code failed 473 * @return the actual buffer size needed for the variant code. If it's greater 474 * than variantCapacity, the returned variant code will be truncated. 475 * @stable ICU 2.0 476 */ 477 U_CAPI int32_t U_EXPORT2 478 uloc_getVariant(const char* localeID, 479 char* variant, 480 int32_t variantCapacity, 481 UErrorCode* err); 482 483 484 /** 485 * Gets the full name for the specified locale. 486 * 487 * This function may return with a failure error code for certain kinds of inputs 488 * but does not fully check for well-formed locale IDs / language tags. 489 * 490 * Note: This has the effect of 'canonicalizing' the ICU locale ID to 491 * a certain extent. Upper and lower case are set as needed. 492 * It does NOT map aliased names in any way. 493 * See the top of this header file. 494 * This API supports preflighting. 495 * 496 * @param localeID the locale to get the full name with 497 * @param name fill in buffer for the name without keywords. 498 * @param nameCapacity capacity of the fill in buffer. 499 * @param err error information if retrieving the full name failed 500 * @return the actual buffer size needed for the full name. If it's greater 501 * than nameCapacity, the returned full name will be truncated. 502 * @stable ICU 2.0 503 */ 504 U_CAPI int32_t U_EXPORT2 505 uloc_getName(const char* localeID, 506 char* name, 507 int32_t nameCapacity, 508 UErrorCode* err); 509 510 /** 511 * Gets the full name for the specified locale. 512 * Note: This has the effect of 'canonicalizing' the string to 513 * a certain extent. Upper and lower case are set as needed, 514 * and if the components were in 'POSIX' format they are changed to 515 * ICU format. It does NOT map aliased names in any way. 516 * See the top of this header file. 517 * 518 * @param localeID the locale to get the full name with 519 * @param name the full name for localeID 520 * @param nameCapacity the size of the name buffer to store the 521 * full name with 522 * @param err error information if retrieving the full name failed 523 * @return the actual buffer size needed for the full name. If it's greater 524 * than nameCapacity, the returned full name will be truncated. 525 * @stable ICU 2.8 526 */ 527 U_CAPI int32_t U_EXPORT2 528 uloc_canonicalize(const char* localeID, 529 char* name, 530 int32_t nameCapacity, 531 UErrorCode* err); 532 533 /** 534 * Gets the ISO language code for the specified locale. 535 * 536 * @param localeID the locale to get the ISO language code with 537 * @return language the ISO language code for localeID 538 * @stable ICU 2.0 539 */ 540 U_CAPI const char* U_EXPORT2 541 uloc_getISO3Language(const char* localeID); 542 543 544 /** 545 * Gets the ISO country code for the specified locale. 546 * 547 * @param localeID the locale to get the ISO country code with 548 * @return country the ISO country code for localeID 549 * @stable ICU 2.0 550 */ 551 U_CAPI const char* U_EXPORT2 552 uloc_getISO3Country(const char* localeID); 553 554 /** 555 * Gets the Win32 LCID value for the specified locale. 556 * If the ICU locale is not recognized by Windows, 0 will be returned. 557 * 558 * LCIDs were deprecated with Windows Vista and Microsoft recommends 559 * that developers use BCP47 style tags instead (uloc_toLanguageTag). 560 * 561 * @param localeID the locale to get the Win32 LCID value with 562 * @return country the Win32 LCID for localeID 563 * @stable ICU 2.0 564 */ 565 U_CAPI uint32_t U_EXPORT2 566 uloc_getLCID(const char* localeID); 567 568 /** 569 * Gets the language name suitable for display for the specified locale. 570 * 571 * @param locale the locale to get the ISO language code with 572 * @param displayLocale Specifies the locale to be used to display the name. In 573 * other words, if the locale's language code is "en", passing 574 * Locale::getFrench() for inLocale would result in "Anglais", 575 * while passing Locale::getGerman() for inLocale would result 576 * in "Englisch". 577 * @param language the displayable language code for localeID 578 * @param languageCapacity the size of the language buffer to store the 579 * displayable language code with. 580 * @param status error information if retrieving the displayable language code 581 * failed. U_USING_DEFAULT_WARNING indicates that no data was 582 * found from the locale resources and a case canonicalized 583 * language code is placed into language as fallback. 584 * @return the actual buffer size needed for the displayable language code. If 585 * it's greater than languageCapacity, the returned language 586 * code will be truncated. 587 * @stable ICU 2.0 588 */ 589 U_CAPI int32_t U_EXPORT2 590 uloc_getDisplayLanguage(const char* locale, 591 const char* displayLocale, 592 UChar* language, 593 int32_t languageCapacity, 594 UErrorCode* status); 595 596 /** 597 * Gets the script name suitable for display for the specified locale. 598 * 599 * @param locale the locale to get the displayable script code with. NULL may be 600 * used to specify the default. 601 * @param displayLocale Specifies the locale to be used to display the name. In 602 * other words, if the locale's language code is "en", passing 603 * Locale::getFrench() for inLocale would result in "", while 604 * passing Locale::getGerman() for inLocale would result in "". 605 * NULL may be used to specify the default. 606 * @param script the displayable script for the localeID. 607 * @param scriptCapacity the size of the script buffer to store the displayable 608 * script code with. 609 * @param status error information if retrieving the displayable script code 610 * failed. U_USING_DEFAULT_WARNING indicates that no data was 611 * found from the locale resources and a case canonicalized 612 * script code is placed into script as fallback. 613 * @return the actual buffer size needed for the displayable script code. If 614 * it's greater than scriptCapacity, the returned displayable 615 * script code will be truncated. 616 * @stable ICU 2.8 617 */ 618 U_CAPI int32_t U_EXPORT2 619 uloc_getDisplayScript(const char* locale, 620 const char* displayLocale, 621 UChar* script, 622 int32_t scriptCapacity, 623 UErrorCode* status); 624 625 /** 626 * Gets the country name suitable for display for the specified locale. 627 * Warning: this is for the region part of a valid locale ID; it cannot just be 628 * the region code (like "FR"). To get the display name for a region alone, or 629 * for other options, use ULocaleDisplayNames instead. 630 * 631 * @param locale the locale to get the displayable country code with. NULL may 632 * be used to specify the default. 633 * @param displayLocale Specifies the locale to be used to display the name. In 634 * other words, if the locale's language code is "en", passing 635 * Locale::getFrench() for inLocale would result in "Anglais", 636 * while passing Locale::getGerman() for inLocale would result 637 * in "Englisch". NULL may be used to specify the default. 638 * @param country the displayable country code for localeID. 639 * @param countryCapacity the size of the country buffer to store the 640 * displayable country code with. 641 * @param status error information if retrieving the displayable country code 642 * failed. U_USING_DEFAULT_WARNING indicates that no data was 643 * found from the locale resources and a case canonicalized 644 * country code is placed into country as fallback. 645 * @return the actual buffer size needed for the displayable country code. If 646 * it's greater than countryCapacity, the returned displayable 647 * country code will be truncated. 648 * @stable ICU 2.0 649 */ 650 U_CAPI int32_t U_EXPORT2 651 uloc_getDisplayCountry(const char* locale, 652 const char* displayLocale, 653 UChar* country, 654 int32_t countryCapacity, 655 UErrorCode* status); 656 657 658 /** 659 * Gets the variant name suitable for display for the specified locale. 660 * 661 * @param locale the locale to get the displayable variant code with. NULL may 662 * be used to specify the default. 663 * @param displayLocale Specifies the locale to be used to display the name. In 664 * other words, if the locale's language code is "en", passing 665 * Locale::getFrench() for inLocale would result in "Anglais", 666 * while passing Locale::getGerman() for inLocale would result 667 * in "Englisch". NULL may be used to specify the default. 668 * @param variant the displayable variant code for localeID. 669 * @param variantCapacity the size of the variant buffer to store the 670 * displayable variant code with. 671 * @param status error information if retrieving the displayable variant code 672 * failed. U_USING_DEFAULT_WARNING indicates that no data was 673 * found from the locale resources and a case canonicalized 674 * variant code is placed into variant as fallback. 675 * @return the actual buffer size needed for the displayable variant code. If 676 * it's greater than variantCapacity, the returned displayable 677 * variant code will be truncated. 678 * @stable ICU 2.0 679 */ 680 U_CAPI int32_t U_EXPORT2 681 uloc_getDisplayVariant(const char* locale, 682 const char* displayLocale, 683 UChar* variant, 684 int32_t variantCapacity, 685 UErrorCode* status); 686 687 /** 688 * Gets the keyword name suitable for display for the specified locale. E.g: 689 * for the locale string de_DE\@collation=PHONEBOOK, this API gets the display 690 * string for the keyword collation. 691 * Usage: 692 * <code> 693 * UErrorCode status = U_ZERO_ERROR; 694 * const char* keyword =NULL; 695 * int32_t keywordLen = 0; 696 * int32_t keywordCount = 0; 697 * UChar displayKeyword[256]; 698 * int32_t displayKeywordLen = 0; 699 * UEnumeration* keywordEnum = uloc_openKeywords("de_DE@collation=PHONEBOOK;calendar=TRADITIONAL", &status); 700 * for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){ 701 * if(U_FAILURE(status)){ 702 * ...something went wrong so handle the error... 703 * break; 704 * } 705 * // the uenum_next returns NUL terminated string 706 * keyword = uenum_next(keywordEnum, &keywordLen, &status); 707 * displayKeywordLen = uloc_getDisplayKeyword(keyword, "en_US", displayKeyword, 256); 708 * ... do something interesting ..... 709 * } 710 * uenum_close(keywordEnum); 711 * </code> 712 * @param keyword The keyword whose display string needs to be returned. 713 * @param displayLocale Specifies the locale to be used to display the name. In other words, 714 * if the locale's language code is "en", passing Locale::getFrench() for 715 * inLocale would result in "Anglais", while passing Locale::getGerman() 716 * for inLocale would result in "Englisch". NULL may be used to specify the default. 717 * @param dest the buffer to which the displayable keyword should be written. 718 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 719 * dest may be NULL and the function will only return the length of the 720 * result without writing any of the result string (pre-flighting). 721 * @param status error information if retrieving the displayable string failed. 722 * Should not be NULL and should not indicate failure on entry. 723 * U_USING_DEFAULT_WARNING indicates that no data was found from the locale 724 * resources and the keyword is placed into dest as fallback. 725 * @return the actual buffer size needed for the displayable variant code. 726 * @see #uloc_openKeywords 727 * @stable ICU 2.8 728 */ 729 U_CAPI int32_t U_EXPORT2 730 uloc_getDisplayKeyword(const char* keyword, 731 const char* displayLocale, 732 UChar* dest, 733 int32_t destCapacity, 734 UErrorCode* status); 735 /** 736 * Gets the value of the keyword suitable for display for the specified locale. 737 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display 738 * string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword. 739 * 740 * @param locale The locale to get the displayable variant code with. NULL may be used to specify the default. 741 * @param keyword The keyword for whose value should be used. 742 * @param displayLocale Specifies the locale to be used to display the name. In other words, 743 * if the locale's language code is "en", passing Locale::getFrench() for 744 * inLocale would result in "Anglais", while passing Locale::getGerman() 745 * for inLocale would result in "Englisch". NULL may be used to specify the default. 746 * @param dest the buffer to which the displayable keyword should be written. 747 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 748 * dest may be NULL and the function will only return the length of the 749 * result without writing any of the result string (pre-flighting). 750 * @param status error information if retrieving the displayable string failed. 751 * Should not be NULL and must not indicate failure on entry. 752 * U_USING_DEFAULT_WARNING indicates that no data was found from the locale 753 * resources and the value of the keyword is placed into dest as fallback. 754 * @return the actual buffer size needed for the displayable variant code. 755 * @stable ICU 2.8 756 */ 757 U_CAPI int32_t U_EXPORT2 758 uloc_getDisplayKeywordValue( const char* locale, 759 const char* keyword, 760 const char* displayLocale, 761 UChar* dest, 762 int32_t destCapacity, 763 UErrorCode* status); 764 /** 765 * Gets the full name suitable for display for the specified locale. 766 * 767 * @param localeID the locale to get the displayable name with. NULL may be used to specify the default. 768 * @param inLocaleID Specifies the locale to be used to display the name. In other words, 769 * if the locale's language code is "en", passing Locale::getFrench() for 770 * inLocale would result in "Anglais", while passing Locale::getGerman() 771 * for inLocale would result in "Englisch". NULL may be used to specify the default. 772 * @param result the displayable name for localeID 773 * @param maxResultSize the size of the name buffer to store the 774 * displayable full name with 775 * @param err error information if retrieving the displayable name failed 776 * @return the actual buffer size needed for the displayable name. If it's greater 777 * than maxResultSize, the returned displayable name will be truncated. 778 * @stable ICU 2.0 779 */ 780 U_CAPI int32_t U_EXPORT2 781 uloc_getDisplayName(const char* localeID, 782 const char* inLocaleID, 783 UChar* result, 784 int32_t maxResultSize, 785 UErrorCode* err); 786 787 788 /** 789 * Gets the specified locale from a list of available locales. 790 * 791 * This method corresponds to uloc_openAvailableByType called with the 792 * ULOC_AVAILABLE_DEFAULT type argument. 793 * 794 * The return value is a pointer to an item of a locale name array. Both this 795 * array and the pointers it contains are owned by ICU and should not be 796 * deleted or written through by the caller. The locale name is terminated by 797 * a null pointer. 798 * 799 * @param n the specific locale name index of the available locale list; 800 * should not exceed the number returned by uloc_countAvailable. 801 * @return a specified locale name of all available locales 802 * @stable ICU 2.0 803 */ 804 U_CAPI const char* U_EXPORT2 805 uloc_getAvailable(int32_t n); 806 807 /** 808 * Gets the size of the all available locale list. 809 * 810 * @return the size of the locale list 811 * @stable ICU 2.0 812 */ 813 U_CAPI int32_t U_EXPORT2 uloc_countAvailable(void); 814 815 /** 816 * Types for uloc_getAvailableByType and uloc_countAvailableByType. 817 * 818 * @stable ICU 65 819 */ 820 typedef enum ULocAvailableType { 821 /** 822 * Locales that return data when passed to ICU APIs, 823 * but not including legacy or alias locales. 824 * 825 * @stable ICU 65 826 */ 827 ULOC_AVAILABLE_DEFAULT, 828 829 /** 830 * Legacy or alias locales that return data when passed to ICU APIs. 831 * Examples of supported legacy or alias locales: 832 * 833 * - iw (alias to he) 834 * - mo (alias to ro) 835 * - zh_CN (alias to zh_Hans_CN) 836 * - sr_BA (alias to sr_Cyrl_BA) 837 * - ars (alias to ar_SA) 838 * 839 * The locales in this set are disjoint from the ones in 840 * ULOC_AVAILABLE_DEFAULT. To get both sets at the same time, use 841 * ULOC_AVAILABLE_WITH_LEGACY_ALIASES. 842 * 843 * @stable ICU 65 844 */ 845 ULOC_AVAILABLE_ONLY_LEGACY_ALIASES, 846 847 /** 848 * The union of the locales in ULOC_AVAILABLE_DEFAULT and 849 * ULOC_AVAILABLE_ONLY_LEGACY_ALIAS. 850 * 851 * @stable ICU 65 852 */ 853 ULOC_AVAILABLE_WITH_LEGACY_ALIASES, 854 855 #ifndef U_HIDE_INTERNAL_API 856 /** 857 * @internal 858 */ 859 ULOC_AVAILABLE_COUNT 860 #endif /* U_HIDE_INTERNAL_API */ 861 } ULocAvailableType; 862 863 /** 864 * Gets a list of available locales according to the type argument, allowing 865 * the user to access different sets of supported locales in ICU. 866 * 867 * The returned UEnumeration must be closed by the caller. 868 * 869 * @param type Type choice from ULocAvailableType. 870 * @param status Set if an error occurred. 871 * @return a UEnumeration owned by the caller, or nullptr on failure. 872 * @stable ICU 65 873 */ 874 U_CAPI UEnumeration* U_EXPORT2 875 uloc_openAvailableByType(ULocAvailableType type, UErrorCode* status); 876 877 /** 878 * 879 * Gets a list of all available 2-letter language codes defined in ISO 639, 880 * plus additional 3-letter codes determined to be useful for locale generation as 881 * defined by Unicode CLDR. This is a pointer 882 * to an array of pointers to arrays of char. All of these pointers are owned 883 * by ICU-- do not delete them, and do not write through them. The array is 884 * terminated with a null pointer. 885 * @return a list of all available language codes 886 * @stable ICU 2.0 887 */ 888 U_CAPI const char* const* U_EXPORT2 889 uloc_getISOLanguages(void); 890 891 /** 892 * 893 * Gets a list of all available 2-letter country codes defined in ISO 639. This is a 894 * pointer to an array of pointers to arrays of char. All of these pointers are 895 * owned by ICU-- do not delete them, and do not write through them. The array is 896 * terminated with a null pointer. 897 * @return a list of all available country codes 898 * @stable ICU 2.0 899 */ 900 U_CAPI const char* const* U_EXPORT2 901 uloc_getISOCountries(void); 902 903 /** 904 * Truncate the locale ID string to get the parent locale ID. 905 * Copies the part of the string before the last underscore. 906 * The parent locale ID will be an empty string if there is no 907 * underscore, or if there is only one underscore at localeID[0]. 908 * 909 * @param localeID Input locale ID string. 910 * @param parent Output string buffer for the parent locale ID. 911 * @param parentCapacity Size of the output buffer. 912 * @param err A UErrorCode value. 913 * @return The length of the parent locale ID. 914 * @stable ICU 2.0 915 */ 916 U_CAPI int32_t U_EXPORT2 917 uloc_getParent(const char* localeID, 918 char* parent, 919 int32_t parentCapacity, 920 UErrorCode* err); 921 922 923 924 925 /** 926 * Gets the full name for the specified locale, like uloc_getName(), 927 * but without keywords. 928 * 929 * Note: This has the effect of 'canonicalizing' the string to 930 * a certain extent. Upper and lower case are set as needed, 931 * and if the components were in 'POSIX' format they are changed to 932 * ICU format. It does NOT map aliased names in any way. 933 * See the top of this header file. 934 * 935 * This API strips off the keyword part, so "de_DE\@collation=phonebook" 936 * will become "de_DE". 937 * This API supports preflighting. 938 * 939 * @param localeID the locale to get the full name with 940 * @param name fill in buffer for the name without keywords. 941 * @param nameCapacity capacity of the fill in buffer. 942 * @param err error information if retrieving the full name failed 943 * @return the actual buffer size needed for the full name. If it's greater 944 * than nameCapacity, the returned full name will be truncated. 945 * @stable ICU 2.8 946 */ 947 U_CAPI int32_t U_EXPORT2 948 uloc_getBaseName(const char* localeID, 949 char* name, 950 int32_t nameCapacity, 951 UErrorCode* err); 952 953 /** 954 * Gets an enumeration of keywords for the specified locale. Enumeration 955 * must get disposed of by the client using uenum_close function. 956 * 957 * @param localeID the locale to get the variant code with 958 * @param status error information if retrieving the keywords failed 959 * @return enumeration of keywords or NULL if there are no keywords. 960 * @stable ICU 2.8 961 */ 962 U_CAPI UEnumeration* U_EXPORT2 963 uloc_openKeywords(const char* localeID, 964 UErrorCode* status); 965 966 /** 967 * Get the value for a keyword. Locale name does not need to be normalized. 968 * 969 * @param localeID locale name containing the keyword ("de_DE@currency=EURO;collation=PHONEBOOK") 970 * @param keywordName name of the keyword for which we want the value; must not be 971 * NULL or empty, and must consist only of [A-Za-z0-9]. Case insensitive. 972 * @param buffer receiving buffer 973 * @param bufferCapacity capacity of receiving buffer 974 * @param status containing error code: e.g. buffer not big enough or ill-formed localeID 975 * or keywordName parameters. 976 * @return the length of keyword value 977 * @stable ICU 2.8 978 */ 979 U_CAPI int32_t U_EXPORT2 980 uloc_getKeywordValue(const char* localeID, 981 const char* keywordName, 982 char* buffer, int32_t bufferCapacity, 983 UErrorCode* status); 984 985 986 /** 987 * Sets or removes the value of the specified keyword. 988 * 989 * For removing all keywords, use uloc_getBaseName(). 990 * 991 * NOTE: Unlike almost every other ICU function which takes a 992 * buffer, this function will NOT truncate the output text, and will 993 * not update the buffer with unterminated text setting a status of 994 * U_STRING_NOT_TERMINATED_WARNING. If a BUFFER_OVERFLOW_ERROR is received, 995 * it means a terminated version of the updated locale ID would not fit 996 * in the buffer, and the original buffer is untouched. This is done to 997 * prevent incorrect or possibly even malformed locales from being generated 998 * and used. 999 * 1000 * @param keywordName name of the keyword to be set; must not be 1001 * NULL or empty, and must consist only of [A-Za-z0-9]. Case insensitive. 1002 * @param keywordValue value of the keyword to be set. If 0-length or 1003 * NULL, will result in the keyword being removed; no error is given if 1004 * that keyword does not exist. Otherwise, must consist only of 1005 * [A-Za-z0-9] and [/_+-]. 1006 * @param buffer input buffer containing well-formed locale ID to be 1007 * modified. 1008 * @param bufferCapacity capacity of receiving buffer 1009 * @param status containing error code: e.g. buffer not big enough 1010 * or ill-formed keywordName or keywordValue parameters, or ill-formed 1011 * locale ID in buffer on input. 1012 * @return the length needed for the buffer 1013 * @see uloc_getKeywordValue 1014 * @stable ICU 3.2 1015 */ 1016 U_CAPI int32_t U_EXPORT2 1017 uloc_setKeywordValue(const char* keywordName, 1018 const char* keywordValue, 1019 char* buffer, int32_t bufferCapacity, 1020 UErrorCode* status); 1021 1022 /** 1023 * Returns whether the locale's script is written right-to-left. 1024 * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags(). 1025 * If no likely script is known, then false is returned. 1026 * 1027 * A script is right-to-left according to the CLDR script metadata 1028 * which corresponds to whether the script's letters have Bidi_Class=R or AL. 1029 * 1030 * Returns true for "ar" and "en-Hebr", false for "zh" and "fa-Cyrl". 1031 * 1032 * @param locale input locale ID 1033 * @return true if the locale's script is written right-to-left 1034 * @stable ICU 54 1035 */ 1036 U_CAPI UBool U_EXPORT2 1037 uloc_isRightToLeft(const char *locale); 1038 1039 /** 1040 * enums for the return value for the character and line orientation 1041 * functions. 1042 * @stable ICU 4.0 1043 */ 1044 typedef enum { 1045 ULOC_LAYOUT_LTR = 0, /* left-to-right. */ 1046 ULOC_LAYOUT_RTL = 1, /* right-to-left. */ 1047 ULOC_LAYOUT_TTB = 2, /* top-to-bottom. */ 1048 ULOC_LAYOUT_BTT = 3, /* bottom-to-top. */ 1049 ULOC_LAYOUT_UNKNOWN 1050 } ULayoutType; 1051 1052 /** 1053 * Get the layout character orientation for the specified locale. 1054 * 1055 * @param localeId locale name 1056 * @param status Error status 1057 * @return an enum indicating the layout orientation for characters. 1058 * @stable ICU 4.0 1059 */ 1060 U_CAPI ULayoutType U_EXPORT2 1061 uloc_getCharacterOrientation(const char* localeId, 1062 UErrorCode *status); 1063 1064 /** 1065 * Get the layout line orientation for the specified locale. 1066 * 1067 * @param localeId locale name 1068 * @param status Error status 1069 * @return an enum indicating the layout orientation for lines. 1070 * @stable ICU 4.0 1071 */ 1072 U_CAPI ULayoutType U_EXPORT2 1073 uloc_getLineOrientation(const char* localeId, 1074 UErrorCode *status); 1075 1076 /** 1077 * Output values which uloc_acceptLanguage() writes to the 'outResult' parameter. 1078 * 1079 * @see uloc_acceptLanguageFromHTTP 1080 * @see uloc_acceptLanguage 1081 * @stable ICU 3.2 1082 */ 1083 typedef enum { 1084 /** 1085 * No exact match was found. 1086 * @stable ICU 3.2 1087 */ 1088 ULOC_ACCEPT_FAILED = 0, 1089 /** 1090 * An exact match was found. 1091 * @stable ICU 3.2 1092 */ 1093 ULOC_ACCEPT_VALID = 1, 1094 /** 1095 * A fallback was found. For example, the Accept-Language list includes 'ja_JP' 1096 * and is matched with available locale 'ja'. 1097 * @stable ICU 3.2 1098 */ 1099 ULOC_ACCEPT_FALLBACK = 2 /* */ 1100 } UAcceptResult; 1101 1102 /** 1103 * Based on a HTTP header from a web browser and a list of available locales, 1104 * determine an acceptable locale for the user. 1105 * 1106 * This is a thin wrapper over C++ class LocaleMatcher. 1107 * 1108 * @param result - buffer to accept the result locale 1109 * @param resultAvailable the size of the result buffer. 1110 * @param outResult - An out parameter that contains the fallback status 1111 * @param httpAcceptLanguage - "Accept-Language:" header as per HTTP. 1112 * @param availableLocales - list of available locales to match 1113 * @param status ICU error code. Its input value must pass the U_SUCCESS() test, 1114 * or else the function returns immediately. Check for U_FAILURE() 1115 * on output or use with function chaining. (See User Guide for details.) 1116 * @return length needed for the locale. 1117 * @stable ICU 3.2 1118 */ 1119 U_CAPI int32_t U_EXPORT2 1120 uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable, 1121 UAcceptResult *outResult, 1122 const char *httpAcceptLanguage, 1123 UEnumeration* availableLocales, 1124 UErrorCode *status); 1125 1126 /** 1127 * Based on a list of available locales, 1128 * determine an acceptable locale for the user. 1129 * 1130 * This is a thin wrapper over C++ class LocaleMatcher. 1131 * 1132 * @param result - buffer to accept the result locale 1133 * @param resultAvailable the size of the result buffer. 1134 * @param outResult - An out parameter that contains the fallback status 1135 * @param acceptList - list of acceptable languages 1136 * @param acceptListCount - count of acceptList items 1137 * @param availableLocales - list of available locales to match 1138 * @param status ICU error code. Its input value must pass the U_SUCCESS() test, 1139 * or else the function returns immediately. Check for U_FAILURE() 1140 * on output or use with function chaining. (See User Guide for details.) 1141 * @return length needed for the locale. 1142 * @stable ICU 3.2 1143 */ 1144 U_CAPI int32_t U_EXPORT2 1145 uloc_acceptLanguage(char *result, int32_t resultAvailable, 1146 UAcceptResult *outResult, const char **acceptList, 1147 int32_t acceptListCount, 1148 UEnumeration* availableLocales, 1149 UErrorCode *status); 1150 1151 1152 /** 1153 * Gets the ICU locale ID for the specified Win32 LCID value. 1154 * 1155 * @param hostID the Win32 LCID to translate 1156 * @param locale the output buffer for the ICU locale ID, which will be NUL-terminated 1157 * if there is room. 1158 * @param localeCapacity the size of the output buffer 1159 * @param status an error is returned if the LCID is unrecognized or the output buffer 1160 * is too small 1161 * @return actual the actual size of the locale ID, not including NUL-termination 1162 * @stable ICU 3.8 1163 */ 1164 U_CAPI int32_t U_EXPORT2 1165 uloc_getLocaleForLCID(uint32_t hostID, char *locale, int32_t localeCapacity, 1166 UErrorCode *status); 1167 1168 1169 /** 1170 * Add the likely subtags for a provided locale ID, per the algorithm described 1171 * in the following CLDR technical report: 1172 * 1173 * http://www.unicode.org/reports/tr35/#Likely_Subtags 1174 * 1175 * If localeID is already in the maximal form, or there is no data available 1176 * for maximization, it will be copied to the output buffer. For example, 1177 * "sh" cannot be maximized, since there is no reasonable maximization. 1178 * 1179 * Examples: 1180 * 1181 * "und_Zzzz" maximizes to "en_Latn_US" 1182 * 1183 * "en" maximizes to "en_Latn_US" 1184 * 1185 * "de" maximizes to "de_Latn_DE" 1186 * 1187 * "sr" maximizes to "sr_Cyrl_RS" 1188 * 1189 * "zh_Hani" maximizes to "zh_Hani_CN" 1190 * 1191 * 1192 * @param localeID The locale to maximize 1193 * @param maximizedLocaleID The maximized locale 1194 * @param maximizedLocaleIDCapacity The capacity of the maximizedLocaleID buffer 1195 * @param err Error information if maximizing the locale failed. If the length 1196 * of the localeID and the null-terminator is greater than the maximum allowed size, 1197 * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR. 1198 * @return The actual buffer size needed for the maximized locale. If it's 1199 * greater than maximizedLocaleIDCapacity, the returned ID will be truncated. 1200 * On error, the return value is -1. 1201 * @stable ICU 4.0 1202 */ 1203 U_CAPI int32_t U_EXPORT2 1204 uloc_addLikelySubtags(const char* localeID, 1205 char* maximizedLocaleID, 1206 int32_t maximizedLocaleIDCapacity, 1207 UErrorCode* err); 1208 1209 1210 /** 1211 * Minimize the subtags for a provided locale ID, per the algorithm described 1212 * in the following CLDR technical report: 1213 * 1214 * http://www.unicode.org/reports/tr35/#Likely_Subtags 1215 * 1216 * If localeID is already in the minimal form, or there is no data available 1217 * for minimization, it will be copied to the output buffer. Since the 1218 * minimization algorithm relies on proper maximization, see the comments 1219 * for uloc_addLikelySubtags for reasons why there might not be any data. 1220 * 1221 * Examples: 1222 * 1223 * "en_Latn_US" minimizes to "en" 1224 * 1225 * "de_Latn_US" minimizes to "de" 1226 * 1227 * "sr_Cyrl_RS" minimizes to "sr" 1228 * 1229 * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the 1230 * script, and minimizing to "zh" would imply "zh_Hans_CN".) 1231 * 1232 * @param localeID The locale to minimize 1233 * @param minimizedLocaleID The minimized locale 1234 * @param minimizedLocaleIDCapacity The capacity of the minimizedLocaleID buffer 1235 * @param err Error information if minimizing the locale failed. If the length 1236 * of the localeID and the null-terminator is greater than the maximum allowed size, 1237 * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR. 1238 * @return The actual buffer size needed for the minimized locale. If it's 1239 * greater than minimizedLocaleIDCapacity, the returned ID will be truncated. 1240 * On error, the return value is -1. 1241 * @stable ICU 4.0 1242 */ 1243 U_CAPI int32_t U_EXPORT2 1244 uloc_minimizeSubtags(const char* localeID, 1245 char* minimizedLocaleID, 1246 int32_t minimizedLocaleIDCapacity, 1247 UErrorCode* err); 1248 1249 /** 1250 * Returns a locale ID for the specified BCP47 language tag string. 1251 * If the specified language tag contains any ill-formed subtags, 1252 * the first such subtag and all following subtags are ignored. 1253 * <p> 1254 * This implements the 'Language-Tag' production of BCP 47, and so 1255 * supports legacy language tags (marked as “Type: grandfathered” in BCP 47) 1256 * (regular and irregular) as well as private use language tags. 1257 * 1258 * Private use tags are represented as 'x-whatever', 1259 * and legacy tags are converted to their canonical replacements where they exist. 1260 * 1261 * Note that a few legacy tags have no modern replacement; 1262 * these will be converted using the fallback described in 1263 * the first paragraph, so some information might be lost. 1264 * 1265 * @param langtag the input BCP47 language tag. 1266 * @param localeID the output buffer receiving a locale ID for the 1267 * specified BCP47 language tag. 1268 * @param localeIDCapacity the size of the locale ID output buffer. 1269 * @param parsedLength if not NULL, successfully parsed length 1270 * for the input language tag is set. 1271 * @param err error information if receiving the locald ID 1272 * failed. 1273 * @return the length of the locale ID. 1274 * @stable ICU 4.2 1275 */ 1276 U_CAPI int32_t U_EXPORT2 1277 uloc_forLanguageTag(const char* langtag, 1278 char* localeID, 1279 int32_t localeIDCapacity, 1280 int32_t* parsedLength, 1281 UErrorCode* err); 1282 1283 /** 1284 * Returns a well-formed language tag for this locale ID. 1285 * <p> 1286 * <b>Note</b>: When <code>strict</code> is false, any locale 1287 * fields which do not satisfy the BCP47 syntax requirement will 1288 * be omitted from the result. When <code>strict</code> is 1289 * true, this function sets U_ILLEGAL_ARGUMENT_ERROR to the 1290 * <code>err</code> if any locale fields do not satisfy the 1291 * BCP47 syntax requirement. 1292 * @param localeID the input locale ID 1293 * @param langtag the output buffer receiving BCP47 language 1294 * tag for the locale ID. 1295 * @param langtagCapacity the size of the BCP47 language tag 1296 * output buffer. 1297 * @param strict boolean value indicating if the function returns 1298 * an error for an ill-formed input locale ID. 1299 * @param err error information if receiving the language 1300 * tag failed. 1301 * @return The length of the BCP47 language tag. 1302 * @stable ICU 4.2 1303 */ 1304 U_CAPI int32_t U_EXPORT2 1305 uloc_toLanguageTag(const char* localeID, 1306 char* langtag, 1307 int32_t langtagCapacity, 1308 UBool strict, 1309 UErrorCode* err); 1310 1311 /** 1312 * Converts the specified keyword (legacy key, or BCP 47 Unicode locale 1313 * extension key) to the equivalent BCP 47 Unicode locale extension key. 1314 * For example, BCP 47 Unicode locale extension key "co" is returned for 1315 * the input keyword "collation". 1316 * <p> 1317 * When the specified keyword is unknown, but satisfies the BCP syntax, 1318 * then the pointer to the input keyword itself will be returned. 1319 * For example, 1320 * <code>uloc_toUnicodeLocaleKey("ZZ")</code> returns "ZZ". 1321 * 1322 * @param keyword the input locale keyword (either legacy key 1323 * such as "collation" or BCP 47 Unicode locale extension 1324 * key such as "co"). 1325 * @return the well-formed BCP 47 Unicode locale extension key, 1326 * or NULL if the specified locale keyword cannot be 1327 * mapped to a well-formed BCP 47 Unicode locale extension 1328 * key. 1329 * @see uloc_toLegacyKey 1330 * @stable ICU 54 1331 */ 1332 U_CAPI const char* U_EXPORT2 1333 uloc_toUnicodeLocaleKey(const char* keyword); 1334 1335 /** 1336 * Converts the specified keyword value (legacy type, or BCP 47 1337 * Unicode locale extension type) to the well-formed BCP 47 Unicode locale 1338 * extension type for the specified keyword (category). For example, BCP 47 1339 * Unicode locale extension type "phonebk" is returned for the input 1340 * keyword value "phonebook", with the keyword "collation" (or "co"). 1341 * <p> 1342 * When the specified keyword is not recognized, but the specified value 1343 * satisfies the syntax of the BCP 47 Unicode locale extension type, 1344 * or when the specified keyword allows 'variable' type and the specified 1345 * value satisfies the syntax, then the pointer to the input type value itself 1346 * will be returned. 1347 * For example, 1348 * <code>uloc_toUnicodeLocaleType("Foo", "Bar")</code> returns "Bar", 1349 * <code>uloc_toUnicodeLocaleType("variableTop", "00A4")</code> returns "00A4". 1350 * 1351 * @param keyword the locale keyword (either legacy key such as 1352 * "collation" or BCP 47 Unicode locale extension 1353 * key such as "co"). 1354 * @param value the locale keyword value (either legacy type 1355 * such as "phonebook" or BCP 47 Unicode locale extension 1356 * type such as "phonebk"). 1357 * @return the well-formed BCP47 Unicode locale extension type, 1358 * or NULL if the locale keyword value cannot be mapped to 1359 * a well-formed BCP 47 Unicode locale extension type. 1360 * @see uloc_toLegacyType 1361 * @stable ICU 54 1362 */ 1363 U_CAPI const char* U_EXPORT2 1364 uloc_toUnicodeLocaleType(const char* keyword, const char* value); 1365 1366 /** 1367 * Converts the specified keyword (BCP 47 Unicode locale extension key, or 1368 * legacy key) to the legacy key. For example, legacy key "collation" is 1369 * returned for the input BCP 47 Unicode locale extension key "co". 1370 * 1371 * @param keyword the input locale keyword (either BCP 47 Unicode locale 1372 * extension key or legacy key). 1373 * @return the well-formed legacy key, or NULL if the specified 1374 * keyword cannot be mapped to a well-formed legacy key. 1375 * @see toUnicodeLocaleKey 1376 * @stable ICU 54 1377 */ 1378 U_CAPI const char* U_EXPORT2 1379 uloc_toLegacyKey(const char* keyword); 1380 1381 /** 1382 * Converts the specified keyword value (BCP 47 Unicode locale extension type, 1383 * or legacy type or type alias) to the canonical legacy type. For example, 1384 * the legacy type "phonebook" is returned for the input BCP 47 Unicode 1385 * locale extension type "phonebk" with the keyword "collation" (or "co"). 1386 * <p> 1387 * When the specified keyword is not recognized, but the specified value 1388 * satisfies the syntax of legacy key, or when the specified keyword 1389 * allows 'variable' type and the specified value satisfies the syntax, 1390 * then the pointer to the input type value itself will be returned. 1391 * For example, 1392 * <code>uloc_toLegacyType("Foo", "Bar")</code> returns "Bar", 1393 * <code>uloc_toLegacyType("vt", "00A4")</code> returns "00A4". 1394 * 1395 * @param keyword the locale keyword (either legacy keyword such as 1396 * "collation" or BCP 47 Unicode locale extension 1397 * key such as "co"). 1398 * @param value the locale keyword value (either BCP 47 Unicode locale 1399 * extension type such as "phonebk" or legacy keyword value 1400 * such as "phonebook"). 1401 * @return the well-formed legacy type, or NULL if the specified 1402 * keyword value cannot be mapped to a well-formed legacy 1403 * type. 1404 * @see toUnicodeLocaleType 1405 * @stable ICU 54 1406 */ 1407 U_CAPI const char* U_EXPORT2 1408 uloc_toLegacyType(const char* keyword, const char* value); 1409 1410 #endif /*_ULOC*/ 1411