uloc.h 50 KB

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