]> git.saurik.com Git - apple/javascriptcore.git/blob - icu/unicode/uloc.h
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / icu / unicode / uloc.h
1 /*
2 **********************************************************************
3 * Copyright (C) 1997-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 *
7 * File ULOC.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 04/01/97 aliu Creation.
13 * 08/22/98 stephen JDK 1.2 sync.
14 * 12/08/98 rtg New C API for Locale
15 * 03/30/99 damiba overhaul
16 * 03/31/99 helena Javadoc for uloc functions.
17 * 04/15/99 Madhu Updated Javadoc
18 ********************************************************************************
19 */
20
21 #ifndef ULOC_H
22 #define ULOC_H
23
24 #include "unicode/utypes.h"
25 #include "unicode/uenum.h"
26
27 /**
28 * \file
29 * \brief C API: Locale
30 *
31 * <h2> ULoc C API for Locale </h2>
32 * A <code>Locale</code> represents a specific geographical, political,
33 * or cultural region. An operation that requires a <code>Locale</code> to perform
34 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
35 * to tailor information for the user. For example, displaying a number
36 * is a locale-sensitive operation--the number should be formatted
37 * according to the customs/conventions of the user's native country,
38 * region, or culture. In the C APIs, a locales is simply a const char string.
39 *
40 * <P>
41 * You create a <code>Locale</code> with one of the three options listed below.
42 * Each of the component is separated by '_' in the locale string.
43 * \htmlonly<blockquote>\endhtmlonly
44 * <pre>
45 * \code
46 * newLanguage
47 *
48 * newLanguage + newCountry
49 *
50 * newLanguage + newCountry + newVariant
51 * \endcode
52 * </pre>
53 * \htmlonly</blockquote>\endhtmlonly
54 * The first option is a valid <STRONG>ISO
55 * Language Code.</STRONG> These codes are the lower-case two-letter
56 * codes as defined by ISO-639.
57 * You can find a full list of these codes at a number of sites, such as:
58 * <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt">
59 * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</a>
60 *
61 * <P>
62 * The second option includes an additonal <STRONG>ISO Country
63 * Code.</STRONG> These codes are the upper-case two-letter codes
64 * as defined by ISO-3166.
65 * You can find a full list of these codes at a number of sites, such as:
66 * <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html">
67 * http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</a>
68 *
69 * <P>
70 * The third option requires another additonal information--the
71 * <STRONG>Variant.</STRONG>
72 * The Variant codes are vendor and browser-specific.
73 * For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
74 * Where there are two variants, separate them with an underscore, and
75 * put the most important one first. For
76 * example, a Traditional Spanish collation might be referenced, with
77 * "ES", "ES", "Traditional_WIN".
78 *
79 * <P>
80 * Because a <code>Locale</code> is just an identifier for a region,
81 * no validity check is performed when you specify a <code>Locale</code>.
82 * If you want to see whether particular resources are available for the
83 * <code>Locale</code> you asked for, you must query those resources. For
84 * example, ask the <code>UNumberFormat</code> for the locales it supports
85 * using its <code>getAvailable</code> method.
86 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
87 * locale, you get back the best available match, not necessarily
88 * precisely what you asked for. For more information, look at
89 * <code>UResourceBundle</code>.
90 *
91 * <P>
92 * The <code>Locale</code> provides a number of convenient constants
93 * that you can use to specify the commonly used
94 * locales. For example, the following refers to a locale
95 * for the United States:
96 * \htmlonly<blockquote>\endhtmlonly
97 * <pre>
98 * \code
99 * ULOC_US
100 * \endcode
101 * </pre>
102 * \htmlonly</blockquote>\endhtmlonly
103 *
104 * <P>
105 * Once you've specified a locale you can query it for information about
106 * itself. Use <code>uloc_getCountry</code> to get the ISO Country Code and
107 * <code>uloc_getLanguage</code> to get the ISO Language Code. You can
108 * use <code>uloc_getDisplayCountry</code> to get the
109 * name of the country suitable for displaying to the user. Similarly,
110 * you can use <code>uloc_getDisplayLanguage</code> to get the name of
111 * the language suitable for displaying to the user. Interestingly,
112 * the <code>uloc_getDisplayXXX</code> methods are themselves locale-sensitive
113 * and have two versions: one that uses the default locale and one
114 * that takes a locale as an argument and displays the name or country in
115 * a language appropriate to that locale.
116 *
117 * <P>
118 * The ICU provides a number of services that perform locale-sensitive
119 * operations. For example, the <code>unum_xxx</code> functions format
120 * numbers, currency, or percentages in a locale-sensitive manner.
121 * </P>
122 * \htmlonly<blockquote>\endhtmlonly
123 * <pre>
124 * \code
125 * UErrorCode success = U_ZERO_ERROR;
126 * UNumberFormat *nf;
127 * const char* myLocale = "fr_FR";
128 *
129 * nf = unum_open( UNUM_DEFAULT, NULL, success );
130 * unum_close(nf);
131 * nf = unum_open( UNUM_CURRENCY, NULL, success );
132 * unum_close(nf);
133 * nf = unum_open( UNUM_PERCENT, NULL, success );
134 * unum_close(nf);
135 * \endcode
136 * </pre>
137 * \htmlonly</blockquote>\endhtmlonly
138 * Each of these methods has two variants; one with an explicit locale
139 * and one without; the latter using the default locale.
140 * \htmlonly<blockquote>\endhtmlonly
141 * <pre>
142 * \code
143 *
144 * nf = unum_open( UNUM_DEFAULT, myLocale, success );
145 * unum_close(nf);
146 * nf = unum_open( UNUM_CURRENCY, myLocale, success );
147 * unum_close(nf);
148 * nf = unum_open( UNUM_PERCENT, myLocale, success );
149 * unum_close(nf);
150 * \endcode
151 * </pre>
152 * \htmlonly</blockquote>\endhtmlonly
153 * A <code>Locale</code> is the mechanism for identifying the kind of services
154 * (<code>UNumberFormat</code>) that you would like to get. The locale is
155 * <STRONG>just</STRONG> a mechanism for identifying these services.
156 *
157 * <P>
158 * Each international serivce that performs locale-sensitive operations
159 * allows you
160 * to get all the available objects of that type. You can sift
161 * through these objects by language, country, or variant,
162 * and use the display names to present a menu to the user.
163 * For example, you can create a menu of all the collation objects
164 * suitable for a given language. Such classes implement these
165 * three class methods:
166 * \htmlonly<blockquote>\endhtmlonly
167 * <pre>
168 * \code
169 * const char* uloc_getAvailable(int32_t index);
170 * int32_t uloc_countAvailable();
171 * int32_t
172 * uloc_getDisplayName(const char* localeID,
173 * const char* inLocaleID,
174 * UChar* result,
175 * int32_t maxResultSize,
176 * UErrorCode* err);
177 *
178 * \endcode
179 * </pre>
180 * \htmlonly</blockquote>\endhtmlonly
181 * <P>
182 * Concerning POSIX/RFC1766 Locale IDs,
183 * the getLanguage/getCountry/getVariant/getName functions do understand
184 * the POSIX type form of language_COUNTRY.ENCODING\@VARIANT
185 * and if there is not an ICU-stype variant, uloc_getVariant() for example
186 * will return the one listed after the \@at sign. As well, the hyphen
187 * "-" is recognized as a country/variant separator similarly to RFC1766.
188 * So for example, "en-us" will be interpreted as en_US.
189 * As a result, uloc_getName() is far from a no-op, and will have the
190 * effect of converting POSIX/RFC1766 IDs into ICU form, although it does
191 * NOT map any of the actual codes (i.e. russian->ru) in any way.
192 * Applications should call uloc_getName() at the point where a locale ID
193 * is coming from an external source (user entry, OS, web browser)
194 * and pass the resulting string to other ICU functions. For example,
195 * don't use de-de\@EURO as an argument to resourcebundle.
196 *
197 * @see UResourceBundle
198 */
199
200 /** Useful constant for this language. @stable ICU 2.0 */
201 #define ULOC_CHINESE "zh"
202 /** Useful constant for this language. @stable ICU 2.0 */
203 #define ULOC_ENGLISH "en"
204 /** Useful constant for this language. @stable ICU 2.0 */
205 #define ULOC_FRENCH "fr"
206 /** Useful constant for this language. @stable ICU 2.0 */
207 #define ULOC_GERMAN "de"
208 /** Useful constant for this language. @stable ICU 2.0 */
209 #define ULOC_ITALIAN "it"
210 /** Useful constant for this language. @stable ICU 2.0 */
211 #define ULOC_JAPANESE "ja"
212 /** Useful constant for this language. @stable ICU 2.0 */
213 #define ULOC_KOREAN "ko"
214 /** Useful constant for this language. @stable ICU 2.0 */
215 #define ULOC_SIMPLIFIED_CHINESE "zh_CN"
216 /** Useful constant for this language. @stable ICU 2.0 */
217 #define ULOC_TRADITIONAL_CHINESE "zh_TW"
218
219 /** Useful constant for this country/region. @stable ICU 2.0 */
220 #define ULOC_CANADA "en_CA"
221 /** Useful constant for this country/region. @stable ICU 2.0 */
222 #define ULOC_CANADA_FRENCH "fr_CA"
223 /** Useful constant for this country/region. @stable ICU 2.0 */
224 #define ULOC_CHINA "zh_CN"
225 /** Useful constant for this country/region. @stable ICU 2.0 */
226 #define ULOC_PRC "zh_CN"
227 /** Useful constant for this country/region. @stable ICU 2.0 */
228 #define ULOC_FRANCE "fr_FR"
229 /** Useful constant for this country/region. @stable ICU 2.0 */
230 #define ULOC_GERMANY "de_DE"
231 /** Useful constant for this country/region. @stable ICU 2.0 */
232 #define ULOC_ITALY "it_IT"
233 /** Useful constant for this country/region. @stable ICU 2.0 */
234 #define ULOC_JAPAN "ja_JP"
235 /** Useful constant for this country/region. @stable ICU 2.0 */
236 #define ULOC_KOREA "ko_KR"
237 /** Useful constant for this country/region. @stable ICU 2.0 */
238 #define ULOC_TAIWAN "zh_TW"
239 /** Useful constant for this country/region. @stable ICU 2.0 */
240 #define ULOC_UK "en_GB"
241 /** Useful constant for this country/region. @stable ICU 2.0 */
242 #define ULOC_US "en_US"
243
244 /**
245 * Useful constant for the maximum size of the language part of a locale ID.
246 * (including the terminating NULL).
247 * @stable ICU 2.0
248 */
249 #define ULOC_LANG_CAPACITY 12
250
251 /**
252 * Useful constant for the maximum size of the country part of a locale ID
253 * (including the terminating NULL).
254 * @stable ICU 2.0
255 */
256 #define ULOC_COUNTRY_CAPACITY 4
257 /**
258 * Useful constant for the maximum size of the whole locale ID
259 * (including the terminating NULL).
260 * @stable ICU 2.0
261 */
262 #define ULOC_FULLNAME_CAPACITY 56
263
264
265 #ifndef U_HIDE_DRAFT_API
266
267 /**
268 * Useful constant for the maximum size of the script part of a locale ID
269 * (including the terminating NULL).
270 * @draft ICU 2.8
271 */
272 #define ULOC_SCRIPT_CAPACITY 6
273
274 /**
275 * Useful constant for the maximum size of keywords in a locale
276 * @draft ICU 2.8
277 */
278 #define ULOC_KEYWORDS_CAPACITY 50
279
280 /**
281 * Useful constant for the maximum size of keywords in a locale
282 * @draft ICU 2.8
283 */
284 #define ULOC_KEYWORD_AND_VALUES_CAPACITY 100
285
286 /**
287 * Character separating keywords from the locale string
288 * different for EBCDIC - TODO
289 * @draft ICU 2.8
290 */
291 #define ULOC_KEYWORD_SEPARATOR '@'
292 /**
293 * Character for assigning value to a keyword
294 * @draft ICU 2.8
295 */
296 #define ULOC_KEYWORD_ASSIGN '='
297 /**
298 * Character separating keywords
299 * @draft ICU 2.8
300 */
301 #define ULOC_KEYWORD_ITEM_SEPARATOR ';'
302
303 #endif /*U_HIDE_DRAFT_API*/
304
305 /**
306 * Constants for *_getLocale()
307 * Allow user to select whether she wants information on
308 * requested, valid or actual locale.
309 * For example, a collator for "en_US_CALIFORNIA" was
310 * requested. In the current state of ICU (2.0),
311 * the requested locale is "en_US_CALIFORNIA",
312 * the valid locale is "en_US" (most specific locale supported by ICU)
313 * and the actual locale is "root" (the collation data comes unmodified
314 * from the UCA)
315 * The locale is considered supported by ICU if there is a core ICU bundle
316 * for that locale (although it may be empty).
317 * @stable ICU 2.1
318 */
319 typedef enum {
320 /** This is locale the data actually comes from
321 * @stable ICU 2.1
322 */
323 ULOC_ACTUAL_LOCALE = 0,
324 /** This is the most specific locale supported by ICU
325 * @stable ICU 2.1
326 */
327 ULOC_VALID_LOCALE = 1,
328
329 #ifndef U_HIDE_DEPRECATED_API
330 /** This is the requested locale
331 * @deprecated ICU 2.8
332 */
333 ULOC_REQUESTED_LOCALE = 2,
334 #endif /* U_HIDE_DEPRECATED_API */
335
336 ULOC_DATA_LOCALE_TYPE_LIMIT
337 } ULocDataLocaleType ;
338
339
340 /**
341 * Gets ICU's default locale.
342 * The returned string is a snapshot in time, and will remain valid
343 * and unchanged even when uloc_setDefault() is called.
344 * The returned storage is owned by ICU, and must not be altered or deleted
345 * by the caller.
346 *
347 * @return the ICU default locale
348 * @system
349 * @stable ICU 2.0
350 */
351 U_STABLE const char* U_EXPORT2
352 uloc_getDefault(void);
353
354 /**
355 * Sets ICU's default locale.
356 * By default (without calling this function), ICU's default locale will be based
357 * on information obtained from the underlying system environment.
358 * <p>
359 * Changes to ICU's default locale do not propagate back to the
360 * system environment.
361 * <p>
362 * Changes to ICU's default locale to not affect any ICU services that
363 * may already be open based on the previous default locale value.
364 *
365 * @param localeID the new ICU default locale. A value of NULL will try to get
366 * the system's default locale.
367 * @param status the error information if the setting of default locale fails
368 * @system
369 * @stable ICU 2.0
370 */
371 U_STABLE void U_EXPORT2
372 uloc_setDefault(const char* localeID,
373 UErrorCode* status);
374
375 /**
376 * Gets the language code for the specified locale.
377 *
378 * @param localeID the locale to get the ISO language code with
379 * @param language the language code for localeID
380 * @param languageCapacity the size of the language buffer to store the
381 * language code with
382 * @param err error information if retrieving the language code failed
383 * @return the actual buffer size needed for the language code. If it's greater
384 * than languageCapacity, the returned language code will be truncated.
385 * @stable ICU 2.0
386 */
387 U_STABLE int32_t U_EXPORT2
388 uloc_getLanguage(const char* localeID,
389 char* language,
390 int32_t languageCapacity,
391 UErrorCode* err);
392
393 /**
394 * Gets the script code for the specified locale.
395 *
396 * @param localeID the locale to get the ISO language code with
397 * @param script the language code for localeID
398 * @param scriptCapacity the size of the language buffer to store the
399 * language code with
400 * @param err error information if retrieving the language code failed
401 * @return the actual buffer size needed for the language code. If it's greater
402 * than scriptCapacity, the returned language code will be truncated.
403 * @draft ICU 2.8
404 */
405 U_DRAFT int32_t U_EXPORT2
406 uloc_getScript(const char* localeID,
407 char* script,
408 int32_t scriptCapacity,
409 UErrorCode* err);
410
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_DRAFT int32_t U_EXPORT2
424 uloc_getCountry(const char* localeID,
425 char* country,
426 int32_t countryCapacity,
427 UErrorCode* err);
428
429 /**
430 * Gets the variant code for the specified locale.
431 *
432 * @param localeID the locale to get the variant code with
433 * @param variant the variant code for localeID
434 * @param variantCapacity the size of the variant buffer to store the
435 * variant code with
436 * @param err error information if retrieving the variant code failed
437 * @return the actual buffer size needed for the variant code. If it's greater
438 * than variantCapacity, the returned variant code will be truncated.
439 * @stable ICU 2.0
440 */
441 U_STABLE int32_t U_EXPORT2
442 uloc_getVariant(const char* localeID,
443 char* variant,
444 int32_t variantCapacity,
445 UErrorCode* err);
446
447
448 /**
449 * Gets the full name for the specified locale.
450 * Note: This has the effect of 'canonicalizing' the ICU locale ID to
451 * a certain extent. Upper and lower case are set as needed.
452 * It does NOT map aliased names in any way.
453 * See the top of this header file.
454 * This API supports preflighting.
455 *
456 * @param localeID the locale to get the full name with
457 * @param name fill in buffer for the name without keywords.
458 * @param nameCapacity capacity of the fill in buffer.
459 * @param err error information if retrieving the full name failed
460 * @return the actual buffer size needed for the full name. If it's greater
461 * than nameCapacity, the returned full name will be truncated.
462 * @stable ICU 2.0
463 */
464 U_STABLE int32_t U_EXPORT2
465 uloc_getName(const char* localeID,
466 char* name,
467 int32_t nameCapacity,
468 UErrorCode* err);
469
470 /**
471 * Gets the full name for the specified locale.
472 * Note: This has the effect of 'canonicalizing' the string to
473 * a certain extent. Upper and lower case are set as needed,
474 * and if the components were in 'POSIX' format they are changed to
475 * ICU format. It does NOT map aliased names in any way.
476 * See the top of this header file.
477 *
478 * @param localeID the locale to get the full name with
479 * @param name the full name for localeID
480 * @param nameCapacity the size of the name buffer to store the
481 * full name with
482 * @param err error information if retrieving the full name failed
483 * @return the actual buffer size needed for the full name. If it's greater
484 * than nameCapacity, the returned full name will be truncated.
485 * @draft ICU 2.8
486 */
487 U_DRAFT int32_t U_EXPORT2
488 uloc_canonicalize(const char* localeID,
489 char* name,
490 int32_t nameCapacity,
491 UErrorCode* err);
492
493 /**
494 * Gets the ISO language code for the specified locale.
495 *
496 * @param localeID the locale to get the ISO language code with
497 * @return language the ISO language code for localeID
498 * @stable ICU 2.0
499 */
500 U_STABLE const char* U_EXPORT2
501 uloc_getISO3Language(const char* localeID);
502
503
504 /**
505 * Gets the ISO country code for the specified locale.
506 *
507 * @param localeID the locale to get the ISO country code with
508 * @return country the ISO country code for localeID
509 * @stable ICU 2.0
510 */
511 U_STABLE const char* U_EXPORT2
512 uloc_getISO3Country(const char* localeID);
513
514 /**
515 * Gets the Win32 LCID value for the specified locale.
516 * If the ICU locale is not recognized by Windows, 0 will be returned.
517 *
518 * @param localeID the locale to get the Win32 LCID value with
519 * @return country the Win32 LCID for localeID
520 * @stable ICU 2.0
521 */
522 U_STABLE uint32_t U_EXPORT2
523 uloc_getLCID(const char* localeID);
524
525 /**
526 * Gets the language name suitable for display for the specified locale.
527 *
528 * @param locale the locale to get the ISO language code with
529 * @param displayLocale Specifies the locale to be used to display the name. In other words,
530 * if the locale's language code is "en", passing Locale::getFrench() for
531 * inLocale would result in "Anglais", while passing Locale::getGerman()
532 * for inLocale would result in "Englisch".
533 * @param language the displayable language code for localeID
534 * @param languageCapacity the size of the language buffer to store the
535 * displayable language code with
536 * @param status error information if retrieving the displayable language code failed
537 * @return the actual buffer size needed for the displayable language code. If it's greater
538 * than languageCapacity, the returned language code will be truncated.
539 * @stable ICU 2.0
540 */
541 U_STABLE int32_t U_EXPORT2
542 uloc_getDisplayLanguage(const char* locale,
543 const char* displayLocale,
544 UChar* language,
545 int32_t languageCapacity,
546 UErrorCode* status);
547
548 /**
549 * Gets the script name suitable for display for the specified locale.
550 *
551 * @param locale the locale to get the displayable script code with. NULL may be used to specify the default.
552 * @param displayLocale Specifies the locale to be used to display the name. In other words,
553 * if the locale's language code is "en", passing Locale::getFrench() for
554 * inLocale would result in "", while passing Locale::getGerman()
555 * for inLocale would result in "". NULL may be used to specify the default.
556 * @param script the displayable country code for localeID
557 * @param scriptCapacity the size of the script buffer to store the
558 * displayable script code with
559 * @param status error information if retrieving the displayable script code failed
560 * @return the actual buffer size needed for the displayable script code. If it's greater
561 * than scriptCapacity, the returned displayable script code will be truncated.
562 * @draft ICU 2.8
563 */
564 U_DRAFT int32_t U_EXPORT2
565 uloc_getDisplayScript(const char* locale,
566 const char* displayLocale,
567 UChar* script,
568 int32_t scriptCapacity,
569 UErrorCode* status);
570
571 /**
572 * Gets the country name suitable for display for the specified locale.
573 *
574 * @param locale the locale to get the displayable country code with. NULL may be used to specify the default.
575 * @param displayLocale Specifies the locale to be used to display the name. In other words,
576 * if the locale's language code is "en", passing Locale::getFrench() for
577 * inLocale would result in "Anglais", while passing Locale::getGerman()
578 * for inLocale would result in "Englisch". NULL may be used to specify the default.
579 * @param country the displayable country code for localeID
580 * @param countryCapacity the size of the country buffer to store the
581 * displayable country code with
582 * @param status error information if retrieving the displayable country code failed
583 * @return the actual buffer size needed for the displayable country code. If it's greater
584 * than countryCapacity, the returned displayable country code will be truncated.
585 * @stable ICU 2.0
586 */
587 U_STABLE int32_t U_EXPORT2
588 uloc_getDisplayCountry(const char* locale,
589 const char* displayLocale,
590 UChar* country,
591 int32_t countryCapacity,
592 UErrorCode* status);
593
594
595 /**
596 * Gets the variant name suitable for display for the specified locale.
597 *
598 * @param locale the locale to get the displayable variant code with. NULL may be used to specify the default.
599 * @param displayLocale Specifies the locale to be used to display the name. In other words,
600 * if the locale's language code is "en", passing Locale::getFrench() for
601 * inLocale would result in "Anglais", while passing Locale::getGerman()
602 * for inLocale would result in "Englisch". NULL may be used to specify the default.
603 * @param variant the displayable variant code for localeID
604 * @param variantCapacity the size of the variant buffer to store the
605 * displayable variant code with
606 * @param status error information if retrieving the displayable variant code failed
607 * @return the actual buffer size needed for the displayable variant code. If it's greater
608 * than variantCapacity, the returned displayable variant code will be truncated.
609 * @stable ICU 2.0
610 */
611 U_STABLE int32_t U_EXPORT2
612 uloc_getDisplayVariant(const char* locale,
613 const char* displayLocale,
614 UChar* variant,
615 int32_t variantCapacity,
616 UErrorCode* status);
617
618 /**
619 * Gets the keyword name suitable for display for the specified locale.
620 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
621 * string for the keyword collation.
622 * Usage:
623 * <code>
624 * UErrorCode status = U_ZERO_ERROR;
625 * const char* keyword =NULL;
626 * int32_t keywordLen = 0;
627 * int32_t keywordCount = 0;
628 * UChar displayKeyword[256];
629 * int32_t displayKeywordLen = 0;
630 * UEnumeration* keywordEnum = uloc_openKeywords("de_DE@collation=PHONEBOOK;calendar=TRADITIONAL", &status);
631 * for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
632 * if(U_FAILURE(status)){
633 * ...something went wrong so handle the error...
634 * break;
635 * }
636 * // the uenum_next returns NUL terminated string
637 * keyword = uenum_next(keywordEnum, &keywordLen, &status);
638 * displayKeywordLen = uloc_getDisplayKeyword(keyword, "en_US", displayKeyword, 256);
639 * ... do something interesting .....
640 * }
641 * uenum_close(keywordEnum);
642 * </code>
643 * @param keyword The keyword whose display string needs to be returned.
644 * @param displayLocale Specifies the locale to be used to display the name. In other words,
645 * if the locale's language code is "en", passing Locale::getFrench() for
646 * inLocale would result in "Anglais", while passing Locale::getGerman()
647 * for inLocale would result in "Englisch". NULL may be used to specify the default.
648 * @param dest the buffer to which the displayable keyword should be written.
649 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
650 * dest may be NULL and the function will only return the length of the
651 * result without writing any of the result string (pre-flighting).
652 * @param status error information if retrieving the displayable string failed.
653 * Should not be NULL and should not indicate failure on entry.
654 * @return the actual buffer size needed for the displayable variant code.
655 * @see #uloc_openKeywords
656 * @draft ICU 2.8
657 */
658 U_DRAFT int32_t U_EXPORT2
659 uloc_getDisplayKeyword(const char* keyword,
660 const char* displayLocale,
661 UChar* dest,
662 int32_t destCapacity,
663 UErrorCode* status);
664 /**
665 * Gets the value of the keyword suitable for display for the specified locale.
666 * E.g: for the locale string de_DE\@collation=PHONEBOOK, this API gets the display
667 * string for PHONEBOOK, in the display locale, when "collation" is specified as the keyword.
668 *
669 * @param locale The locale to get the displayable variant code with. NULL may be used to specify the default.
670 * @param keyword The keyword for whose value should be used.
671 * @param displayLocale Specifies the locale to be used to display the name. In other words,
672 * if the locale's language code is "en", passing Locale::getFrench() for
673 * inLocale would result in "Anglais", while passing Locale::getGerman()
674 * for inLocale would result in "Englisch". NULL may be used to specify the default.
675 * @param dest the buffer to which the displayable keyword should be written.
676 * @param destCapacity The size of the buffer (number of UChars). If it is 0, then
677 * dest may be NULL and the function will only return the length of the
678 * result without writing any of the result string (pre-flighting).
679 * @param status error information if retrieving the displayable string failed.
680 * Should not be NULL and must not indicate failure on entry.
681 * @return the actual buffer size needed for the displayable variant code.
682 * @draft ICU 2.8
683 */
684 U_DRAFT int32_t U_EXPORT2
685 uloc_getDisplayKeywordValue( const char* locale,
686 const char* keyword,
687 const char* displayLocale,
688 UChar* dest,
689 int32_t destCapacity,
690 UErrorCode* status);
691 /**
692 * Gets the full name suitable for display for the specified locale.
693 *
694 * @param localeID the locale to get the displayable name with. NULL may be used to specify the default.
695 * @param inLocaleID Specifies the locale to be used to display the name. In other words,
696 * if the locale's language code is "en", passing Locale::getFrench() for
697 * inLocale would result in "Anglais", while passing Locale::getGerman()
698 * for inLocale would result in "Englisch". NULL may be used to specify the default.
699 * @param result the displayable name for localeID
700 * @param maxResultSize the size of the name buffer to store the
701 * displayable full name with
702 * @param err error information if retrieving the displayable name failed
703 * @return the actual buffer size needed for the displayable name. If it's greater
704 * than maxResultSize, the returned displayable name will be truncated.
705 * @stable ICU 2.0
706 */
707 U_STABLE int32_t U_EXPORT2
708 uloc_getDisplayName(const char* localeID,
709 const char* inLocaleID,
710 UChar* result,
711 int32_t maxResultSize,
712 UErrorCode* err);
713
714
715 /**
716 * Gets the specified locale from a list of all available locales.
717 * The return value is a pointer to an item of
718 * a locale name array. Both this array and the pointers
719 * it contains are owned by ICU and should not be deleted or written through
720 * by the caller. The locale name is terminated by a null pointer.
721 * @param n the specific locale name index of the available locale list
722 * @return a specified locale name of all available locales
723 * @stable ICU 2.0
724 */
725 U_STABLE const char* U_EXPORT2
726 uloc_getAvailable(int32_t n);
727
728 /**
729 * Gets the size of the all available locale list.
730 *
731 * @return the size of the locale list
732 * @stable ICU 2.0
733 */
734 U_STABLE int32_t U_EXPORT2 uloc_countAvailable(void);
735
736 /**
737 *
738 * Gets a list of all available language codes defined in ISO 639. This is a pointer
739 * to an array of pointers to arrays of char. All of these pointers are owned
740 * by ICU-- do not delete them, and do not write through them. The array is
741 * terminated with a null pointer.
742 * @return a list of all available language codes
743 * @stable ICU 2.0
744 */
745 U_STABLE const char* const* U_EXPORT2
746 uloc_getISOLanguages(void);
747
748 /**
749 *
750 * Gets a list of all available 2-letter country codes defined in ISO 639. This is a
751 * pointer to an array of pointers to arrays of char. All of these pointers are
752 * owned by ICU-- do not delete them, and do not write through them. The array is
753 * terminated with a null pointer.
754 * @return a list of all available country codes
755 * @stable ICU 2.0
756 */
757 U_STABLE const char* const* U_EXPORT2
758 uloc_getISOCountries(void);
759
760 /**
761 * Truncate the locale ID string to get the parent locale ID.
762 * Copies the part of the string before the last underscore.
763 * The parent locale ID will be an empty string if there is no
764 * underscore, or if there is only one underscore at localeID[0].
765 *
766 * @param localeID Input locale ID string.
767 * @param parent Output string buffer for the parent locale ID.
768 * @param parentCapacity Size of the output buffer.
769 * @param err A UErrorCode value.
770 * @return The length of the parent locale ID.
771 * @stable ICU 2.0
772 */
773 U_STABLE int32_t U_EXPORT2
774 uloc_getParent(const char* localeID,
775 char* parent,
776 int32_t parentCapacity,
777 UErrorCode* err);
778
779
780
781
782 /**
783 * Gets the full name for the specified locale.
784 * Note: This has the effect of 'canonicalizing' the string to
785 * a certain extent. Upper and lower case are set as needed,
786 * and if the components were in 'POSIX' format they are changed to
787 * ICU format. It does NOT map aliased names in any way.
788 * See the top of this header file.
789 * This API strips off the keyword part, so "de_DE\@collation=phonebook"
790 * will become "de_DE".
791 * This API supports preflighting.
792 *
793 * @param localeID the locale to get the full name with
794 * @param name fill in buffer for the name without keywords.
795 * @param nameCapacity capacity of the fill in buffer.
796 * @param err error information if retrieving the full name failed
797 * @return the actual buffer size needed for the full name. If it's greater
798 * than nameCapacity, the returned full name will be truncated.
799 * @draft ICU 2.8
800 */
801 U_DRAFT int32_t U_EXPORT2
802 uloc_getBaseName(const char* localeID,
803 char* name,
804 int32_t nameCapacity,
805 UErrorCode* err);
806
807 /**
808 * Gets an enumeration of keywords for the specified locale. Enumeration
809 * must get disposed of by the client using uenum_close function.
810 *
811 * @param localeID the locale to get the variant code with
812 * @param status error information if retrieving the keywords failed
813 * @return enumeration of keywords or NULL if there are no keywords.
814 * @draft ICU 2.8
815 */
816 U_DRAFT UEnumeration* U_EXPORT2
817 uloc_openKeywords(const char* localeID,
818 UErrorCode* status);
819
820 /**
821 * Get the value for a keyword. Locale name does not need to be normalized.
822 *
823 * @param localeID locale name containing the keyword ("de_DE@currency=EURO;collation=PHONEBOOK")
824 * @param keywordName name of the keyword for which we want the value. Case insensitive.
825 * @param buffer receiving buffer
826 * @param bufferCapacity capacity of receiving buffer
827 * @param status containing error code - buffer not big enough.
828 * @return the length of keyword value
829 * @draft ICU 2.8
830 */
831 U_DRAFT int32_t U_EXPORT2
832 uloc_getKeywordValue(const char* localeID,
833 const char* keywordName,
834 char* buffer, int32_t bufferCapacity,
835 UErrorCode* status);
836
837
838 /**
839 * Set the value of the specified keyword.
840 * NOTE: Unlike almost every other ICU function which takes a
841 * buffer, this function will NOT truncate the output text. If a
842 * BUFFER_OVERFLOW_ERROR is received, it means that the original
843 * buffer is untouched. This is done to prevent incorrect or possibly
844 * even malformed locales from being generated and used.
845 *
846 * @param keywordName name of the keyword to be set. Case insensitive.
847 * @param keywordValue value of the keyword to be set. If 0-length or
848 * NULL, will result in the keyword being removed. No error is given if
849 * that keyword does not exist.
850 * @param buffer input buffer containing locale to be modified.
851 * @param bufferCapacity capacity of receiving buffer
852 * @param status containing error code - buffer not big enough.
853 * @return the length needed for the buffer
854 * @see uloc_getKeywordValue
855 * @draft ICU 3.2
856 */
857 U_DRAFT int32_t U_EXPORT2
858 uloc_setKeywordValue(const char* keywordName,
859 const char* keywordValue,
860 char* buffer, int32_t bufferCapacity,
861 UErrorCode* status);
862
863 /**
864 * enums for the 'outResult' parameter return value
865 * @see uloc_acceptLanguageFromHTTP
866 * @see uloc_acceptLanguage
867 * @draft ICU 3.2
868 */
869 typedef enum {
870 ULOC_ACCEPT_FAILED = 0, /* No exact match was found. */
871 ULOC_ACCEPT_VALID = 1, /* An exact match was found. */
872 ULOC_ACCEPT_FALLBACK = 2 /* A fallback was found, for example,
873 Accept list contained 'ja_JP'
874 which matched available locale 'ja'. */
875 } UAcceptResult;
876
877
878 /**
879 * @param httpAcceptLanguage - "Accept-Language:" header as per HTTP.
880 * @param result - buffer to accept the result locale
881 * @param resultAvailable the size of the result buffer.
882 * @param availableLocales - list of available locales to match
883 * @param status Error status, may be BUFFER_OVERFLOW_ERROR
884 * @return length needed for the locale.
885 * @draft ICU 3.2
886 */
887 U_DRAFT int32_t U_EXPORT2
888 uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable,
889 UAcceptResult *outResult,
890 const char *httpAcceptLanguage,
891 UEnumeration* availableLocales,
892 UErrorCode *status);
893
894 /**
895 * @param acceptList -list of acceptable languages
896 * @param acceptListCount - count of acceptList items
897 * @param result - buffer to accept the result locale
898 * @param resultAvailable the size of the result buffer.
899 * @param availableLocales - list of available locales to match
900 * @param status Error status, may be BUFFER_OVERFLOW_ERROR
901 * @return length needed for the locale.
902 * @draft ICU 3.2
903 */
904 U_DRAFT int32_t U_EXPORT2
905 uloc_acceptLanguage(char *result, int32_t resultAvailable,
906 UAcceptResult *outResult, const char **acceptList,
907 int32_t acceptListCount,
908 UEnumeration* availableLocales,
909 UErrorCode *status);
910
911 /*eof*/
912
913
914 #endif /*_ULOC*/
915
916
917