1/* 2********************************************************************** 3* Copyright (C) 1997-2009, International Business Machines 4* Corporation and others. All Rights Reserved. 5********************************************************************** 6* 7* File ULOC.H 8* 9* Modification History: 10* 11* Date Name Description 12* 04/01/97 aliu Creation. 13* 08/22/98 stephen JDK 1.2 sync. 14* 12/08/98 rtg New C API for Locale 15* 03/30/99 damiba overhaul 16* 03/31/99 helena Javadoc for uloc functions. 17* 04/15/99 Madhu Updated Javadoc 18******************************************************************************** 19*/ 20 21#ifndef ULOC_H 22#define ULOC_H 23 24#include "unicode/utypes.h" 25#include "unicode/uenum.h" 26 27/** 28 * \file 29 * \brief C API: Locale 30 * 31 * <h2> ULoc C API for Locale </h2> 32 * A <code>Locale</code> represents a specific geographical, political, 33 * or cultural region. An operation that requires a <code>Locale</code> to perform 34 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code> 35 * to tailor information for the user. For example, displaying a number 36 * is a locale-sensitive operation--the number should be formatted 37 * according to the customs/conventions of the user's native country, 38 * region, or culture. In the C APIs, a locales is simply a const char string. 39 * 40 * <P> 41 * You create a <code>Locale</code> with one of the three options listed below. 42 * Each of the component is separated by '_' in the locale string. 43 * \htmlonly<blockquote>\endhtmlonly 44 * <pre> 45 * \code 46 * newLanguage 47 * 48 * newLanguage + newCountry 49 * 50 * newLanguage + newCountry + newVariant 51 * \endcode 52 * </pre> 53 * \htmlonly</blockquote>\endhtmlonly 54 * The first option is a valid <STRONG>ISO 55 * Language Code.</STRONG> These codes are the lower-case two-letter 56 * codes as defined by ISO-639. 57 * You can find a full list of these codes at a number of sites, such as: 58 * <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt"> 59 * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</a> 60 * 61 * <P> 62 * The second option includes an additonal <STRONG>ISO Country 63 * Code.</STRONG> These codes are the upper-case two-letter codes 64 * as defined by ISO-3166. 65 * You can find a full list of these codes at a number of sites, such as: 66 * <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html"> 67 * http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</a> 68 * 69 * <P> 70 * The third option requires another additonal information--the 71 * <STRONG>Variant.</STRONG> 72 * The Variant codes are vendor and browser-specific. 73 * For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. 74 * Where there are two variants, separate them with an underscore, and 75 * put the most important one first. For 76 * example, a Traditional Spanish collation might be referenced, with 77 * "ES", "ES", "Traditional_WIN". 78 * 79 * <P> 80 * Because a <code>Locale</code> is just an identifier for a region, 81 * no validity check is performed when you specify a <code>Locale</code>. 82 * If you want to see whether particular resources are available for the 83 * <code>Locale</code> you asked for, you must query those resources. For 84 * example, ask the <code>UNumberFormat</code> for the locales it supports 85 * using its <code>getAvailable</code> method. 86 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular 87 * locale, you get back the best available match, not necessarily 88 * precisely what you asked for. For more information, look at 89 * <code>UResourceBundle</code>. 90 * 91 * <P> 92 * The <code>Locale</code> provides a number of convenient constants 93 * that you can use to specify the commonly used 94 * locales. For example, the following refers to a locale 95 * for the United States: 96 * \htmlonly<blockquote>\endhtmlonly 97 * <pre> 98 * \code 99 * ULOC_US 100 * \endcode 101 * </pre> 102 * \htmlonly</blockquote>\endhtmlonly 103 * 104 * <P> 105 * Once you've specified a locale you can query it for information about 106 * itself. Use <code>uloc_getCountry</code> to get the ISO Country Code and 107 * <code>uloc_getLanguage</code> to get the ISO Language Code. You can 108 * use <code>uloc_getDisplayCountry</code> to get the 109 * name of the country suitable for displaying to the user. Similarly, 110 * you can use <code>uloc_getDisplayLanguage</code> to get the name of 111 * the language suitable for displaying to the user. Interestingly, 112 * the <code>uloc_getDisplayXXX</code> methods are themselves locale-sensitive 113 * and have two versions: one that uses the default locale and one 114 * that takes a locale as an argument and displays the name or country in 115 * a language appropriate to that locale. 116 * 117 * <P> 118 * The ICU provides a number of services that perform locale-sensitive 119 * operations. For example, the <code>unum_xxx</code> functions format 120 * numbers, currency, or percentages in a locale-sensitive manner. 121 * </P> 122 * \htmlonly<blockquote>\endhtmlonly 123 * <pre> 124 * \code 125 * UErrorCode success = U_ZERO_ERROR; 126 * UNumberFormat *nf; 127 * const char* myLocale = "fr_FR"; 128 * 129 * nf = unum_open( UNUM_DEFAULT, NULL, success ); 130 * unum_close(nf); 131 * nf = unum_open( UNUM_CURRENCY, NULL, success ); 132 * unum_close(nf); 133 * nf = unum_open( UNUM_PERCENT, NULL, success ); 134 * unum_close(nf); 135 * \endcode 136 * </pre> 137 * \htmlonly</blockquote>\endhtmlonly 138 * Each of these methods has two variants; one with an explicit locale 139 * and one without; the latter using the default locale. 140 * \htmlonly<blockquote>\endhtmlonly 141 * <pre> 142 * \code 143 * 144 * nf = unum_open( UNUM_DEFAULT, myLocale, success ); 145 * unum_close(nf); 146 * nf = unum_open( UNUM_CURRENCY, myLocale, success ); 147 * unum_close(nf); 148 * nf = unum_open( UNUM_PERCENT, myLocale, success ); 149 * unum_close(nf); 150 * \endcode 151 * </pre> 152 * \htmlonly</blockquote>\endhtmlonly 153 * A <code>Locale</code> is the mechanism for identifying the kind of services 154 * (<code>UNumberFormat</code>) that you would like to get. The locale is 155 * <STRONG>just</STRONG> a mechanism for identifying these services. 156 * 157 * <P> 158 * Each international serivce that performs locale-sensitive operations 159 * allows you 160 * to get all the available objects of that type. You can sift 161 * through these objects by language, country, or variant, 162 * and use the display names to present a menu to the user. 163 * For example, you can create a menu of all the collation objects 164 * suitable for a given language. Such classes implement these 165 * three class methods: 166 * \htmlonly<blockquote>\endhtmlonly 167 * <pre> 168 * \code 169 * const char* uloc_getAvailable(int32_t index); 170 * int32_t uloc_countAvailable(); 171 * int32_t 172 * uloc_getDisplayName(const char* localeID, 173 * const char* inLocaleID, 174 * UChar* result, 175 * int32_t maxResultSize, 176 * UErrorCode* err); 177 * 178 * \endcode 179 * </pre> 180 * \htmlonly</blockquote>\endhtmlonly 181 * <P> 182 * Concerning POSIX/RFC1766 Locale IDs, 183 * the getLanguage/getCountry/getVariant/getName functions do understand 184 * the POSIX type form of language_COUNTRY.ENCODING\@VARIANT 185 * and if there is not an ICU-stype variant, uloc_getVariant() for example 186 * will return the one listed after the \@at sign. As well, the hyphen 187 * "-" is recognized as a country/variant separator similarly to RFC1766. 188 * So for example, "en-us" will be interpreted as en_US. 189 * As a result, uloc_getName() is far from a no-op, and will have the 190 * effect of converting POSIX/RFC1766 IDs into ICU form, although it does 191 * NOT map any of the actual codes (i.e. russian->ru) in any way. 192 * Applications should call uloc_getName() at the point where a locale ID 193 * is coming from an external source (user entry, OS, web browser) 194 * and pass the resulting string to other ICU functions. For example, 195 * don't use de-de\@EURO as an argument to resourcebundle. 196 * 197 * @see UResourceBundle 198 */ 199 200/** Useful constant for this language. @stable ICU 2.0 */ 201#define ULOC_CHINESE "zh" 202/** Useful constant for this language. @stable ICU 2.0 */ 203#define ULOC_ENGLISH "en" 204/** Useful constant for this language. @stable ICU 2.0 */ 205#define ULOC_FRENCH "fr" 206/** Useful constant for this language. @stable ICU 2.0 */ 207#define ULOC_GERMAN "de" 208/** Useful constant for this language. @stable ICU 2.0 */ 209#define ULOC_ITALIAN "it" 210/** Useful constant for this language. @stable ICU 2.0 */ 211#define ULOC_JAPANESE "ja" 212/** Useful constant for this language. @stable ICU 2.0 */ 213#define ULOC_KOREAN "ko" 214/** Useful constant for this language. @stable ICU 2.0 */ 215#define ULOC_SIMPLIFIED_CHINESE "zh_CN" 216/** Useful constant for this language. @stable ICU 2.0 */ 217#define ULOC_TRADITIONAL_CHINESE "zh_TW" 218 219/** Useful constant for this country/region. @stable ICU 2.0 */ 220#define ULOC_CANADA "en_CA" 221/** Useful constant for this country/region. @stable ICU 2.0 */ 222#define ULOC_CANADA_FRENCH "fr_CA" 223/** Useful constant for this country/region. @stable ICU 2.0 */ 224#define ULOC_CHINA "zh_CN" 225/** Useful constant for this country/region. @stable ICU 2.0 */ 226#define ULOC_PRC "zh_CN" 227/** Useful constant for this country/region. @stable ICU 2.0 */ 228#define ULOC_FRANCE "fr_FR" 229/** Useful constant for this country/region. @stable ICU 2.0 */ 230#define ULOC_GERMANY "de_DE" 231/** Useful constant for this country/region. @stable ICU 2.0 */ 232#define ULOC_ITALY "it_IT" 233/** Useful constant for this country/region. @stable ICU 2.0 */ 234#define ULOC_JAPAN "ja_JP" 235/** Useful constant for this country/region. @stable ICU 2.0 */ 236#define ULOC_KOREA "ko_KR" 237/** Useful constant for this country/region. @stable ICU 2.0 */ 238#define ULOC_TAIWAN "zh_TW" 239/** Useful constant for this country/region. @stable ICU 2.0 */ 240#define ULOC_UK "en_GB" 241/** Useful constant for this country/region. @stable ICU 2.0 */ 242#define ULOC_US "en_US" 243 244/** 245 * Useful constant for the maximum size of the language part of a locale ID. 246 * (including the terminating NULL). 247 * @stable ICU 2.0 248 */ 249#define ULOC_LANG_CAPACITY 12 250 251/** 252 * Useful constant for the maximum size of the country part of a locale ID 253 * (including the terminating NULL). 254 * @stable ICU 2.0 255 */ 256#define ULOC_COUNTRY_CAPACITY 4 257/** 258 * Useful constant for the maximum size of the whole locale ID 259 * (including the terminating NULL and all keywords). 260 * @stable ICU 2.0 261 */ 262#define ULOC_FULLNAME_CAPACITY 157 263 264/** 265 * Useful constant for the maximum size of the script part of a locale ID 266 * (including the terminating NULL). 267 * @stable ICU 2.8 268 */ 269#define ULOC_SCRIPT_CAPACITY 6 270 271/** 272 * Useful constant for the maximum size of keywords in a locale 273 * @stable ICU 2.8 274 */ 275#define ULOC_KEYWORDS_CAPACITY 50 276 277/** 278 * Useful constant for the maximum total size of keywords and their values in a locale 279 * @stable ICU 2.8 280 */ 281#define ULOC_KEYWORD_AND_VALUES_CAPACITY 100 282 283/** 284 * Character separating keywords from the locale string 285 * different for EBCDIC - TODO 286 * @stable ICU 2.8 287 */ 288#define ULOC_KEYWORD_SEPARATOR '@' 289/** 290 * Character for assigning value to a keyword 291 * @stable ICU 2.8 292 */ 293#define ULOC_KEYWORD_ASSIGN '=' 294/** 295 * Character separating keywords 296 * @stable ICU 2.8 297 */ 298#define ULOC_KEYWORD_ITEM_SEPARATOR ';' 299 300/** 301 * Constants for *_getLocale() 302 * Allow user to select whether she wants information on 303 * requested, valid or actual locale. 304 * For example, a collator for "en_US_CALIFORNIA" was 305 * requested. In the current state of ICU (2.0), 306 * the requested locale is "en_US_CALIFORNIA", 307 * the valid locale is "en_US" (most specific locale supported by ICU) 308 * and the actual locale is "root" (the collation data comes unmodified 309 * from the UCA) 310 * The locale is considered supported by ICU if there is a core ICU bundle 311 * for that locale (although it may be empty). 312 * @stable ICU 2.1 313 */ 314typedef enum { 315 /** This is locale the data actually comes from 316 * @stable ICU 2.1 317 */ 318 ULOC_ACTUAL_LOCALE = 0, 319 /** This is the most specific locale supported by ICU 320 * @stable ICU 2.1 321 */ 322 ULOC_VALID_LOCALE = 1, 323 324#ifndef U_HIDE_DEPRECATED_API 325 /** This is the requested locale 326 * @deprecated ICU 2.8 327 */ 328 ULOC_REQUESTED_LOCALE = 2, 329#endif /* U_HIDE_DEPRECATED_API */ 330 331 ULOC_DATA_LOCALE_TYPE_LIMIT = 3 332} ULocDataLocaleType ; 333 334 335/** 336 * Gets ICU's default locale. 337 * The returned string is a snapshot in time, and will remain valid 338 * and unchanged even when uloc_setDefault() is called. 339 * The returned storage is owned by ICU, and must not be altered or deleted 340 * by the caller. 341 * 342 * @return the ICU default locale 343 * @system 344 * @stable ICU 2.0 345 */ 346U_STABLE const char* U_EXPORT2 347uloc_getDefault(void); 348 349/** 350 * Sets ICU's default locale. 351 * By default (without calling this function), ICU's default locale will be based 352 * on information obtained from the underlying system environment. 353 * <p> 354 * Changes to ICU's default locale do not propagate back to the 355 * system environment. 356 * <p> 357 * Changes to ICU's default locale to not affect any ICU services that 358 * may already be open based on the previous default locale value. 359 * 360 * @param localeID the new ICU default locale. A value of NULL will try to get 361 * the system's default locale. 362 * @param status the error information if the setting of default locale fails 363 * @system 364 * @stable ICU 2.0 365 */ 366U_STABLE void U_EXPORT2 367uloc_setDefault(const char* localeID, 368 UErrorCode* status); 369 370/** 371 * Gets the language code for the specified locale. 372 * 373 * @param localeID the locale to get the ISO language code with 374 * @param language the language code for localeID 375 * @param languageCapacity the size of the language buffer to store the 376 * language code with 377 * @param err error information if retrieving the language code failed 378 * @return the actual buffer size needed for the language code. If it's greater 379 * than languageCapacity, the returned language code will be truncated. 380 * @stable ICU 2.0 381 */ 382U_STABLE int32_t U_EXPORT2 383uloc_getLanguage(const char* localeID, 384 char* language, 385 int32_t languageCapacity, 386 UErrorCode* err); 387 388/** 389 * Gets the script code for the specified locale. 390 * 391 * @param localeID the locale to get the ISO language code with 392 * @param script the language code for localeID 393 * @param scriptCapacity the size of the language buffer to store the 394 * language code with 395 * @param err error information if retrieving the language code failed 396 * @return the actual buffer size needed for the language code. If it's greater 397 * than scriptCapacity, the returned language code will be truncated. 398 * @stable ICU 2.8 399 */ 400U_STABLE int32_t U_EXPORT2 401uloc_getScript(const char* localeID, 402 char* script, 403 int32_t scriptCapacity, 404 UErrorCode* err); 405 406/** 407 * Gets the country code for the specified locale. 408 * 409 * @param localeID the locale to get the country code with 410 * @param country the country code for localeID 411 * @param countryCapacity the size of the country buffer to store the 412 * country code with 413 * @param err error information if retrieving the country code failed 414 * @return the actual buffer size needed for the country code. If it's greater 415 * than countryCapacity, the returned country code will be truncated. 416 * @stable ICU 2.0 417 */ 418U_STABLE int32_t U_EXPORT2 419uloc_getCountry(const char* localeID, 420 char* country, 421 int32_t countryCapacity, 422 UErrorCode* err); 423 424/** 425 * Gets the variant code for the specified locale. 426 * 427 * @param localeID the locale to get the variant code with 428 * @param variant the variant code for localeID 429 * @param variantCapacity the size of the variant buffer to store the 430 * variant code with 431 * @param err error information if retrieving the variant code failed 432 * @return the actual buffer size needed for the variant code. If it's greater 433 * than variantCapacity, the returned variant code will be truncated. 434 * @stable ICU 2.0 435 */ 436U_STABLE int32_t U_EXPORT2 437uloc_getVariant(const char* localeID, 438 char* variant, 439 int32_t variantCapacity, 440 UErrorCode* err); 441 442 443/** 444 * Gets the full name for the specified locale. 445 * Note: This has the effect of 'canonicalizing' the ICU locale ID to 446 * a certain extent. Upper and lower case are set as needed. 447 * It does NOT map aliased names in any way. 448 * See the top of this header file. 449 * This API supports preflighting. 450 * 451 * @param localeID the locale to get the full name with 452 * @param name fill in buffer for the name without keywords. 453 * @param nameCapacity capacity of the fill in buffer. 454 * @param err error information if retrieving the full name failed 455 * @return the actual buffer size needed for the full name. If it's greater 456 * than nameCapacity, the returned full name will be truncated. 457 * @stable ICU 2.0 458 */ 459U_STABLE int32_t U_EXPORT2 460uloc_getName(const char* localeID, 461 char* name, 462 int32_t nameCapacity, 463 UErrorCode* err); 464 465/** 466 * Gets the full name for the specified locale. 467 * Note: This has the effect of 'canonicalizing' the string to 468 * a certain extent. Upper and lower case are set as needed, 469 * and if the components were in 'POSIX' format they are changed to 470 * ICU format. It does NOT map aliased names in any way. 471 * See the top of this header file. 472 * 473 * @param localeID the locale to get the full name with 474 * @param name the full name for localeID 475 * @param nameCapacity the size of the name buffer to store the 476 * full name with 477 * @param err error information if retrieving the full name failed 478 * @return the actual buffer size needed for the full name. If it's greater 479 * than nameCapacity, the returned full name will be truncated. 480 * @stable ICU 2.8 481 */ 482U_STABLE int32_t U_EXPORT2 483uloc_canonicalize(const char* localeID, 484 char* name, 485 int32_t nameCapacity, 486 UErrorCode* err); 487 488/** 489 * Gets the ISO language code for the specified locale. 490 * 491 * @param localeID the locale to get the ISO language code with 492 * @return language the ISO language code for localeID 493 * @stable ICU 2.0 494 */ 495U_STABLE const char* U_EXPORT2 496uloc_getISO3Language(const char* localeID); 497 498 499/** 500 * Gets the ISO country code for the specified locale. 501 * 502 * @param localeID the locale to get the ISO country code with 503 * @return country the ISO country code for localeID 504 * @stable ICU 2.0 505 */ 506U_STABLE const char* U_EXPORT2 507uloc_getISO3Country(const char* localeID); 508 509/** 510 * Gets the Win32 LCID value for the specified locale. 511 * If the ICU locale is not recognized by Windows, 0 will be returned. 512 * 513 * @param localeID the locale to get the Win32 LCID value with 514 * @return country the Win32 LCID for localeID 515 * @stable ICU 2.0 516 */ 517U_STABLE uint32_t U_EXPORT2 518uloc_getLCID(const char* localeID); 519 520/** 521 * Gets the language name suitable for display for the specified locale. 522 * 523 * @param locale the locale to get the ISO language code with 524 * @param displayLocale Specifies the locale to be used to display the name. In other words, 525 * if the locale's language code is "en", passing Locale::getFrench() for 526 * inLocale would result in "Anglais", while passing Locale::getGerman() 527 * for inLocale would result in "Englisch". 528 * @param language the displayable language code for localeID 529 * @param languageCapacity the size of the language buffer to store the 530 * displayable language code with 531 * @param status error information if retrieving the displayable language code failed 532 * @return the actual buffer size needed for the displayable language code. If it's greater 533 * than languageCapacity, the returned language code will be truncated. 534 * @stable ICU 2.0 535 */ 536U_STABLE int32_t U_EXPORT2 537uloc_getDisplayLanguage(const char* locale, 538 const char* displayLocale, 539 UChar* language, 540 int32_t languageCapacity, 541 UErrorCode* status); 542 543/** 544 * Gets the script name suitable for display for the specified locale. 545 * 546 * @param locale the locale to get the displayable script code with. NULL may be used to specify the default. 547 * @param displayLocale Specifies the locale to be used to display the name. In other words, 548 * if the locale's language code is "en", passing Locale::getFrench() for 549 * inLocale would result in "", while passing Locale::getGerman() 550 * for inLocale would result in "". NULL may be used to specify the default. 551 * @param script the displayable country code for localeID 552 * @param scriptCapacity the size of the script buffer to store the 553 * displayable script code with 554 * @param status error information if retrieving the displayable script code failed 555 * @return the actual buffer size needed for the displayable script code. If it's greater 556 * than scriptCapacity, the returned displayable script code will be truncated. 557 * @stable ICU 2.8 558 */ 559U_STABLE int32_t U_EXPORT2 560uloc_getDisplayScript(const char* locale, 561 const char* displayLocale, 562 UChar* script, 563 int32_t scriptCapacity, 564 UErrorCode* status); 565 566/** 567 * Gets the country name suitable for display for the specified locale. 568 * 569 * @param locale the locale to get the displayable country code with. NULL may be used to specify the default. 570 * @param displayLocale Specifies the locale to be used to display the name. In other words, 571 * if the locale's language code is "en", passing Locale::getFrench() for 572 * inLocale would result in "Anglais", while passing Locale::getGerman() 573 * for inLocale would result in "Englisch". NULL may be used to specify the default. 574 * @param country the displayable country code for localeID 575 * @param countryCapacity the size of the country buffer to store the 576 * displayable country code with 577 * @param status error information if retrieving the displayable country code failed 578 * @return the actual buffer size needed for the displayable country code. If it's greater 579 * than countryCapacity, the returned displayable country code will be truncated. 580 * @stable ICU 2.0 581 */ 582U_STABLE int32_t U_EXPORT2 583uloc_getDisplayCountry(const char* locale, 584 const char* displayLocale, 585 UChar* country, 586 int32_t countryCapacity, 587 UErrorCode* status); 588 589 590/** 591 * Gets the variant name suitable for display for the specified locale. 592 * 593 * @param locale the locale to get the displayable variant code with. NULL may be used to specify the default. 594 * @param displayLocale Specifies the locale to be used to display the name. In other words, 595 * if the locale's language code is "en", passing Locale::getFrench() for 596 * inLocale would result in "Anglais", while passing Locale::getGerman() 597 * for inLocale would result in "Englisch". NULL may be used to specify the default. 598 * @param variant the displayable variant code for localeID 599 * @param variantCapacity the size of the variant buffer to store the 600 * displayable variant code with 601 * @param status error information if retrieving the displayable variant code failed 602 * @return the actual buffer size needed for the displayable variant code. If it's greater 603 * than variantCapacity, the returned displayable variant code will be truncated. 604 * @stable ICU 2.0 605 */ 606U_STABLE int32_t U_EXPORT2 607uloc_getDisplayVariant(const char* locale, 608 const char* displayLocale, 609 UChar* variant, 610 int32_t variantCapacity, 611 UErrorCode* status); 612 613/** 614 * Gets the keyword name suitable for display for the specified locale. 615 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display 616 * string for the keyword collation. 617 * Usage: 618 * <code> 619 * UErrorCode status = U_ZERO_ERROR; 620 * const char* keyword =NULL; 621 * int32_t keywordLen = 0; 622 * int32_t keywordCount = 0; 623 * UChar displayKeyword[256]; 624 * int32_t displayKeywordLen = 0; 625 * UEnumeration* keywordEnum = uloc_openKeywords("de_DE@collation=PHONEBOOK;calendar=TRADITIONAL", &status); 626 * for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){ 627 * if(U_FAILURE(status)){ 628 * ...something went wrong so handle the error... 629 * break; 630 * } 631 * // the uenum_next returns NUL terminated string 632 * keyword = uenum_next(keywordEnum, &keywordLen, &status); 633 * displayKeywordLen = uloc_getDisplayKeyword(keyword, "en_US", displayKeyword, 256); 634 * ... do something interesting ..... 635 * } 636 * uenum_close(keywordEnum); 637 * </code> 638 * @param keyword The keyword whose display string needs to be returned. 639 * @param displayLocale Specifies the locale to be used to display the name. In other words, 640 * if the locale's language code is "en", passing Locale::getFrench() for 641 * inLocale would result in "Anglais", while passing Locale::getGerman() 642 * for inLocale would result in "Englisch". NULL may be used to specify the default. 643 * @param dest the buffer to which the displayable keyword should be written. 644 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 645 * dest may be NULL and the function will only return the length of the 646 * result without writing any of the result string (pre-flighting). 647 * @param status error information if retrieving the displayable string failed. 648 * Should not be NULL and should not indicate failure on entry. 649 * @return the actual buffer size needed for the displayable variant code. 650 * @see #uloc_openKeywords 651 * @stable ICU 2.8 652 */ 653U_STABLE int32_t U_EXPORT2 654uloc_getDisplayKeyword(const char* keyword, 655 const char* displayLocale, 656 UChar* dest, 657 int32_t destCapacity, 658 UErrorCode* status); 659/** 660 * Gets the value of the keyword suitable for display for the specified locale. 661 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display 662 * string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword. 663 * 664 * @param locale The locale to get the displayable variant code with. NULL may be used to specify the default. 665 * @param keyword The keyword for whose value should be used. 666 * @param displayLocale Specifies the locale to be used to display the name. In other words, 667 * if the locale's language code is "en", passing Locale::getFrench() for 668 * inLocale would result in "Anglais", while passing Locale::getGerman() 669 * for inLocale would result in "Englisch". NULL may be used to specify the default. 670 * @param dest the buffer to which the displayable keyword should be written. 671 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 672 * dest may be NULL and the function will only return the length of the 673 * result without writing any of the result string (pre-flighting). 674 * @param status error information if retrieving the displayable string failed. 675 * Should not be NULL and must not indicate failure on entry. 676 * @return the actual buffer size needed for the displayable variant code. 677 * @stable ICU 2.8 678 */ 679U_STABLE int32_t U_EXPORT2 680uloc_getDisplayKeywordValue( const char* locale, 681 const char* keyword, 682 const char* displayLocale, 683 UChar* dest, 684 int32_t destCapacity, 685 UErrorCode* status); 686/** 687 * Gets the full name suitable for display for the specified locale. 688 * 689 * @param localeID the locale to get the displayable name with. NULL may be used to specify the default. 690 * @param inLocaleID Specifies the locale to be used to display the name. In other words, 691 * if the locale's language code is "en", passing Locale::getFrench() for 692 * inLocale would result in "Anglais", while passing Locale::getGerman() 693 * for inLocale would result in "Englisch". NULL may be used to specify the default. 694 * @param result the displayable name for localeID 695 * @param maxResultSize the size of the name buffer to store the 696 * displayable full name with 697 * @param err error information if retrieving the displayable name failed 698 * @return the actual buffer size needed for the displayable name. If it's greater 699 * than maxResultSize, the returned displayable name will be truncated. 700 * @stable ICU 2.0 701 */ 702U_STABLE int32_t U_EXPORT2 703uloc_getDisplayName(const char* localeID, 704 const char* inLocaleID, 705 UChar* result, 706 int32_t maxResultSize, 707 UErrorCode* err); 708 709 710/** 711 * Gets the specified locale from a list of all available locales. 712 * The return value is a pointer to an item of 713 * a locale name array. Both this array and the pointers 714 * it contains are owned by ICU and should not be deleted or written through 715 * by the caller. The locale name is terminated by a null pointer. 716 * @param n the specific locale name index of the available locale list 717 * @return a specified locale name of all available locales 718 * @stable ICU 2.0 719 */ 720U_STABLE const char* U_EXPORT2 721uloc_getAvailable(int32_t n); 722 723/** 724 * Gets the size of the all available locale list. 725 * 726 * @return the size of the locale list 727 * @stable ICU 2.0 728 */ 729U_STABLE int32_t U_EXPORT2 uloc_countAvailable(void); 730 731/** 732 * 733 * Gets a list of all available language codes defined in ISO 639. This is a pointer 734 * to an array of pointers to arrays of char. All of these pointers are owned 735 * by ICU-- do not delete them, and do not write through them. The array is 736 * terminated with a null pointer. 737 * @return a list of all available language codes 738 * @stable ICU 2.0 739 */ 740U_STABLE const char* const* U_EXPORT2 741uloc_getISOLanguages(void); 742 743/** 744 * 745 * Gets a list of all available 2-letter country codes defined in ISO 639. This is a 746 * pointer to an array of pointers to arrays of char. All of these pointers are 747 * owned by ICU-- do not delete them, and do not write through them. The array is 748 * terminated with a null pointer. 749 * @return a list of all available country codes 750 * @stable ICU 2.0 751 */ 752U_STABLE const char* const* U_EXPORT2 753uloc_getISOCountries(void); 754 755/** 756 * Truncate the locale ID string to get the parent locale ID. 757 * Copies the part of the string before the last underscore. 758 * The parent locale ID will be an empty string if there is no 759 * underscore, or if there is only one underscore at localeID[0]. 760 * 761 * @param localeID Input locale ID string. 762 * @param parent Output string buffer for the parent locale ID. 763 * @param parentCapacity Size of the output buffer. 764 * @param err A UErrorCode value. 765 * @return The length of the parent locale ID. 766 * @stable ICU 2.0 767 */ 768U_STABLE int32_t U_EXPORT2 769uloc_getParent(const char* localeID, 770 char* parent, 771 int32_t parentCapacity, 772 UErrorCode* err); 773 774 775 776 777/** 778 * Gets the full name for the specified locale. 779 * Note: This has the effect of 'canonicalizing' the string to 780 * a certain extent. Upper and lower case are set as needed, 781 * and if the components were in 'POSIX' format they are changed to 782 * ICU format. It does NOT map aliased names in any way. 783 * See the top of this header file. 784 * This API strips off the keyword part, so "de_DE\@collation=phonebook" 785 * will become "de_DE". 786 * This API supports preflighting. 787 * 788 * @param localeID the locale to get the full name with 789 * @param name fill in buffer for the name without keywords. 790 * @param nameCapacity capacity of the fill in buffer. 791 * @param err error information if retrieving the full name failed 792 * @return the actual buffer size needed for the full name. If it's greater 793 * than nameCapacity, the returned full name will be truncated. 794 * @stable ICU 2.8 795 */ 796U_STABLE int32_t U_EXPORT2 797uloc_getBaseName(const char* localeID, 798 char* name, 799 int32_t nameCapacity, 800 UErrorCode* err); 801 802/** 803 * Gets an enumeration of keywords for the specified locale. Enumeration 804 * must get disposed of by the client using uenum_close function. 805 * 806 * @param localeID the locale to get the variant code with 807 * @param status error information if retrieving the keywords failed 808 * @return enumeration of keywords or NULL if there are no keywords. 809 * @stable ICU 2.8 810 */ 811U_STABLE UEnumeration* U_EXPORT2 812uloc_openKeywords(const char* localeID, 813 UErrorCode* status); 814 815/** 816 * Get the value for a keyword. Locale name does not need to be normalized. 817 * 818 * @param localeID locale name containing the keyword ("de_DE@currency=EURO;collation=PHONEBOOK") 819 * @param keywordName name of the keyword for which we want the value. Case insensitive. 820 * @param buffer receiving buffer 821 * @param bufferCapacity capacity of receiving buffer 822 * @param status containing error code - buffer not big enough. 823 * @return the length of keyword value 824 * @stable ICU 2.8 825 */ 826U_STABLE int32_t U_EXPORT2 827uloc_getKeywordValue(const char* localeID, 828 const char* keywordName, 829 char* buffer, int32_t bufferCapacity, 830 UErrorCode* status); 831 832 833/** 834 * Set the value of the specified keyword. 835 * NOTE: Unlike almost every other ICU function which takes a 836 * buffer, this function will NOT truncate the output text. If a 837 * BUFFER_OVERFLOW_ERROR is received, it means that the original 838 * buffer is untouched. This is done to prevent incorrect or possibly 839 * even malformed locales from being generated and used. 840 * 841 * @param keywordName name of the keyword to be set. Case insensitive. 842 * @param keywordValue value of the keyword to be set. If 0-length or 843 * NULL, will result in the keyword being removed. No error is given if 844 * that keyword does not exist. 845 * @param buffer input buffer containing locale to be modified. 846 * @param bufferCapacity capacity of receiving buffer 847 * @param status containing error code - buffer not big enough. 848 * @return the length needed for the buffer 849 * @see uloc_getKeywordValue 850 * @stable ICU 3.2 851 */ 852U_STABLE int32_t U_EXPORT2 853uloc_setKeywordValue(const char* keywordName, 854 const char* keywordValue, 855 char* buffer, int32_t bufferCapacity, 856 UErrorCode* status); 857 858/** 859 * enums for the return value for the character and line orientation 860 * functions. 861 * @stable ICU 4.0 862 */ 863typedef enum { 864 ULOC_LAYOUT_LTR = 0, /* left-to-right. */ 865 ULOC_LAYOUT_RTL = 1, /* right-to-left. */ 866 ULOC_LAYOUT_TTB = 2, /* top-to-bottom. */ 867 ULOC_LAYOUT_BTT = 3, /* bottom-to-top. */ 868 ULOC_LAYOUT_UNKNOWN 869} ULayoutType; 870 871/** 872 * Get the layout character orientation for the specified locale. 873 * 874 * @param localeId locale name 875 * @param status Error status 876 * @return an enum indicating the layout orientation for characters. 877 * @stable ICU 4.0 878 */ 879U_DRAFT ULayoutType U_EXPORT2 880uloc_getCharacterOrientation(const char* localeId, 881 UErrorCode *status); 882 883/** 884 * Get the layout line orientation for the specified locale. 885 * 886 * @param localeId locale name 887 * @param status Error status 888 * @return an enum indicating the layout orientation for lines. 889 * @stable ICU 4.0 890 */ 891U_DRAFT ULayoutType U_EXPORT2 892uloc_getLineOrientation(const char* localeId, 893 UErrorCode *status); 894 895/** 896 * enums for the 'outResult' parameter return value 897 * @see uloc_acceptLanguageFromHTTP 898 * @see uloc_acceptLanguage 899 * @stable ICU 3.2 900 */ 901typedef enum { 902 ULOC_ACCEPT_FAILED = 0, /* No exact match was found. */ 903 ULOC_ACCEPT_VALID = 1, /* An exact match was found. */ 904 ULOC_ACCEPT_FALLBACK = 2 /* A fallback was found, for example, 905 Accept list contained 'ja_JP' 906 which matched available locale 'ja'. */ 907} UAcceptResult; 908 909 910/** 911 * Based on a HTTP header from a web browser and a list of available locales, 912 * determine an acceptable locale for the user. 913 * @param result - buffer to accept the result locale 914 * @param resultAvailable the size of the result buffer. 915 * @param outResult - An out parameter that contains the fallback status 916 * @param httpAcceptLanguage - "Accept-Language:" header as per HTTP. 917 * @param availableLocales - list of available locales to match 918 * @param status Error status, may be BUFFER_OVERFLOW_ERROR 919 * @return length needed for the locale. 920 * @stable ICU 3.2 921 */ 922U_STABLE int32_t U_EXPORT2 923uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable, 924 UAcceptResult *outResult, 925 const char *httpAcceptLanguage, 926 UEnumeration* availableLocales, 927 UErrorCode *status); 928 929/** 930 * Based on a list of available locales, 931 * determine an acceptable locale for the user. 932 * @param result - buffer to accept the result locale 933 * @param resultAvailable the size of the result buffer. 934 * @param outResult - An out parameter that contains the fallback status 935 * @param acceptList - list of acceptable languages 936 * @param acceptListCount - count of acceptList items 937 * @param availableLocales - list of available locales to match 938 * @param status Error status, may be BUFFER_OVERFLOW_ERROR 939 * @return length needed for the locale. 940 * @stable ICU 3.2 941 */ 942U_STABLE int32_t U_EXPORT2 943uloc_acceptLanguage(char *result, int32_t resultAvailable, 944 UAcceptResult *outResult, const char **acceptList, 945 int32_t acceptListCount, 946 UEnumeration* availableLocales, 947 UErrorCode *status); 948 949 950/** 951 * Gets the ICU locale ID for the specified Win32 LCID value. 952 * 953 * @param hostID the Win32 LCID to translate 954 * @param locale the output buffer for the ICU locale ID, which will be NUL-terminated 955 * if there is room. 956 * @param localeCapacity the size of the output buffer 957 * @param status an error is returned if the LCID is unrecognized or the output buffer 958 * is too small 959 * @return actual the actual size of the locale ID, not including NUL-termination 960 * @stable ICU 3.8 961 */ 962U_DRAFT int32_t U_EXPORT2 963uloc_getLocaleForLCID(uint32_t hostID, char *locale, int32_t localeCapacity, 964 UErrorCode *status); 965 966 967/** 968 * Add the likely subtags for a provided locale ID, per the algorithm described 969 * in the following CLDR technical report: 970 * 971 * http://www.unicode.org/reports/tr35/#Likely_Subtags 972 * 973 * If localeID is already in the maximal form, or there is no data available 974 * for maximization, it will be copied to the output buffer. For example, 975 * "und-Zzzz" cannot be maximized, since there is no reasonable maximization. 976 * 977 * Examples: 978 * 979 * "en" maximizes to "en_Latn_US" 980 * 981 * "de" maximizes to "de_Latn_US" 982 * 983 * "sr" maximizes to "sr_Cyrl_RS" 984 * 985 * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.) 986 * 987 * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.) 988 * 989 * @param localeID The locale to maximize 990 * @param maximizedLocaleID The maximized locale 991 * @param maximizedLocaleIDCapacity The capacity of the maximizedLocaleID buffer 992 * @param err Error information if maximizing the locale failed. If the length 993 * of the localeID and the null-terminator is greater than the maximum allowed size, 994 * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR. 995 * @return The actual buffer size needed for the maximized locale. If it's 996 * greater than maximizedLocaleIDCapacity, the returned ID will be truncated. 997 * On error, the return value is -1. 998 * @stable ICU 4.0 999 */ 1000U_DRAFT int32_t U_EXPORT2 1001uloc_addLikelySubtags(const char* localeID, 1002 char* maximizedLocaleID, 1003 int32_t maximizedLocaleIDCapacity, 1004 UErrorCode* err); 1005 1006 1007/** 1008 * Minimize the subtags for a provided locale ID, per the algorithm described 1009 * in the following CLDR technical report: 1010 * 1011 * http://www.unicode.org/reports/tr35/#Likely_Subtags 1012 * 1013 * If localeID is already in the minimal form, or there is no data available 1014 * for minimization, it will be copied to the output buffer. Since the 1015 * minimization algorithm relies on proper maximization, see the comments 1016 * for uloc_addLikelySubtags for reasons why there might not be any data. 1017 * 1018 * Examples: 1019 * 1020 * "en_Latn_US" minimizes to "en" 1021 * 1022 * "de_Latn_US" minimizes to "de" 1023 * 1024 * "sr_Cyrl_RS" minimizes to "sr" 1025 * 1026 * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the 1027 * script, and minimizing to "zh" would imply "zh_Hans_CN".) 1028 * 1029 * @param localeID The locale to minimize 1030 * @param minimizedLocaleID The minimized locale 1031 * @param minimizedLocaleIDCapacity The capacity of the minimizedLocaleID buffer 1032 * @param err Error information if minimizing the locale failed. If the length 1033 * of the localeID and the null-terminator is greater than the maximum allowed size, 1034 * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR. 1035 * @return The actual buffer size needed for the minimized locale. If it's 1036 * greater than minimizedLocaleIDCapacity, the returned ID will be truncated. 1037 * On error, the return value is -1. 1038 * @stable ICU 4.0 1039 */ 1040U_DRAFT int32_t U_EXPORT2 1041uloc_minimizeSubtags(const char* localeID, 1042 char* minimizedLocaleID, 1043 int32_t minimizedLocaleIDCapacity, 1044 UErrorCode* err); 1045 1046/** 1047 * Returns a locale ID for the specified BCP47 language tag string. 1048 * If the specified language tag contains any ill-formed subtags, 1049 * the first such subtag and all following subtags are ignored. 1050 * <p> 1051 * This implements the 'Language-Tag' production of BCP47, and so 1052 * supports grandfathered (regular and irregular) as well as private 1053 * use language tags. Private use tags are represented as 'x-whatever', 1054 * and grandfathered tags are converted to their canonical replacements 1055 * where they exist. Note that a few grandfathered tags have no modern 1056 * replacement, these will be converted using the fallback described in 1057 * the first paragraph, so some information might be lost. 1058 * @param langtag the input BCP47 language tag. 1059 * @param localeID the output buffer receiving a locale ID for the 1060 * specified BCP47 language tag. 1061 * @param localeIDCapacity the size of the locale ID output buffer. 1062 * @param parsedLength if not NULL, succsessfully parsed length 1063 * for the input language tag is set. 1064 * @param err error information if receiving the locald ID 1065 * failed. 1066 * @return the length of the locale ID. 1067 * @draft ICU 4.2 1068 */ 1069U_DRAFT int32_t U_EXPORT2 1070uloc_forLanguageTag(const char* langtag, 1071 char* localeID, 1072 int32_t localeIDCapacity, 1073 int32_t* parsedLength, 1074 UErrorCode* err); 1075 1076/** 1077 * Returns a well-formed language tag for this locale ID. 1078 * <p> 1079 * <b>Note</b>: When <code>strict</code> is FALSE, any locale 1080 * fields which do not satisfy the BCP47 syntax requirement will 1081 * be omitted from the result. When <code>strict</code> is 1082 * TRUE, this function sets U_ILLEGAL_ARGUMENT_ERROR to the 1083 * <code>err</code> if any locale fields do not satisfy the 1084 * BCP47 syntax requirement. 1085 * @param localeID the input lcoale ID 1086 * @param langtag the output buffer receiving BCP47 language 1087 * tag for the locale ID. 1088 * @param langtagCapacity the size of the BCP47 language tag 1089 * output buffer. 1090 * @param strict boolean value indicating if the function returns 1091 * an error for an ill-formed input locale ID. 1092 * @param err error information if receiving the language 1093 * tag failed. 1094 * @return The length of the BCP47 language tag. 1095 * @draft ICU 4.2 1096 */ 1097U_DRAFT int32_t U_EXPORT2 1098uloc_toLanguageTag(const char* localeID, 1099 char* langtag, 1100 int32_t langtagCapacity, 1101 UBool strict, 1102 UErrorCode* err); 1103 1104#endif /*_ULOC*/ 1105