|
|
|||
File indexing completed on 2026-01-10 10:29:15
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ********************************************************************** 0005 * Copyright (C) 1997-2016, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ********************************************************************** 0008 * 0009 * File ULOC.H 0010 * 0011 * Modification History: 0012 * 0013 * Date Name Description 0014 * 04/01/97 aliu Creation. 0015 * 08/22/98 stephen JDK 1.2 sync. 0016 * 12/08/98 rtg New C API for Locale 0017 * 03/30/99 damiba overhaul 0018 * 03/31/99 helena Javadoc for uloc functions. 0019 * 04/15/99 Madhu Updated Javadoc 0020 ******************************************************************************** 0021 */ 0022 0023 #ifndef ULOC_H 0024 #define ULOC_H 0025 0026 #include "unicode/utypes.h" 0027 #include "unicode/uenum.h" 0028 0029 /** 0030 * \file 0031 * \brief C API: Locale ID functionality similar to C++ class Locale 0032 * 0033 * <h2> ULoc C API for Locale </h2> 0034 * A <code>Locale</code> represents a specific geographical, political, 0035 * or cultural region. An operation that requires a <code>Locale</code> to perform 0036 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code> 0037 * to tailor information for the user. For example, displaying a number 0038 * is a locale-sensitive operation--the number should be formatted 0039 * according to the customs/conventions of the user's native country, 0040 * region, or culture. In the C APIs, a locales is simply a const char string. 0041 * 0042 * <P> 0043 * You create a <code>Locale</code> with one of the three options listed below. 0044 * Each of the component is separated by '_' in the locale string. 0045 * \htmlonly<blockquote>\endhtmlonly 0046 * <pre> 0047 * \code 0048 * newLanguage 0049 * 0050 * newLanguage + newCountry 0051 * 0052 * newLanguage + newCountry + newVariant 0053 * \endcode 0054 * </pre> 0055 * \htmlonly</blockquote>\endhtmlonly 0056 * The first option is a valid <STRONG>ISO 0057 * Language Code.</STRONG> These codes are the lower-case two-letter 0058 * codes as defined by ISO-639. 0059 * You can find a full list of these codes at a number of sites, such as: 0060 * <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt"> 0061 * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</a> 0062 * 0063 * <P> 0064 * The second option includes an additional <STRONG>ISO Country 0065 * Code.</STRONG> These codes are the upper-case two-letter codes 0066 * as defined by ISO-3166. 0067 * You can find a full list of these codes at a number of sites, such as: 0068 * <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html"> 0069 * http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</a> 0070 * 0071 * <P> 0072 * The third option requires another additional information--the 0073 * <STRONG>Variant.</STRONG> 0074 * The Variant codes are vendor and browser-specific. 0075 * For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. 0076 * Where there are two variants, separate them with an underscore, and 0077 * put the most important one first. For 0078 * example, a Traditional Spanish collation might be referenced, with 0079 * "ES", "ES", "Traditional_WIN". 0080 * 0081 * <P> 0082 * Because a <code>Locale</code> is just an identifier for a region, 0083 * no validity check is performed when you specify a <code>Locale</code>. 0084 * If you want to see whether particular resources are available for the 0085 * <code>Locale</code> you asked for, you must query those resources. For 0086 * example, ask the <code>UNumberFormat</code> for the locales it supports 0087 * using its <code>getAvailable</code> method. 0088 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular 0089 * locale, you get back the best available match, not necessarily 0090 * precisely what you asked for. For more information, look at 0091 * <code>UResourceBundle</code>. 0092 * 0093 * <P> 0094 * The <code>Locale</code> provides a number of convenient constants 0095 * that you can use to specify the commonly used 0096 * locales. For example, the following refers to a locale 0097 * for the United States: 0098 * \htmlonly<blockquote>\endhtmlonly 0099 * <pre> 0100 * \code 0101 * ULOC_US 0102 * \endcode 0103 * </pre> 0104 * \htmlonly</blockquote>\endhtmlonly 0105 * 0106 * <P> 0107 * Once you've specified a locale you can query it for information about 0108 * itself. Use <code>uloc_getCountry</code> to get the ISO Country Code and 0109 * <code>uloc_getLanguage</code> to get the ISO Language Code. You can 0110 * use <code>uloc_getDisplayCountry</code> to get the 0111 * name of the country suitable for displaying to the user. Similarly, 0112 * you can use <code>uloc_getDisplayLanguage</code> to get the name of 0113 * the language suitable for displaying to the user. Interestingly, 0114 * the <code>uloc_getDisplayXXX</code> methods are themselves locale-sensitive 0115 * and have two versions: one that uses the default locale and one 0116 * that takes a locale as an argument and displays the name or country in 0117 * a language appropriate to that locale. 0118 * 0119 * <P> 0120 * The ICU provides a number of services that perform locale-sensitive 0121 * operations. For example, the <code>unum_xxx</code> functions format 0122 * numbers, currency, or percentages in a locale-sensitive manner. 0123 * </P> 0124 * \htmlonly<blockquote>\endhtmlonly 0125 * <pre> 0126 * \code 0127 * UErrorCode success = U_ZERO_ERROR; 0128 * UNumberFormat *nf; 0129 * const char* myLocale = "fr_FR"; 0130 * 0131 * nf = unum_open( UNUM_DEFAULT, NULL, success ); 0132 * unum_close(nf); 0133 * nf = unum_open( UNUM_CURRENCY, NULL, success ); 0134 * unum_close(nf); 0135 * nf = unum_open( UNUM_PERCENT, NULL, success ); 0136 * unum_close(nf); 0137 * \endcode 0138 * </pre> 0139 * \htmlonly</blockquote>\endhtmlonly 0140 * Each of these methods has two variants; one with an explicit locale 0141 * and one without; the latter using the default locale. 0142 * \htmlonly<blockquote>\endhtmlonly 0143 * <pre> 0144 * \code 0145 * 0146 * nf = unum_open( UNUM_DEFAULT, myLocale, success ); 0147 * unum_close(nf); 0148 * nf = unum_open( UNUM_CURRENCY, myLocale, success ); 0149 * unum_close(nf); 0150 * nf = unum_open( UNUM_PERCENT, myLocale, success ); 0151 * unum_close(nf); 0152 * \endcode 0153 * </pre> 0154 * \htmlonly</blockquote>\endhtmlonly 0155 * A <code>Locale</code> is the mechanism for identifying the kind of services 0156 * (<code>UNumberFormat</code>) that you would like to get. The locale is 0157 * <STRONG>just</STRONG> a mechanism for identifying these services. 0158 * 0159 * <P> 0160 * Each international service that performs locale-sensitive operations 0161 * allows you 0162 * to get all the available objects of that type. You can sift 0163 * through these objects by language, country, or variant, 0164 * and use the display names to present a menu to the user. 0165 * For example, you can create a menu of all the collation objects 0166 * suitable for a given language. Such classes implement these 0167 * three class methods: 0168 * \htmlonly<blockquote>\endhtmlonly 0169 * <pre> 0170 * \code 0171 * const char* uloc_getAvailable(int32_t index); 0172 * int32_t uloc_countAvailable(); 0173 * int32_t 0174 * uloc_getDisplayName(const char* localeID, 0175 * const char* inLocaleID, 0176 * UChar* result, 0177 * int32_t maxResultSize, 0178 * UErrorCode* err); 0179 * 0180 * \endcode 0181 * </pre> 0182 * \htmlonly</blockquote>\endhtmlonly 0183 * <P> 0184 * Concerning POSIX/RFC1766 Locale IDs, 0185 * the getLanguage/getCountry/getVariant/getName functions do understand 0186 * the POSIX type form of language_COUNTRY.ENCODING\@VARIANT 0187 * and if there is not an ICU-stype variant, uloc_getVariant() for example 0188 * will return the one listed after the \@at sign. As well, the hyphen 0189 * "-" is recognized as a country/variant separator similarly to RFC1766. 0190 * So for example, "en-us" will be interpreted as en_US. 0191 * As a result, uloc_getName() is far from a no-op, and will have the 0192 * effect of converting POSIX/RFC1766 IDs into ICU form, although it does 0193 * NOT map any of the actual codes (i.e. russian->ru) in any way. 0194 * Applications should call uloc_getName() at the point where a locale ID 0195 * is coming from an external source (user entry, OS, web browser) 0196 * and pass the resulting string to other ICU functions. For example, 0197 * don't use de-de\@EURO as an argument to resourcebundle. 0198 * 0199 * @see UResourceBundle 0200 */ 0201 0202 /** Useful constant for this language. @stable ICU 2.0 */ 0203 #define ULOC_CHINESE "zh" 0204 /** Useful constant for this language. @stable ICU 2.0 */ 0205 #define ULOC_ENGLISH "en" 0206 /** Useful constant for this language. @stable ICU 2.0 */ 0207 #define ULOC_FRENCH "fr" 0208 /** Useful constant for this language. @stable ICU 2.0 */ 0209 #define ULOC_GERMAN "de" 0210 /** Useful constant for this language. @stable ICU 2.0 */ 0211 #define ULOC_ITALIAN "it" 0212 /** Useful constant for this language. @stable ICU 2.0 */ 0213 #define ULOC_JAPANESE "ja" 0214 /** Useful constant for this language. @stable ICU 2.0 */ 0215 #define ULOC_KOREAN "ko" 0216 /** Useful constant for this language. @stable ICU 2.0 */ 0217 #define ULOC_SIMPLIFIED_CHINESE "zh_CN" 0218 /** Useful constant for this language. @stable ICU 2.0 */ 0219 #define ULOC_TRADITIONAL_CHINESE "zh_TW" 0220 0221 /** Useful constant for this country/region. @stable ICU 2.0 */ 0222 #define ULOC_CANADA "en_CA" 0223 /** Useful constant for this country/region. @stable ICU 2.0 */ 0224 #define ULOC_CANADA_FRENCH "fr_CA" 0225 /** Useful constant for this country/region. @stable ICU 2.0 */ 0226 #define ULOC_CHINA "zh_CN" 0227 /** Useful constant for this country/region. @stable ICU 2.0 */ 0228 #define ULOC_PRC "zh_CN" 0229 /** Useful constant for this country/region. @stable ICU 2.0 */ 0230 #define ULOC_FRANCE "fr_FR" 0231 /** Useful constant for this country/region. @stable ICU 2.0 */ 0232 #define ULOC_GERMANY "de_DE" 0233 /** Useful constant for this country/region. @stable ICU 2.0 */ 0234 #define ULOC_ITALY "it_IT" 0235 /** Useful constant for this country/region. @stable ICU 2.0 */ 0236 #define ULOC_JAPAN "ja_JP" 0237 /** Useful constant for this country/region. @stable ICU 2.0 */ 0238 #define ULOC_KOREA "ko_KR" 0239 /** Useful constant for this country/region. @stable ICU 2.0 */ 0240 #define ULOC_TAIWAN "zh_TW" 0241 /** Useful constant for this country/region. @stable ICU 2.0 */ 0242 #define ULOC_UK "en_GB" 0243 /** Useful constant for this country/region. @stable ICU 2.0 */ 0244 #define ULOC_US "en_US" 0245 0246 /** 0247 * Useful constant for the maximum size of the language part of a locale ID. 0248 * (including the terminating NULL). 0249 * @stable ICU 2.0 0250 */ 0251 #define ULOC_LANG_CAPACITY 12 0252 0253 /** 0254 * Useful constant for the maximum size of the country part of a locale ID 0255 * (including the terminating NULL). 0256 * @stable ICU 2.0 0257 */ 0258 #define ULOC_COUNTRY_CAPACITY 4 0259 /** 0260 * Useful constant for the maximum size of the whole locale ID 0261 * (including the terminating NULL and all keywords). 0262 * @stable ICU 2.0 0263 */ 0264 #define ULOC_FULLNAME_CAPACITY 157 0265 0266 /** 0267 * Useful constant for the maximum size of the script part of a locale ID 0268 * (including the terminating NULL). 0269 * @stable ICU 2.8 0270 */ 0271 #define ULOC_SCRIPT_CAPACITY 6 0272 0273 /** 0274 * Useful constant for the maximum size of keywords in a locale 0275 * @stable ICU 2.8 0276 */ 0277 #define ULOC_KEYWORDS_CAPACITY 96 0278 0279 /** 0280 * Useful constant for the maximum total size of keywords and their values in a locale 0281 * @stable ICU 2.8 0282 */ 0283 #define ULOC_KEYWORD_AND_VALUES_CAPACITY 100 0284 0285 /** 0286 * Invariant character separating keywords from the locale string 0287 * @stable ICU 2.8 0288 */ 0289 #define ULOC_KEYWORD_SEPARATOR '@' 0290 0291 /** 0292 * Unicode code point for '@' separating keywords from the locale string. 0293 * @see ULOC_KEYWORD_SEPARATOR 0294 * @stable ICU 4.6 0295 */ 0296 #define ULOC_KEYWORD_SEPARATOR_UNICODE 0x40 0297 0298 /** 0299 * Invariant character for assigning value to a keyword 0300 * @stable ICU 2.8 0301 */ 0302 #define ULOC_KEYWORD_ASSIGN '=' 0303 0304 /** 0305 * Unicode code point for '=' for assigning value to a keyword. 0306 * @see ULOC_KEYWORD_ASSIGN 0307 * @stable ICU 4.6 0308 */ 0309 #define ULOC_KEYWORD_ASSIGN_UNICODE 0x3D 0310 0311 /** 0312 * Invariant character separating keywords 0313 * @stable ICU 2.8 0314 */ 0315 #define ULOC_KEYWORD_ITEM_SEPARATOR ';' 0316 0317 /** 0318 * Unicode code point for ';' separating keywords 0319 * @see ULOC_KEYWORD_ITEM_SEPARATOR 0320 * @stable ICU 4.6 0321 */ 0322 #define ULOC_KEYWORD_ITEM_SEPARATOR_UNICODE 0x3B 0323 0324 /** 0325 * Constants for *_getLocale() 0326 * Allow user to select whether she wants information on 0327 * requested, valid or actual locale. 0328 * For example, a collator for "en_US_CALIFORNIA" was 0329 * requested. In the current state of ICU (2.0), 0330 * the requested locale is "en_US_CALIFORNIA", 0331 * the valid locale is "en_US" (most specific locale supported by ICU) 0332 * and the actual locale is "root" (the collation data comes unmodified 0333 * from the UCA) 0334 * The locale is considered supported by ICU if there is a core ICU bundle 0335 * for that locale (although it may be empty). 0336 * @stable ICU 2.1 0337 */ 0338 typedef enum { 0339 /** This is locale the data actually comes from 0340 * @stable ICU 2.1 0341 */ 0342 ULOC_ACTUAL_LOCALE = 0, 0343 /** This is the most specific locale supported by ICU 0344 * @stable ICU 2.1 0345 */ 0346 ULOC_VALID_LOCALE = 1, 0347 0348 #ifndef U_HIDE_DEPRECATED_API 0349 /** This is the requested locale 0350 * @deprecated ICU 2.8 0351 */ 0352 ULOC_REQUESTED_LOCALE = 2, 0353 0354 /** 0355 * One more than the highest normal ULocDataLocaleType value. 0356 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0357 */ 0358 ULOC_DATA_LOCALE_TYPE_LIMIT = 3 0359 #endif // U_HIDE_DEPRECATED_API 0360 } ULocDataLocaleType; 0361 0362 #ifndef U_HIDE_SYSTEM_API 0363 /** 0364 * Gets ICU's default locale. 0365 * The returned string is a snapshot in time, and will remain valid 0366 * and unchanged even when uloc_setDefault() is called. 0367 * The returned storage is owned by ICU, and must not be altered or deleted 0368 * by the caller. 0369 * 0370 * @return the ICU default locale 0371 * @system 0372 * @stable ICU 2.0 0373 */ 0374 U_CAPI const char* U_EXPORT2 0375 uloc_getDefault(void); 0376 0377 /** 0378 * Sets ICU's default locale. 0379 * By default (without calling this function), ICU's default locale will be based 0380 * on information obtained from the underlying system environment. 0381 * <p> 0382 * Changes to ICU's default locale do not propagate back to the 0383 * system environment. 0384 * <p> 0385 * Changes to ICU's default locale to not affect any ICU services that 0386 * may already be open based on the previous default locale value. 0387 * 0388 * @param localeID the new ICU default locale. A value of NULL will try to get 0389 * the system's default locale. 0390 * @param status the error information if the setting of default locale fails 0391 * @system 0392 * @stable ICU 2.0 0393 */ 0394 U_CAPI void U_EXPORT2 0395 uloc_setDefault(const char* localeID, 0396 UErrorCode* status); 0397 #endif /* U_HIDE_SYSTEM_API */ 0398 0399 /** 0400 * Gets the language code for the specified locale. 0401 * 0402 * This function may return with a failure error code for certain kinds of inputs 0403 * but does not fully check for well-formed locale IDs / language tags. 0404 * 0405 * @param localeID the locale to get the ISO language code with 0406 * @param language the language code for localeID 0407 * @param languageCapacity the size of the language buffer to store the 0408 * language code with 0409 * @param err error information if retrieving the language code failed 0410 * @return the actual buffer size needed for the language code. If it's greater 0411 * than languageCapacity, the returned language code will be truncated. 0412 * @stable ICU 2.0 0413 */ 0414 U_CAPI int32_t U_EXPORT2 0415 uloc_getLanguage(const char* localeID, 0416 char* language, 0417 int32_t languageCapacity, 0418 UErrorCode* err); 0419 0420 /** 0421 * Gets the script code for the specified locale. 0422 * 0423 * This function may return with a failure error code for certain kinds of inputs 0424 * but does not fully check for well-formed locale IDs / language tags. 0425 * 0426 * @param localeID the locale to get the ISO language code with 0427 * @param script the language code for localeID 0428 * @param scriptCapacity the size of the language buffer to store the 0429 * language code with 0430 * @param err error information if retrieving the language code failed 0431 * @return the actual buffer size needed for the language code. If it's greater 0432 * than scriptCapacity, the returned language code will be truncated. 0433 * @stable ICU 2.8 0434 */ 0435 U_CAPI int32_t U_EXPORT2 0436 uloc_getScript(const char* localeID, 0437 char* script, 0438 int32_t scriptCapacity, 0439 UErrorCode* err); 0440 0441 /** 0442 * Gets the country code for the specified locale. 0443 * 0444 * This function may return with a failure error code for certain kinds of inputs 0445 * but does not fully check for well-formed locale IDs / language tags. 0446 * 0447 * @param localeID the locale to get the country code with 0448 * @param country the country code for localeID 0449 * @param countryCapacity the size of the country buffer to store the 0450 * country code with 0451 * @param err error information if retrieving the country code failed 0452 * @return the actual buffer size needed for the country code. If it's greater 0453 * than countryCapacity, the returned country code will be truncated. 0454 * @stable ICU 2.0 0455 */ 0456 U_CAPI int32_t U_EXPORT2 0457 uloc_getCountry(const char* localeID, 0458 char* country, 0459 int32_t countryCapacity, 0460 UErrorCode* err); 0461 0462 /** 0463 * Gets the variant code for the specified locale. 0464 * 0465 * This function may return with a failure error code for certain kinds of inputs 0466 * but does not fully check for well-formed locale IDs / language tags. 0467 * 0468 * @param localeID the locale to get the variant code with 0469 * @param variant the variant code for localeID 0470 * @param variantCapacity the size of the variant buffer to store the 0471 * variant code with 0472 * @param err error information if retrieving the variant code failed 0473 * @return the actual buffer size needed for the variant code. If it's greater 0474 * than variantCapacity, the returned variant code will be truncated. 0475 * @stable ICU 2.0 0476 */ 0477 U_CAPI int32_t U_EXPORT2 0478 uloc_getVariant(const char* localeID, 0479 char* variant, 0480 int32_t variantCapacity, 0481 UErrorCode* err); 0482 0483 0484 /** 0485 * Gets the full name for the specified locale. 0486 * 0487 * This function may return with a failure error code for certain kinds of inputs 0488 * but does not fully check for well-formed locale IDs / language tags. 0489 * 0490 * Note: This has the effect of 'canonicalizing' the ICU locale ID to 0491 * a certain extent. Upper and lower case are set as needed. 0492 * It does NOT map aliased names in any way. 0493 * See the top of this header file. 0494 * This API supports preflighting. 0495 * 0496 * @param localeID the locale to get the full name with 0497 * @param name fill in buffer for the name without keywords. 0498 * @param nameCapacity capacity of the fill in buffer. 0499 * @param err error information if retrieving the full name failed 0500 * @return the actual buffer size needed for the full name. If it's greater 0501 * than nameCapacity, the returned full name will be truncated. 0502 * @stable ICU 2.0 0503 */ 0504 U_CAPI int32_t U_EXPORT2 0505 uloc_getName(const char* localeID, 0506 char* name, 0507 int32_t nameCapacity, 0508 UErrorCode* err); 0509 0510 /** 0511 * Gets the full name for the specified locale. 0512 * Note: This has the effect of 'canonicalizing' the string to 0513 * a certain extent. Upper and lower case are set as needed, 0514 * and if the components were in 'POSIX' format they are changed to 0515 * ICU format. It does NOT map aliased names in any way. 0516 * See the top of this header file. 0517 * 0518 * @param localeID the locale to get the full name with 0519 * @param name the full name for localeID 0520 * @param nameCapacity the size of the name buffer to store the 0521 * full name with 0522 * @param err error information if retrieving the full name failed 0523 * @return the actual buffer size needed for the full name. If it's greater 0524 * than nameCapacity, the returned full name will be truncated. 0525 * @stable ICU 2.8 0526 */ 0527 U_CAPI int32_t U_EXPORT2 0528 uloc_canonicalize(const char* localeID, 0529 char* name, 0530 int32_t nameCapacity, 0531 UErrorCode* err); 0532 0533 /** 0534 * Gets the ISO language code for the specified locale. 0535 * 0536 * @param localeID the locale to get the ISO language code with 0537 * @return language the ISO language code for localeID 0538 * @stable ICU 2.0 0539 */ 0540 U_CAPI const char* U_EXPORT2 0541 uloc_getISO3Language(const char* localeID); 0542 0543 0544 /** 0545 * Gets the ISO country code for the specified locale. 0546 * 0547 * @param localeID the locale to get the ISO country code with 0548 * @return country the ISO country code for localeID 0549 * @stable ICU 2.0 0550 */ 0551 U_CAPI const char* U_EXPORT2 0552 uloc_getISO3Country(const char* localeID); 0553 0554 /** 0555 * Gets the Win32 LCID value for the specified locale. 0556 * If the ICU locale is not recognized by Windows, 0 will be returned. 0557 * 0558 * LCIDs were deprecated with Windows Vista and Microsoft recommends 0559 * that developers use BCP47 style tags instead (uloc_toLanguageTag). 0560 * 0561 * @param localeID the locale to get the Win32 LCID value with 0562 * @return country the Win32 LCID for localeID 0563 * @stable ICU 2.0 0564 */ 0565 U_CAPI uint32_t U_EXPORT2 0566 uloc_getLCID(const char* localeID); 0567 0568 /** 0569 * Gets the language name suitable for display for the specified locale. 0570 * 0571 * @param locale the locale to get the ISO language code with 0572 * @param displayLocale Specifies the locale to be used to display the name. In 0573 * other words, if the locale's language code is "en", passing 0574 * Locale::getFrench() for inLocale would result in "Anglais", 0575 * while passing Locale::getGerman() for inLocale would result 0576 * in "Englisch". 0577 * @param language the displayable language code for localeID 0578 * @param languageCapacity the size of the language buffer to store the 0579 * displayable language code with. 0580 * @param status error information if retrieving the displayable language code 0581 * failed. U_USING_DEFAULT_WARNING indicates that no data was 0582 * found from the locale resources and a case canonicalized 0583 * language code is placed into language as fallback. 0584 * @return the actual buffer size needed for the displayable language code. If 0585 * it's greater than languageCapacity, the returned language 0586 * code will be truncated. 0587 * @stable ICU 2.0 0588 */ 0589 U_CAPI int32_t U_EXPORT2 0590 uloc_getDisplayLanguage(const char* locale, 0591 const char* displayLocale, 0592 UChar* language, 0593 int32_t languageCapacity, 0594 UErrorCode* status); 0595 0596 /** 0597 * Gets the script name suitable for display for the specified locale. 0598 * 0599 * @param locale the locale to get the displayable script code with. NULL may be 0600 * used to specify the default. 0601 * @param displayLocale Specifies the locale to be used to display the name. In 0602 * other words, if the locale's language code is "en", passing 0603 * Locale::getFrench() for inLocale would result in "", while 0604 * passing Locale::getGerman() for inLocale would result in "". 0605 * NULL may be used to specify the default. 0606 * @param script the displayable script for the localeID. 0607 * @param scriptCapacity the size of the script buffer to store the displayable 0608 * script code with. 0609 * @param status error information if retrieving the displayable script code 0610 * failed. U_USING_DEFAULT_WARNING indicates that no data was 0611 * found from the locale resources and a case canonicalized 0612 * script code is placed into script as fallback. 0613 * @return the actual buffer size needed for the displayable script code. If 0614 * it's greater than scriptCapacity, the returned displayable 0615 * script code will be truncated. 0616 * @stable ICU 2.8 0617 */ 0618 U_CAPI int32_t U_EXPORT2 0619 uloc_getDisplayScript(const char* locale, 0620 const char* displayLocale, 0621 UChar* script, 0622 int32_t scriptCapacity, 0623 UErrorCode* status); 0624 0625 /** 0626 * Gets the country name suitable for display for the specified locale. 0627 * Warning: this is for the region part of a valid locale ID; it cannot just be 0628 * the region code (like "FR"). To get the display name for a region alone, or 0629 * for other options, use ULocaleDisplayNames instead. 0630 * 0631 * @param locale the locale to get the displayable country code with. NULL may 0632 * be used to specify the default. 0633 * @param displayLocale Specifies the locale to be used to display the name. In 0634 * other words, if the locale's language code is "en", passing 0635 * Locale::getFrench() for inLocale would result in "Anglais", 0636 * while passing Locale::getGerman() for inLocale would result 0637 * in "Englisch". NULL may be used to specify the default. 0638 * @param country the displayable country code for localeID. 0639 * @param countryCapacity the size of the country buffer to store the 0640 * displayable country code with. 0641 * @param status error information if retrieving the displayable country code 0642 * failed. U_USING_DEFAULT_WARNING indicates that no data was 0643 * found from the locale resources and a case canonicalized 0644 * country code is placed into country as fallback. 0645 * @return the actual buffer size needed for the displayable country code. If 0646 * it's greater than countryCapacity, the returned displayable 0647 * country code will be truncated. 0648 * @stable ICU 2.0 0649 */ 0650 U_CAPI int32_t U_EXPORT2 0651 uloc_getDisplayCountry(const char* locale, 0652 const char* displayLocale, 0653 UChar* country, 0654 int32_t countryCapacity, 0655 UErrorCode* status); 0656 0657 0658 /** 0659 * Gets the variant name suitable for display for the specified locale. 0660 * 0661 * @param locale the locale to get the displayable variant code with. NULL may 0662 * be used to specify the default. 0663 * @param displayLocale Specifies the locale to be used to display the name. In 0664 * other words, if the locale's language code is "en", passing 0665 * Locale::getFrench() for inLocale would result in "Anglais", 0666 * while passing Locale::getGerman() for inLocale would result 0667 * in "Englisch". NULL may be used to specify the default. 0668 * @param variant the displayable variant code for localeID. 0669 * @param variantCapacity the size of the variant buffer to store the 0670 * displayable variant code with. 0671 * @param status error information if retrieving the displayable variant code 0672 * failed. U_USING_DEFAULT_WARNING indicates that no data was 0673 * found from the locale resources and a case canonicalized 0674 * variant code is placed into variant as fallback. 0675 * @return the actual buffer size needed for the displayable variant code. If 0676 * it's greater than variantCapacity, the returned displayable 0677 * variant code will be truncated. 0678 * @stable ICU 2.0 0679 */ 0680 U_CAPI int32_t U_EXPORT2 0681 uloc_getDisplayVariant(const char* locale, 0682 const char* displayLocale, 0683 UChar* variant, 0684 int32_t variantCapacity, 0685 UErrorCode* status); 0686 0687 /** 0688 * Gets the keyword name suitable for display for the specified locale. E.g: 0689 * for the locale string de_DE\@collation=PHONEBOOK, this API gets the display 0690 * string for the keyword collation. 0691 * Usage: 0692 * <code> 0693 * UErrorCode status = U_ZERO_ERROR; 0694 * const char* keyword =NULL; 0695 * int32_t keywordLen = 0; 0696 * int32_t keywordCount = 0; 0697 * UChar displayKeyword[256]; 0698 * int32_t displayKeywordLen = 0; 0699 * UEnumeration* keywordEnum = uloc_openKeywords("de_DE@collation=PHONEBOOK;calendar=TRADITIONAL", &status); 0700 * for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){ 0701 * if(U_FAILURE(status)){ 0702 * ...something went wrong so handle the error... 0703 * break; 0704 * } 0705 * // the uenum_next returns NUL terminated string 0706 * keyword = uenum_next(keywordEnum, &keywordLen, &status); 0707 * displayKeywordLen = uloc_getDisplayKeyword(keyword, "en_US", displayKeyword, 256); 0708 * ... do something interesting ..... 0709 * } 0710 * uenum_close(keywordEnum); 0711 * </code> 0712 * @param keyword The keyword whose display string needs to be returned. 0713 * @param displayLocale Specifies the locale to be used to display the name. In other words, 0714 * if the locale's language code is "en", passing Locale::getFrench() for 0715 * inLocale would result in "Anglais", while passing Locale::getGerman() 0716 * for inLocale would result in "Englisch". NULL may be used to specify the default. 0717 * @param dest the buffer to which the displayable keyword should be written. 0718 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 0719 * dest may be NULL and the function will only return the length of the 0720 * result without writing any of the result string (pre-flighting). 0721 * @param status error information if retrieving the displayable string failed. 0722 * Should not be NULL and should not indicate failure on entry. 0723 * U_USING_DEFAULT_WARNING indicates that no data was found from the locale 0724 * resources and the keyword is placed into dest as fallback. 0725 * @return the actual buffer size needed for the displayable variant code. 0726 * @see #uloc_openKeywords 0727 * @stable ICU 2.8 0728 */ 0729 U_CAPI int32_t U_EXPORT2 0730 uloc_getDisplayKeyword(const char* keyword, 0731 const char* displayLocale, 0732 UChar* dest, 0733 int32_t destCapacity, 0734 UErrorCode* status); 0735 /** 0736 * Gets the value of the keyword suitable for display for the specified locale. 0737 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display 0738 * string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword. 0739 * 0740 * @param locale The locale to get the displayable variant code with. NULL may be used to specify the default. 0741 * @param keyword The keyword for whose value should be used. 0742 * @param displayLocale Specifies the locale to be used to display the name. In other words, 0743 * if the locale's language code is "en", passing Locale::getFrench() for 0744 * inLocale would result in "Anglais", while passing Locale::getGerman() 0745 * for inLocale would result in "Englisch". NULL may be used to specify the default. 0746 * @param dest the buffer to which the displayable keyword should be written. 0747 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then 0748 * dest may be NULL and the function will only return the length of the 0749 * result without writing any of the result string (pre-flighting). 0750 * @param status error information if retrieving the displayable string failed. 0751 * Should not be NULL and must not indicate failure on entry. 0752 * U_USING_DEFAULT_WARNING indicates that no data was found from the locale 0753 * resources and the value of the keyword is placed into dest as fallback. 0754 * @return the actual buffer size needed for the displayable variant code. 0755 * @stable ICU 2.8 0756 */ 0757 U_CAPI int32_t U_EXPORT2 0758 uloc_getDisplayKeywordValue( const char* locale, 0759 const char* keyword, 0760 const char* displayLocale, 0761 UChar* dest, 0762 int32_t destCapacity, 0763 UErrorCode* status); 0764 /** 0765 * Gets the full name suitable for display for the specified locale. 0766 * 0767 * @param localeID the locale to get the displayable name with. NULL may be used to specify the default. 0768 * @param inLocaleID Specifies the locale to be used to display the name. In other words, 0769 * if the locale's language code is "en", passing Locale::getFrench() for 0770 * inLocale would result in "Anglais", while passing Locale::getGerman() 0771 * for inLocale would result in "Englisch". NULL may be used to specify the default. 0772 * @param result the displayable name for localeID 0773 * @param maxResultSize the size of the name buffer to store the 0774 * displayable full name with 0775 * @param err error information if retrieving the displayable name failed 0776 * @return the actual buffer size needed for the displayable name. If it's greater 0777 * than maxResultSize, the returned displayable name will be truncated. 0778 * @stable ICU 2.0 0779 */ 0780 U_CAPI int32_t U_EXPORT2 0781 uloc_getDisplayName(const char* localeID, 0782 const char* inLocaleID, 0783 UChar* result, 0784 int32_t maxResultSize, 0785 UErrorCode* err); 0786 0787 0788 /** 0789 * Gets the specified locale from a list of available locales. 0790 * 0791 * This method corresponds to uloc_openAvailableByType called with the 0792 * ULOC_AVAILABLE_DEFAULT type argument. 0793 * 0794 * The return value is a pointer to an item of a locale name array. Both this 0795 * array and the pointers it contains are owned by ICU and should not be 0796 * deleted or written through by the caller. The locale name is terminated by 0797 * a null pointer. 0798 * 0799 * @param n the specific locale name index of the available locale list; 0800 * should not exceed the number returned by uloc_countAvailable. 0801 * @return a specified locale name of all available locales 0802 * @stable ICU 2.0 0803 */ 0804 U_CAPI const char* U_EXPORT2 0805 uloc_getAvailable(int32_t n); 0806 0807 /** 0808 * Gets the size of the all available locale list. 0809 * 0810 * @return the size of the locale list 0811 * @stable ICU 2.0 0812 */ 0813 U_CAPI int32_t U_EXPORT2 uloc_countAvailable(void); 0814 0815 /** 0816 * Types for uloc_getAvailableByType and uloc_countAvailableByType. 0817 * 0818 * @stable ICU 65 0819 */ 0820 typedef enum ULocAvailableType { 0821 /** 0822 * Locales that return data when passed to ICU APIs, 0823 * but not including legacy or alias locales. 0824 * 0825 * @stable ICU 65 0826 */ 0827 ULOC_AVAILABLE_DEFAULT, 0828 0829 /** 0830 * Legacy or alias locales that return data when passed to ICU APIs. 0831 * Examples of supported legacy or alias locales: 0832 * 0833 * - iw (alias to he) 0834 * - mo (alias to ro) 0835 * - zh_CN (alias to zh_Hans_CN) 0836 * - sr_BA (alias to sr_Cyrl_BA) 0837 * - ars (alias to ar_SA) 0838 * 0839 * The locales in this set are disjoint from the ones in 0840 * ULOC_AVAILABLE_DEFAULT. To get both sets at the same time, use 0841 * ULOC_AVAILABLE_WITH_LEGACY_ALIASES. 0842 * 0843 * @stable ICU 65 0844 */ 0845 ULOC_AVAILABLE_ONLY_LEGACY_ALIASES, 0846 0847 /** 0848 * The union of the locales in ULOC_AVAILABLE_DEFAULT and 0849 * ULOC_AVAILABLE_ONLY_LEGACY_ALIAS. 0850 * 0851 * @stable ICU 65 0852 */ 0853 ULOC_AVAILABLE_WITH_LEGACY_ALIASES, 0854 0855 #ifndef U_HIDE_INTERNAL_API 0856 /** 0857 * @internal 0858 */ 0859 ULOC_AVAILABLE_COUNT 0860 #endif /* U_HIDE_INTERNAL_API */ 0861 } ULocAvailableType; 0862 0863 /** 0864 * Gets a list of available locales according to the type argument, allowing 0865 * the user to access different sets of supported locales in ICU. 0866 * 0867 * The returned UEnumeration must be closed by the caller. 0868 * 0869 * @param type Type choice from ULocAvailableType. 0870 * @param status Set if an error occurred. 0871 * @return a UEnumeration owned by the caller, or nullptr on failure. 0872 * @stable ICU 65 0873 */ 0874 U_CAPI UEnumeration* U_EXPORT2 0875 uloc_openAvailableByType(ULocAvailableType type, UErrorCode* status); 0876 0877 /** 0878 * 0879 * Gets a list of all available 2-letter language codes defined in ISO 639, 0880 * plus additional 3-letter codes determined to be useful for locale generation as 0881 * defined by Unicode CLDR. This is a pointer 0882 * to an array of pointers to arrays of char. All of these pointers are owned 0883 * by ICU-- do not delete them, and do not write through them. The array is 0884 * terminated with a null pointer. 0885 * @return a list of all available language codes 0886 * @stable ICU 2.0 0887 */ 0888 U_CAPI const char* const* U_EXPORT2 0889 uloc_getISOLanguages(void); 0890 0891 /** 0892 * 0893 * Gets a list of all available 2-letter country codes defined in ISO 639. This is a 0894 * pointer to an array of pointers to arrays of char. All of these pointers are 0895 * owned by ICU-- do not delete them, and do not write through them. The array is 0896 * terminated with a null pointer. 0897 * @return a list of all available country codes 0898 * @stable ICU 2.0 0899 */ 0900 U_CAPI const char* const* U_EXPORT2 0901 uloc_getISOCountries(void); 0902 0903 /** 0904 * Truncate the locale ID string to get the parent locale ID. 0905 * Copies the part of the string before the last underscore. 0906 * The parent locale ID will be an empty string if there is no 0907 * underscore, or if there is only one underscore at localeID[0]. 0908 * 0909 * @param localeID Input locale ID string. 0910 * @param parent Output string buffer for the parent locale ID. 0911 * @param parentCapacity Size of the output buffer. 0912 * @param err A UErrorCode value. 0913 * @return The length of the parent locale ID. 0914 * @stable ICU 2.0 0915 */ 0916 U_CAPI int32_t U_EXPORT2 0917 uloc_getParent(const char* localeID, 0918 char* parent, 0919 int32_t parentCapacity, 0920 UErrorCode* err); 0921 0922 0923 0924 0925 /** 0926 * Gets the full name for the specified locale, like uloc_getName(), 0927 * but without keywords. 0928 * 0929 * Note: This has the effect of 'canonicalizing' the string to 0930 * a certain extent. Upper and lower case are set as needed, 0931 * and if the components were in 'POSIX' format they are changed to 0932 * ICU format. It does NOT map aliased names in any way. 0933 * See the top of this header file. 0934 * 0935 * This API strips off the keyword part, so "de_DE\@collation=phonebook" 0936 * will become "de_DE". 0937 * This API supports preflighting. 0938 * 0939 * @param localeID the locale to get the full name with 0940 * @param name fill in buffer for the name without keywords. 0941 * @param nameCapacity capacity of the fill in buffer. 0942 * @param err error information if retrieving the full name failed 0943 * @return the actual buffer size needed for the full name. If it's greater 0944 * than nameCapacity, the returned full name will be truncated. 0945 * @stable ICU 2.8 0946 */ 0947 U_CAPI int32_t U_EXPORT2 0948 uloc_getBaseName(const char* localeID, 0949 char* name, 0950 int32_t nameCapacity, 0951 UErrorCode* err); 0952 0953 /** 0954 * Gets an enumeration of keywords for the specified locale. Enumeration 0955 * must get disposed of by the client using uenum_close function. 0956 * 0957 * @param localeID the locale to get the variant code with 0958 * @param status error information if retrieving the keywords failed 0959 * @return enumeration of keywords or NULL if there are no keywords. 0960 * @stable ICU 2.8 0961 */ 0962 U_CAPI UEnumeration* U_EXPORT2 0963 uloc_openKeywords(const char* localeID, 0964 UErrorCode* status); 0965 0966 /** 0967 * Get the value for a keyword. Locale name does not need to be normalized. 0968 * 0969 * @param localeID locale name containing the keyword ("de_DE@currency=EURO;collation=PHONEBOOK") 0970 * @param keywordName name of the keyword for which we want the value; must not be 0971 * NULL or empty, and must consist only of [A-Za-z0-9]. Case insensitive. 0972 * @param buffer receiving buffer 0973 * @param bufferCapacity capacity of receiving buffer 0974 * @param status containing error code: e.g. buffer not big enough or ill-formed localeID 0975 * or keywordName parameters. 0976 * @return the length of keyword value 0977 * @stable ICU 2.8 0978 */ 0979 U_CAPI int32_t U_EXPORT2 0980 uloc_getKeywordValue(const char* localeID, 0981 const char* keywordName, 0982 char* buffer, int32_t bufferCapacity, 0983 UErrorCode* status); 0984 0985 0986 /** 0987 * Sets or removes the value of the specified keyword. 0988 * 0989 * For removing all keywords, use uloc_getBaseName(). 0990 * 0991 * NOTE: Unlike almost every other ICU function which takes a 0992 * buffer, this function will NOT truncate the output text, and will 0993 * not update the buffer with unterminated text setting a status of 0994 * U_STRING_NOT_TERMINATED_WARNING. If a BUFFER_OVERFLOW_ERROR is received, 0995 * it means a terminated version of the updated locale ID would not fit 0996 * in the buffer, and the original buffer is untouched. This is done to 0997 * prevent incorrect or possibly even malformed locales from being generated 0998 * and used. 0999 * 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*/
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|