uloc.h 50 KB

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