uloc.h 55 KB

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