uloc.h 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 1997-2016, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. *
  9. * File ULOC.H
  10. *
  11. * Modification History:
  12. *
  13. * Date Name Description
  14. * 04/01/97 aliu Creation.
  15. * 08/22/98 stephen JDK 1.2 sync.
  16. * 12/08/98 rtg New C API for Locale
  17. * 03/30/99 damiba overhaul
  18. * 03/31/99 helena Javadoc for uloc functions.
  19. * 04/15/99 Madhu Updated Javadoc
  20. ********************************************************************************
  21. */
  22. #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 ID functionality similar to C++ class 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 additional <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 additional 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 service 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_CAPI 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_CAPI 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_CAPI 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_CAPI 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_CAPI 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_CAPI 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_CAPI 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_CAPI 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_CAPI 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_CAPI 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. * LCIDs were deprecated with Windows Vista and Microsoft recommends
  511. * that developers use BCP47 style tags instead (uloc_toLanguageTag).
  512. *
  513. * @param localeID the locale to get the Win32 LCID value with
  514. * @return country the Win32 LCID for localeID
  515. * @stable ICU 2.0
  516. */
  517. U_CAPI uint32_t U_EXPORT2
  518. uloc_getLCID(const char* localeID);
  519. /**
  520. * Gets the language name suitable for display for the specified locale.
  521. *
  522. * @param locale the locale to get the ISO language code with
  523. * @param displayLocale Specifies the locale to be used to display the name. In
  524. * other words, if the locale's language code is "en", passing
  525. * Locale::getFrench() for inLocale would result in "Anglais",
  526. * while passing Locale::getGerman() for inLocale would result
  527. * in "Englisch".
  528. * @param language the displayable language code for localeID
  529. * @param languageCapacity the size of the language buffer to store the
  530. * displayable language code with.
  531. * @param status error information if retrieving the displayable language code
  532. * failed. U_USING_DEFAULT_WARNING indicates that no data was
  533. * found from the locale resources and a case canonicalized
  534. * language code is placed into language as fallback.
  535. * @return the actual buffer size needed for the displayable language code. If
  536. * it's greater than languageCapacity, the returned language
  537. * code will be truncated.
  538. * @stable ICU 2.0
  539. */
  540. U_CAPI int32_t U_EXPORT2
  541. uloc_getDisplayLanguage(const char* locale,
  542. const char* displayLocale,
  543. UChar* language,
  544. int32_t languageCapacity,
  545. UErrorCode* status);
  546. /**
  547. * Gets the script name suitable for display for the specified locale.
  548. *
  549. * @param locale the locale to get the displayable script code with. NULL may be
  550. * used to specify the default.
  551. * @param displayLocale Specifies the locale to be used to display the name. In
  552. * other words, if the locale's language code is "en", passing
  553. * Locale::getFrench() for inLocale would result in "", while
  554. * passing Locale::getGerman() for inLocale would result in "".
  555. * NULL may be used to specify the default.
  556. * @param script the displayable script for the localeID.
  557. * @param scriptCapacity the size of the script buffer to store the displayable
  558. * script code with.
  559. * @param status error information if retrieving the displayable script code
  560. * failed. U_USING_DEFAULT_WARNING indicates that no data was
  561. * found from the locale resources and a case canonicalized
  562. * script code is placed into script as fallback.
  563. * @return the actual buffer size needed for the displayable script code. If
  564. * it's greater than scriptCapacity, the returned displayable
  565. * script code will be truncated.
  566. * @stable ICU 2.8
  567. */
  568. U_CAPI int32_t U_EXPORT2
  569. uloc_getDisplayScript(const char* locale,
  570. const char* displayLocale,
  571. UChar* script,
  572. int32_t scriptCapacity,
  573. UErrorCode* status);
  574. /**
  575. * Gets the country name suitable for display for the specified locale.
  576. * Warning: this is for the region part of a valid locale ID; it cannot just be
  577. * the region code (like "FR"). To get the display name for a region alone, or
  578. * for other options, use ULocaleDisplayNames instead.
  579. *
  580. * @param locale the locale to get the displayable country code with. NULL may
  581. * be used to specify the default.
  582. * @param displayLocale Specifies the locale to be used to display the name. In
  583. * other words, if the locale's language code is "en", passing
  584. * Locale::getFrench() for inLocale would result in "Anglais",
  585. * while passing Locale::getGerman() for inLocale would result
  586. * in "Englisch". NULL may be used to specify the default.
  587. * @param country the displayable country code for localeID.
  588. * @param countryCapacity the size of the country buffer to store the
  589. * displayable country code with.
  590. * @param status error information if retrieving the displayable country code
  591. * failed. U_USING_DEFAULT_WARNING indicates that no data was
  592. * found from the locale resources and a case canonicalized
  593. * country code is placed into country as fallback.
  594. * @return the actual buffer size needed for the displayable country code. If
  595. * it's greater than countryCapacity, the returned displayable
  596. * country code will be truncated.
  597. * @stable ICU 2.0
  598. */
  599. U_CAPI int32_t U_EXPORT2
  600. uloc_getDisplayCountry(const char* locale,
  601. const char* displayLocale,
  602. UChar* country,
  603. int32_t countryCapacity,
  604. UErrorCode* status);
  605. /**
  606. * Gets the variant name suitable for display for the specified locale.
  607. *
  608. * @param locale the locale to get the displayable variant code with. NULL may
  609. * be used to specify the default.
  610. * @param displayLocale Specifies the locale to be used to display the name. In
  611. * other words, if the locale's language code is "en", passing
  612. * Locale::getFrench() for inLocale would result in "Anglais",
  613. * while passing Locale::getGerman() for inLocale would result
  614. * in "Englisch". NULL may be used to specify the default.
  615. * @param variant the displayable variant code for localeID.
  616. * @param variantCapacity the size of the variant buffer to store the
  617. * displayable variant code with.
  618. * @param status error information if retrieving the displayable variant code
  619. * failed. U_USING_DEFAULT_WARNING indicates that no data was
  620. * found from the locale resources and a case canonicalized
  621. * variant code is placed into variant as fallback.
  622. * @return the actual buffer size needed for the displayable variant code. If
  623. * it's greater than variantCapacity, the returned displayable
  624. * variant code will be truncated.
  625. * @stable ICU 2.0
  626. */
  627. U_CAPI int32_t U_EXPORT2
  628. uloc_getDisplayVariant(const char* locale,
  629. const char* displayLocale,
  630. UChar* variant,
  631. int32_t variantCapacity,
  632. UErrorCode* status);
  633. /**
  634. * Gets the keyword name suitable for display for the specified locale. E.g:
  635. * for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
  636. * string for the keyword collation.
  637. * Usage:
  638. * <code>
  639. * UErrorCode status = U_ZERO_ERROR;
  640. * const char* keyword =NULL;
  641. * int32_t keywordLen = 0;
  642. * int32_t keywordCount = 0;
  643. * UChar displayKeyword[256];
  644. * int32_t displayKeywordLen = 0;
  645. * UEnumeration* keywordEnum = uloc_openKeywords("de_DE@collation=PHONEBOOK;calendar=TRADITIONAL", &status);
  646. * for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
  647. * if(U_FAILURE(status)){
  648. * ...something went wrong so handle the error...
  649. * break;
  650. * }
  651. * // the uenum_next returns NUL terminated string
  652. * keyword = uenum_next(keywordEnum, &keywordLen, &status);
  653. * displayKeywordLen = uloc_getDisplayKeyword(keyword, "en_US", displayKeyword, 256);
  654. * ... do something interesting .....
  655. * }
  656. * uenum_close(keywordEnum);
  657. * </code>
  658. * @param keyword The keyword whose display string needs to be returned.
  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 should not indicate failure on entry.
  669. * U_USING_DEFAULT_WARNING indicates that no data was found from the locale
  670. * resources and the keyword is placed into dest as fallback.
  671. * @return the actual buffer size needed for the displayable variant code.
  672. * @see #uloc_openKeywords
  673. * @stable ICU 2.8
  674. */
  675. U_CAPI int32_t U_EXPORT2
  676. uloc_getDisplayKeyword(const char* keyword,
  677. const char* displayLocale,
  678. UChar* dest,
  679. int32_t destCapacity,
  680. UErrorCode* status);
  681. /**
  682. * Gets the value of the keyword suitable for display for the specified locale.
  683. * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
  684. * string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword.
  685. *
  686. * @param locale The locale to get the displayable variant code with. NULL may be used to specify the default.
  687. * @param keyword The keyword for whose value should be used.
  688. * @param displayLocale Specifies the locale to be used to display the name. In other words,
  689. * if the locale's language code is "en", passing Locale::getFrench() for
  690. * inLocale would result in "Anglais", while passing Locale::getGerman()
  691. * for inLocale would result in "Englisch". NULL may be used to specify the default.
  692. * @param dest the buffer to which the displayable keyword should be written.
  693. * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
  694. * dest may be NULL and the function will only return the length of the
  695. * result without writing any of the result string (pre-flighting).
  696. * @param status error information if retrieving the displayable string failed.
  697. * Should not be NULL and must not indicate failure on entry.
  698. * U_USING_DEFAULT_WARNING indicates that no data was found from the locale
  699. * resources and the value of the keyword is placed into dest as fallback.
  700. * @return the actual buffer size needed for the displayable variant code.
  701. * @stable ICU 2.8
  702. */
  703. U_CAPI int32_t U_EXPORT2
  704. uloc_getDisplayKeywordValue( const char* locale,
  705. const char* keyword,
  706. const char* displayLocale,
  707. UChar* dest,
  708. int32_t destCapacity,
  709. UErrorCode* status);
  710. /**
  711. * Gets the full name suitable for display for the specified locale.
  712. *
  713. * @param localeID the locale to get the displayable name with. NULL may be used to specify the default.
  714. * @param inLocaleID Specifies the locale to be used to display the name. In other words,
  715. * if the locale's language code is "en", passing Locale::getFrench() for
  716. * inLocale would result in "Anglais", while passing Locale::getGerman()
  717. * for inLocale would result in "Englisch". NULL may be used to specify the default.
  718. * @param result the displayable name for localeID
  719. * @param maxResultSize the size of the name buffer to store the
  720. * displayable full name with
  721. * @param err error information if retrieving the displayable name failed
  722. * @return the actual buffer size needed for the displayable name. If it's greater
  723. * than maxResultSize, the returned displayable name will be truncated.
  724. * @stable ICU 2.0
  725. */
  726. U_CAPI int32_t U_EXPORT2
  727. uloc_getDisplayName(const char* localeID,
  728. const char* inLocaleID,
  729. UChar* result,
  730. int32_t maxResultSize,
  731. UErrorCode* err);
  732. /**
  733. * Gets the specified locale from a list of available locales.
  734. *
  735. * This method corresponds to uloc_openAvailableByType called with the
  736. * ULOC_AVAILABLE_DEFAULT type argument.
  737. *
  738. * The return value is a pointer to an item of a locale name array. Both this
  739. * array and the pointers it contains are owned by ICU and should not be
  740. * deleted or written through by the caller. The locale name is terminated by
  741. * a null pointer.
  742. *
  743. * @param n the specific locale name index of the available locale list;
  744. * should not exceed the number returned by uloc_countAvailable.
  745. * @return a specified locale name of all available locales
  746. * @stable ICU 2.0
  747. */
  748. U_CAPI const char* U_EXPORT2
  749. uloc_getAvailable(int32_t n);
  750. /**
  751. * Gets the size of the all available locale list.
  752. *
  753. * @return the size of the locale list
  754. * @stable ICU 2.0
  755. */
  756. U_CAPI int32_t U_EXPORT2 uloc_countAvailable(void);
  757. /**
  758. * Types for uloc_getAvailableByType and uloc_countAvailableByType.
  759. *
  760. * @stable ICU 65
  761. */
  762. typedef enum ULocAvailableType {
  763. /**
  764. * Locales that return data when passed to ICU APIs,
  765. * but not including legacy or alias locales.
  766. *
  767. * @stable ICU 65
  768. */
  769. ULOC_AVAILABLE_DEFAULT,
  770. /**
  771. * Legacy or alias locales that return data when passed to ICU APIs.
  772. * Examples of supported legacy or alias locales:
  773. *
  774. * - iw (alias to he)
  775. * - mo (alias to ro)
  776. * - zh_CN (alias to zh_Hans_CN)
  777. * - sr_BA (alias to sr_Cyrl_BA)
  778. * - ars (alias to ar_SA)
  779. *
  780. * The locales in this set are disjoint from the ones in
  781. * ULOC_AVAILABLE_DEFAULT. To get both sets at the same time, use
  782. * ULOC_AVAILABLE_WITH_LEGACY_ALIASES.
  783. *
  784. * @stable ICU 65
  785. */
  786. ULOC_AVAILABLE_ONLY_LEGACY_ALIASES,
  787. /**
  788. * The union of the locales in ULOC_AVAILABLE_DEFAULT and
  789. * ULOC_AVAILABLE_ONLY_LEGACY_ALIAS.
  790. *
  791. * @stable ICU 65
  792. */
  793. ULOC_AVAILABLE_WITH_LEGACY_ALIASES,
  794. #ifndef U_HIDE_INTERNAL_API
  795. /**
  796. * @internal
  797. */
  798. ULOC_AVAILABLE_COUNT
  799. #endif /* U_HIDE_INTERNAL_API */
  800. } ULocAvailableType;
  801. /**
  802. * Gets a list of available locales according to the type argument, allowing
  803. * the user to access different sets of supported locales in ICU.
  804. *
  805. * The returned UEnumeration must be closed by the caller.
  806. *
  807. * @param type Type choice from ULocAvailableType.
  808. * @param status Set if an error occurred.
  809. * @return a UEnumeration owned by the caller, or nullptr on failure.
  810. * @stable ICU 65
  811. */
  812. U_CAPI UEnumeration* U_EXPORT2
  813. uloc_openAvailableByType(ULocAvailableType type, UErrorCode* status);
  814. /**
  815. *
  816. * Gets a list of all available 2-letter language codes defined in ISO 639,
  817. * plus additional 3-letter codes determined to be useful for locale generation as
  818. * defined by Unicode CLDR. This is a pointer
  819. * to an array of pointers to arrays of char. All of these pointers are owned
  820. * by ICU-- do not delete them, and do not write through them. The array is
  821. * terminated with a null pointer.
  822. * @return a list of all available language codes
  823. * @stable ICU 2.0
  824. */
  825. U_CAPI const char* const* U_EXPORT2
  826. uloc_getISOLanguages(void);
  827. /**
  828. *
  829. * Gets a list of all available 2-letter country codes defined in ISO 639. This is a
  830. * pointer to an array of pointers to arrays of char. All of these pointers are
  831. * owned by ICU-- do not delete them, and do not write through them. The array is
  832. * terminated with a null pointer.
  833. * @return a list of all available country codes
  834. * @stable ICU 2.0
  835. */
  836. U_CAPI const char* const* U_EXPORT2
  837. uloc_getISOCountries(void);
  838. /**
  839. * Truncate the locale ID string to get the parent locale ID.
  840. * Copies the part of the string before the last underscore.
  841. * The parent locale ID will be an empty string if there is no
  842. * underscore, or if there is only one underscore at localeID[0].
  843. *
  844. * @param localeID Input locale ID string.
  845. * @param parent Output string buffer for the parent locale ID.
  846. * @param parentCapacity Size of the output buffer.
  847. * @param err A UErrorCode value.
  848. * @return The length of the parent locale ID.
  849. * @stable ICU 2.0
  850. */
  851. U_CAPI int32_t U_EXPORT2
  852. uloc_getParent(const char* localeID,
  853. char* parent,
  854. int32_t parentCapacity,
  855. UErrorCode* err);
  856. /**
  857. * Gets the full name for the specified locale, like uloc_getName(),
  858. * but without keywords.
  859. *
  860. * Note: This has the effect of 'canonicalizing' the string to
  861. * a certain extent. Upper and lower case are set as needed,
  862. * and if the components were in 'POSIX' format they are changed to
  863. * ICU format. It does NOT map aliased names in any way.
  864. * See the top of this header file.
  865. *
  866. * This API strips off the keyword part, so "de_DE\@collation=phonebook"
  867. * will become "de_DE".
  868. * This API supports preflighting.
  869. *
  870. * @param localeID the locale to get the full name with
  871. * @param name fill in buffer for the name without keywords.
  872. * @param nameCapacity capacity of the fill in buffer.
  873. * @param err error information if retrieving the full name failed
  874. * @return the actual buffer size needed for the full name. If it's greater
  875. * than nameCapacity, the returned full name will be truncated.
  876. * @stable ICU 2.8
  877. */
  878. U_CAPI int32_t U_EXPORT2
  879. uloc_getBaseName(const char* localeID,
  880. char* name,
  881. int32_t nameCapacity,
  882. UErrorCode* err);
  883. /**
  884. * Gets an enumeration of keywords for the specified locale. Enumeration
  885. * must get disposed of by the client using uenum_close function.
  886. *
  887. * @param localeID the locale to get the variant code with
  888. * @param status error information if retrieving the keywords failed
  889. * @return enumeration of keywords or NULL if there are no keywords.
  890. * @stable ICU 2.8
  891. */
  892. U_CAPI UEnumeration* U_EXPORT2
  893. uloc_openKeywords(const char* localeID,
  894. UErrorCode* status);
  895. /**
  896. * Get the value for a keyword. Locale name does not need to be normalized.
  897. *
  898. * @param localeID locale name containing the keyword ("de_DE@currency=EURO;collation=PHONEBOOK")
  899. * @param keywordName name of the keyword for which we want the value; must not be
  900. * NULL or empty, and must consist only of [A-Za-z0-9]. Case insensitive.
  901. * @param buffer receiving buffer
  902. * @param bufferCapacity capacity of receiving buffer
  903. * @param status containing error code: e.g. buffer not big enough or ill-formed localeID
  904. * or keywordName parameters.
  905. * @return the length of keyword value
  906. * @stable ICU 2.8
  907. */
  908. U_CAPI int32_t U_EXPORT2
  909. uloc_getKeywordValue(const char* localeID,
  910. const char* keywordName,
  911. char* buffer, int32_t bufferCapacity,
  912. UErrorCode* status);
  913. /**
  914. * Sets or removes the value of the specified keyword.
  915. *
  916. * For removing all keywords, use uloc_getBaseName().
  917. *
  918. * NOTE: Unlike almost every other ICU function which takes a
  919. * buffer, this function will NOT truncate the output text, and will
  920. * not update the buffer with unterminated text setting a status of
  921. * U_STRING_NOT_TERMINATED_WARNING. If a BUFFER_OVERFLOW_ERROR is received,
  922. * it means a terminated version of the updated locale ID would not fit
  923. * in the buffer, and the original buffer is untouched. This is done to
  924. * prevent incorrect or possibly even malformed locales from being generated
  925. * and used.
  926. *
  927. * @param keywordName name of the keyword to be set; must not be
  928. * NULL or empty, and must consist only of [A-Za-z0-9]. Case insensitive.
  929. * @param keywordValue value of the keyword to be set. If 0-length or
  930. * NULL, will result in the keyword being removed; no error is given if
  931. * that keyword does not exist. Otherwise, must consist only of
  932. * [A-Za-z0-9] and [/_+-].
  933. * @param buffer input buffer containing well-formed locale ID to be
  934. * modified.
  935. * @param bufferCapacity capacity of receiving buffer
  936. * @param status containing error code: e.g. buffer not big enough
  937. * or ill-formed keywordName or keywordValue parameters, or ill-formed
  938. * locale ID in buffer on input.
  939. * @return the length needed for the buffer
  940. * @see uloc_getKeywordValue
  941. * @stable ICU 3.2
  942. */
  943. U_CAPI int32_t U_EXPORT2
  944. uloc_setKeywordValue(const char* keywordName,
  945. const char* keywordValue,
  946. char* buffer, int32_t bufferCapacity,
  947. UErrorCode* status);
  948. /**
  949. * Returns whether the locale's script is written right-to-left.
  950. * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags().
  951. * If no likely script is known, then false is returned.
  952. *
  953. * A script is right-to-left according to the CLDR script metadata
  954. * which corresponds to whether the script's letters have Bidi_Class=R or AL.
  955. *
  956. * Returns true for "ar" and "en-Hebr", false for "zh" and "fa-Cyrl".
  957. *
  958. * @param locale input locale ID
  959. * @return true if the locale's script is written right-to-left
  960. * @stable ICU 54
  961. */
  962. U_CAPI UBool U_EXPORT2
  963. uloc_isRightToLeft(const char *locale);
  964. /**
  965. * enums for the return value for the character and line orientation
  966. * functions.
  967. * @stable ICU 4.0
  968. */
  969. typedef enum {
  970. ULOC_LAYOUT_LTR = 0, /* left-to-right. */
  971. ULOC_LAYOUT_RTL = 1, /* right-to-left. */
  972. ULOC_LAYOUT_TTB = 2, /* top-to-bottom. */
  973. ULOC_LAYOUT_BTT = 3, /* bottom-to-top. */
  974. ULOC_LAYOUT_UNKNOWN
  975. } ULayoutType;
  976. /**
  977. * Get the layout character orientation for the specified locale.
  978. *
  979. * @param localeId locale name
  980. * @param status Error status
  981. * @return an enum indicating the layout orientation for characters.
  982. * @stable ICU 4.0
  983. */
  984. U_CAPI ULayoutType U_EXPORT2
  985. uloc_getCharacterOrientation(const char* localeId,
  986. UErrorCode *status);
  987. /**
  988. * Get the layout line orientation for the specified locale.
  989. *
  990. * @param localeId locale name
  991. * @param status Error status
  992. * @return an enum indicating the layout orientation for lines.
  993. * @stable ICU 4.0
  994. */
  995. U_CAPI ULayoutType U_EXPORT2
  996. uloc_getLineOrientation(const char* localeId,
  997. UErrorCode *status);
  998. /**
  999. * Output values which uloc_acceptLanguage() writes to the 'outResult' parameter.
  1000. *
  1001. * @see uloc_acceptLanguageFromHTTP
  1002. * @see uloc_acceptLanguage
  1003. * @stable ICU 3.2
  1004. */
  1005. typedef enum {
  1006. /**
  1007. * No exact match was found.
  1008. * @stable ICU 3.2
  1009. */
  1010. ULOC_ACCEPT_FAILED = 0,
  1011. /**
  1012. * An exact match was found.
  1013. * @stable ICU 3.2
  1014. */
  1015. ULOC_ACCEPT_VALID = 1,
  1016. /**
  1017. * A fallback was found. For example, the Accept-Language list includes 'ja_JP'
  1018. * and is matched with available locale 'ja'.
  1019. * @stable ICU 3.2
  1020. */
  1021. ULOC_ACCEPT_FALLBACK = 2 /* */
  1022. } UAcceptResult;
  1023. /**
  1024. * Based on a HTTP header from a web browser and a list of available locales,
  1025. * determine an acceptable locale for the user.
  1026. *
  1027. * This is a thin wrapper over C++ class LocaleMatcher.
  1028. *
  1029. * @param result - buffer to accept the result locale
  1030. * @param resultAvailable the size of the result buffer.
  1031. * @param outResult - An out parameter that contains the fallback status
  1032. * @param httpAcceptLanguage - "Accept-Language:" header as per HTTP.
  1033. * @param availableLocales - list of available locales to match
  1034. * @param status ICU error code. Its input value must pass the U_SUCCESS() test,
  1035. * or else the function returns immediately. Check for U_FAILURE()
  1036. * on output or use with function chaining. (See User Guide for details.)
  1037. * @return length needed for the locale.
  1038. * @stable ICU 3.2
  1039. */
  1040. U_CAPI int32_t U_EXPORT2
  1041. uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable,
  1042. UAcceptResult *outResult,
  1043. const char *httpAcceptLanguage,
  1044. UEnumeration* availableLocales,
  1045. UErrorCode *status);
  1046. /**
  1047. * Based on a list of available locales,
  1048. * determine an acceptable locale for the user.
  1049. *
  1050. * This is a thin wrapper over C++ class LocaleMatcher.
  1051. *
  1052. * @param result - buffer to accept the result locale
  1053. * @param resultAvailable the size of the result buffer.
  1054. * @param outResult - An out parameter that contains the fallback status
  1055. * @param acceptList - list of acceptable languages
  1056. * @param acceptListCount - count of acceptList items
  1057. * @param availableLocales - list of available locales to match
  1058. * @param status ICU error code. Its input value must pass the U_SUCCESS() test,
  1059. * or else the function returns immediately. Check for U_FAILURE()
  1060. * on output or use with function chaining. (See User Guide for details.)
  1061. * @return length needed for the locale.
  1062. * @stable ICU 3.2
  1063. */
  1064. U_CAPI int32_t U_EXPORT2
  1065. uloc_acceptLanguage(char *result, int32_t resultAvailable,
  1066. UAcceptResult *outResult, const char **acceptList,
  1067. int32_t acceptListCount,
  1068. UEnumeration* availableLocales,
  1069. UErrorCode *status);
  1070. /**
  1071. * Gets the ICU locale ID for the specified Win32 LCID value.
  1072. *
  1073. * @param hostID the Win32 LCID to translate
  1074. * @param locale the output buffer for the ICU locale ID, which will be NUL-terminated
  1075. * if there is room.
  1076. * @param localeCapacity the size of the output buffer
  1077. * @param status an error is returned if the LCID is unrecognized or the output buffer
  1078. * is too small
  1079. * @return actual the actual size of the locale ID, not including NUL-termination
  1080. * @stable ICU 3.8
  1081. */
  1082. U_CAPI int32_t U_EXPORT2
  1083. uloc_getLocaleForLCID(uint32_t hostID, char *locale, int32_t localeCapacity,
  1084. UErrorCode *status);
  1085. /**
  1086. * Add the likely subtags for a provided locale ID, per the algorithm described
  1087. * in the following CLDR technical report:
  1088. *
  1089. * http://www.unicode.org/reports/tr35/#Likely_Subtags
  1090. *
  1091. * If localeID is already in the maximal form, or there is no data available
  1092. * for maximization, it will be copied to the output buffer. For example,
  1093. * "und-Zzzz" cannot be maximized, since there is no reasonable maximization.
  1094. *
  1095. * Examples:
  1096. *
  1097. * "en" maximizes to "en_Latn_US"
  1098. *
  1099. * "de" maximizes to "de_Latn_US"
  1100. *
  1101. * "sr" maximizes to "sr_Cyrl_RS"
  1102. *
  1103. * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.)
  1104. *
  1105. * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.)
  1106. *
  1107. * @param localeID The locale to maximize
  1108. * @param maximizedLocaleID The maximized locale
  1109. * @param maximizedLocaleIDCapacity The capacity of the maximizedLocaleID buffer
  1110. * @param err Error information if maximizing the locale failed. If the length
  1111. * of the localeID and the null-terminator is greater than the maximum allowed size,
  1112. * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR.
  1113. * @return The actual buffer size needed for the maximized locale. If it's
  1114. * greater than maximizedLocaleIDCapacity, the returned ID will be truncated.
  1115. * On error, the return value is -1.
  1116. * @stable ICU 4.0
  1117. */
  1118. U_CAPI int32_t U_EXPORT2
  1119. uloc_addLikelySubtags(const char* localeID,
  1120. char* maximizedLocaleID,
  1121. int32_t maximizedLocaleIDCapacity,
  1122. UErrorCode* err);
  1123. /**
  1124. * Minimize the subtags for a provided locale ID, per the algorithm described
  1125. * in the following CLDR technical report:
  1126. *
  1127. * http://www.unicode.org/reports/tr35/#Likely_Subtags
  1128. *
  1129. * If localeID is already in the minimal form, or there is no data available
  1130. * for minimization, it will be copied to the output buffer. Since the
  1131. * minimization algorithm relies on proper maximization, see the comments
  1132. * for uloc_addLikelySubtags for reasons why there might not be any data.
  1133. *
  1134. * Examples:
  1135. *
  1136. * "en_Latn_US" minimizes to "en"
  1137. *
  1138. * "de_Latn_US" minimizes to "de"
  1139. *
  1140. * "sr_Cyrl_RS" minimizes to "sr"
  1141. *
  1142. * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the
  1143. * script, and minimizing to "zh" would imply "zh_Hans_CN".)
  1144. *
  1145. * @param localeID The locale to minimize
  1146. * @param minimizedLocaleID The minimized locale
  1147. * @param minimizedLocaleIDCapacity The capacity of the minimizedLocaleID buffer
  1148. * @param err Error information if minimizing the locale failed. If the length
  1149. * of the localeID and the null-terminator is greater than the maximum allowed size,
  1150. * or the localeId is not well-formed, the error code is U_ILLEGAL_ARGUMENT_ERROR.
  1151. * @return The actual buffer size needed for the minimized locale. If it's
  1152. * greater than minimizedLocaleIDCapacity, the returned ID will be truncated.
  1153. * On error, the return value is -1.
  1154. * @stable ICU 4.0
  1155. */
  1156. U_CAPI int32_t U_EXPORT2
  1157. uloc_minimizeSubtags(const char* localeID,
  1158. char* minimizedLocaleID,
  1159. int32_t minimizedLocaleIDCapacity,
  1160. UErrorCode* err);
  1161. /**
  1162. * Returns a locale ID for the specified BCP47 language tag string.
  1163. * If the specified language tag contains any ill-formed subtags,
  1164. * the first such subtag and all following subtags are ignored.
  1165. * <p>
  1166. * This implements the 'Language-Tag' production of BCP 47, and so
  1167. * supports legacy language tags (marked as “Type: grandfathered” in BCP 47)
  1168. * (regular and irregular) as well as private use language tags.
  1169. *
  1170. * Private use tags are represented as 'x-whatever',
  1171. * and legacy tags are converted to their canonical replacements where they exist.
  1172. *
  1173. * Note that a few legacy tags have no modern replacement;
  1174. * these will be converted using the fallback described in
  1175. * the first paragraph, so some information might be lost.
  1176. *
  1177. * @param langtag the input BCP47 language tag.
  1178. * @param localeID the output buffer receiving a locale ID for the
  1179. * specified BCP47 language tag.
  1180. * @param localeIDCapacity the size of the locale ID output buffer.
  1181. * @param parsedLength if not NULL, successfully parsed length
  1182. * for the input language tag is set.
  1183. * @param err error information if receiving the locald ID
  1184. * failed.
  1185. * @return the length of the locale ID.
  1186. * @stable ICU 4.2
  1187. */
  1188. U_CAPI int32_t U_EXPORT2
  1189. uloc_forLanguageTag(const char* langtag,
  1190. char* localeID,
  1191. int32_t localeIDCapacity,
  1192. int32_t* parsedLength,
  1193. UErrorCode* err);
  1194. /**
  1195. * Returns a well-formed language tag for this locale ID.
  1196. * <p>
  1197. * <b>Note</b>: When <code>strict</code> is false, any locale
  1198. * fields which do not satisfy the BCP47 syntax requirement will
  1199. * be omitted from the result. When <code>strict</code> is
  1200. * true, this function sets U_ILLEGAL_ARGUMENT_ERROR to the
  1201. * <code>err</code> if any locale fields do not satisfy the
  1202. * BCP47 syntax requirement.
  1203. * @param localeID the input locale ID
  1204. * @param langtag the output buffer receiving BCP47 language
  1205. * tag for the locale ID.
  1206. * @param langtagCapacity the size of the BCP47 language tag
  1207. * output buffer.
  1208. * @param strict boolean value indicating if the function returns
  1209. * an error for an ill-formed input locale ID.
  1210. * @param err error information if receiving the language
  1211. * tag failed.
  1212. * @return The length of the BCP47 language tag.
  1213. * @stable ICU 4.2
  1214. */
  1215. U_CAPI int32_t U_EXPORT2
  1216. uloc_toLanguageTag(const char* localeID,
  1217. char* langtag,
  1218. int32_t langtagCapacity,
  1219. UBool strict,
  1220. UErrorCode* err);
  1221. /**
  1222. * Converts the specified keyword (legacy key, or BCP 47 Unicode locale
  1223. * extension key) to the equivalent BCP 47 Unicode locale extension key.
  1224. * For example, BCP 47 Unicode locale extension key "co" is returned for
  1225. * the input keyword "collation".
  1226. * <p>
  1227. * When the specified keyword is unknown, but satisfies the BCP syntax,
  1228. * then the pointer to the input keyword itself will be returned.
  1229. * For example,
  1230. * <code>uloc_toUnicodeLocaleKey("ZZ")</code> returns "ZZ".
  1231. *
  1232. * @param keyword the input locale keyword (either legacy key
  1233. * such as "collation" or BCP 47 Unicode locale extension
  1234. * key such as "co").
  1235. * @return the well-formed BCP 47 Unicode locale extension key,
  1236. * or NULL if the specified locale keyword cannot be
  1237. * mapped to a well-formed BCP 47 Unicode locale extension
  1238. * key.
  1239. * @see uloc_toLegacyKey
  1240. * @stable ICU 54
  1241. */
  1242. U_CAPI const char* U_EXPORT2
  1243. uloc_toUnicodeLocaleKey(const char* keyword);
  1244. /**
  1245. * Converts the specified keyword value (legacy type, or BCP 47
  1246. * Unicode locale extension type) to the well-formed BCP 47 Unicode locale
  1247. * extension type for the specified keyword (category). For example, BCP 47
  1248. * Unicode locale extension type "phonebk" is returned for the input
  1249. * keyword value "phonebook", with the keyword "collation" (or "co").
  1250. * <p>
  1251. * When the specified keyword is not recognized, but the specified value
  1252. * satisfies the syntax of the BCP 47 Unicode locale extension type,
  1253. * or when the specified keyword allows 'variable' type and the specified
  1254. * value satisfies the syntax, then the pointer to the input type value itself
  1255. * will be returned.
  1256. * For example,
  1257. * <code>uloc_toUnicodeLocaleType("Foo", "Bar")</code> returns "Bar",
  1258. * <code>uloc_toUnicodeLocaleType("variableTop", "00A4")</code> returns "00A4".
  1259. *
  1260. * @param keyword the locale keyword (either legacy key such as
  1261. * "collation" or BCP 47 Unicode locale extension
  1262. * key such as "co").
  1263. * @param value the locale keyword value (either legacy type
  1264. * such as "phonebook" or BCP 47 Unicode locale extension
  1265. * type such as "phonebk").
  1266. * @return the well-formed BCP47 Unicode locale extension type,
  1267. * or NULL if the locale keyword value cannot be mapped to
  1268. * a well-formed BCP 47 Unicode locale extension type.
  1269. * @see uloc_toLegacyType
  1270. * @stable ICU 54
  1271. */
  1272. U_CAPI const char* U_EXPORT2
  1273. uloc_toUnicodeLocaleType(const char* keyword, const char* value);
  1274. /**
  1275. * Converts the specified keyword (BCP 47 Unicode locale extension key, or
  1276. * legacy key) to the legacy key. For example, legacy key "collation" is
  1277. * returned for the input BCP 47 Unicode locale extension key "co".
  1278. *
  1279. * @param keyword the input locale keyword (either BCP 47 Unicode locale
  1280. * extension key or legacy key).
  1281. * @return the well-formed legacy key, or NULL if the specified
  1282. * keyword cannot be mapped to a well-formed legacy key.
  1283. * @see toUnicodeLocaleKey
  1284. * @stable ICU 54
  1285. */
  1286. U_CAPI const char* U_EXPORT2
  1287. uloc_toLegacyKey(const char* keyword);
  1288. /**
  1289. * Converts the specified keyword value (BCP 47 Unicode locale extension type,
  1290. * or legacy type or type alias) to the canonical legacy type. For example,
  1291. * the legacy type "phonebook" is returned for the input BCP 47 Unicode
  1292. * locale extension type "phonebk" with the keyword "collation" (or "co").
  1293. * <p>
  1294. * When the specified keyword is not recognized, but the specified value
  1295. * satisfies the syntax of legacy key, or when the specified keyword
  1296. * allows 'variable' type and the specified value satisfies the syntax,
  1297. * then the pointer to the input type value itself will be returned.
  1298. * For example,
  1299. * <code>uloc_toLegacyType("Foo", "Bar")</code> returns "Bar",
  1300. * <code>uloc_toLegacyType("vt", "00A4")</code> returns "00A4".
  1301. *
  1302. * @param keyword the locale keyword (either legacy keyword such as
  1303. * "collation" or BCP 47 Unicode locale extension
  1304. * key such as "co").
  1305. * @param value the locale keyword value (either BCP 47 Unicode locale
  1306. * extension type such as "phonebk" or legacy keyword value
  1307. * such as "phonebook").
  1308. * @return the well-formed legacy type, or NULL if the specified
  1309. * keyword value cannot be mapped to a well-formed legacy
  1310. * type.
  1311. * @see toUnicodeLocaleType
  1312. * @stable ICU 54
  1313. */
  1314. U_CAPI const char* U_EXPORT2
  1315. uloc_toLegacyType(const char* keyword, const char* value);
  1316. #endif /*_ULOC*/