]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unicode/locid.h
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / locid.h
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
3*
4388f060 4* Copyright (C) 1996-2012, International Business Machines
b75a7d8f
A
5* Corporation and others. All Rights Reserved.
6*
7******************************************************************************
8*
9* File locid.h
10*
11* Created by: Helena Shih
12*
13* Modification History:
14*
15* Date Name Description
16* 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
17* get and set it.
18* 04/02/97 aliu Made operator!= inline; fixed return value of getName().
19* 04/15/97 aliu Cleanup for AIX/Win32.
20* 04/24/97 aliu Numerous changes per code review.
21* 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
22* 09/08/98 stephen Moved definition of kEmptyString for Mac Port
23* 11/09/99 weiv Added const char * getName() const;
24* 04/12/00 srl removing unicodestring api's and cached hash code
25* 08/10/01 grhoten Change the static Locales to accessor functions
26******************************************************************************
27*/
28
29#ifndef LOCID_H
30#define LOCID_H
31
32#include "unicode/utypes.h"
33#include "unicode/uobject.h"
34#include "unicode/unistr.h"
35#include "unicode/putil.h"
36#include "unicode/uloc.h"
374ca955 37#include "unicode/strenum.h"
b75a7d8f
A
38
39/**
40 * \file
41 * \brief C++ API: Locale ID object.
42 */
43
44/**
45 * A <code>Locale</code> object represents a specific geographical, political,
46 * or cultural region. An operation that requires a <code>Locale</code> to perform
47 * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
48 * to tailor information for the user. For example, displaying a number
49 * is a locale-sensitive operation--the number should be formatted
50 * according to the customs/conventions of the user's native country,
51 * region, or culture.
52 *
53 * The Locale class is not suitable for subclassing.
54 *
55 * <P>
374ca955 56 * You can create a <code>Locale</code> object using the constructor in
b75a7d8f 57 * this class:
374ca955 58 * \htmlonly<blockquote>\endhtmlonly
b75a7d8f 59 * <pre>
73c04bcf
A
60 * Locale( const char* language,
61 * const char* country,
62 * const char* variant);
b75a7d8f 63 * </pre>
374ca955 64 * \htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
65 * The first argument to the constructors is a valid <STRONG>ISO
66 * Language Code.</STRONG> These codes are the lower-case two-letter
67 * codes as defined by ISO-639.
374ca955
A
68 * You can find a full list of these codes at:
69 * <BR><a href ="http://www.loc.gov/standards/iso639-2/">
70 * http://www.loc.gov/standards/iso639-2/</a>
b75a7d8f
A
71 *
72 * <P>
73 * The second argument to the constructors is a valid <STRONG>ISO Country
74 * Code.</STRONG> These codes are the upper-case two-letter codes
75 * as defined by ISO-3166.
76 * You can find a full list of these codes at a number of sites, such as:
73c04bcf
A
77 * <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html">
78 * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a>
b75a7d8f
A
79 *
80 * <P>
81 * The third constructor requires a third argument--the <STRONG>Variant.</STRONG>
82 * The Variant codes are vendor and browser-specific.
73c04bcf 83 * For example, use REVISED for a langauge's revised script orthography, and POSIX for POSIX.
b75a7d8f
A
84 * Where there are two variants, separate them with an underscore, and
85 * put the most important one first. For
86 * example, a Traditional Spanish collation might be referenced, with
73c04bcf 87 * "ES", "ES", "Traditional_POSIX".
b75a7d8f
A
88 *
89 * <P>
90 * Because a <code>Locale</code> object is just an identifier for a region,
91 * no validity check is performed when you construct a <code>Locale</code>.
92 * If you want to see whether particular resources are available for the
93 * <code>Locale</code> you construct, you must query those resources. For
94 * example, ask the <code>NumberFormat</code> for the locales it supports
95 * using its <code>getAvailableLocales</code> method.
96 * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
97 * locale, you get back the best available match, not necessarily
98 * precisely what you asked for. For more information, look at
99 * <code>ResourceBundle</code>.
100 *
101 * <P>
102 * The <code>Locale</code> class provides a number of convenient constants
103 * that you can use to create <code>Locale</code> objects for commonly used
104 * locales. For example, the following refers to a <code>Locale</code> object
105 * for the United States:
374ca955 106 * \htmlonly<blockquote>\endhtmlonly
b75a7d8f
A
107 * <pre>
108 * Locale::getUS()
109 * </pre>
374ca955 110 * \htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
111 *
112 * <P>
113 * Once you've created a <code>Locale</code> you can query it for information about
114 * itself. Use <code>getCountry</code> to get the ISO Country Code and
115 * <code>getLanguage</code> to get the ISO Language Code. You can
116 * use <code>getDisplayCountry</code> to get the
117 * name of the country suitable for displaying to the user. Similarly,
118 * you can use <code>getDisplayLanguage</code> to get the name of
119 * the language suitable for displaying to the user. Interestingly,
120 * the <code>getDisplayXXX</code> methods are themselves locale-sensitive
121 * and have two versions: one that uses the default locale and one
122 * that takes a locale as an argument and displays the name or country in
123 * a language appropriate to that locale.
124 *
125 * <P>
374ca955 126 * ICU provides a number of classes that perform locale-sensitive
b75a7d8f
A
127 * operations. For example, the <code>NumberFormat</code> class formats
128 * numbers, currency, or percentages in a locale-sensitive manner. Classes
129 * such as <code>NumberFormat</code> have a number of convenience methods
130 * for creating a default object of that type. For example, the
131 * <code>NumberFormat</code> class provides these three convenience methods
132 * for creating a default <code>NumberFormat</code> object:
374ca955 133 * \htmlonly<blockquote>\endhtmlonly
b75a7d8f
A
134 * <pre>
135 * UErrorCode success = U_ZERO_ERROR;
136 * Locale myLocale;
137 * NumberFormat *nf;
374ca955 138 *
b75a7d8f
A
139 * nf = NumberFormat::createInstance( success ); delete nf;
140 * nf = NumberFormat::createCurrencyInstance( success ); delete nf;
141 * nf = NumberFormat::createPercentInstance( success ); delete nf;
142 * </pre>
374ca955 143 * \htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
144 * Each of these methods has two variants; one with an explicit locale
145 * and one without; the latter using the default locale.
374ca955 146 * \htmlonly<blockquote>\endhtmlonly
b75a7d8f
A
147 * <pre>
148 * nf = NumberFormat::createInstance( myLocale, success ); delete nf;
149 * nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf;
150 * nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf;
151 * </pre>
374ca955 152 * \htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
153 * A <code>Locale</code> is the mechanism for identifying the kind of object
154 * (<code>NumberFormat</code>) that you would like to get. The locale is
155 * <STRONG>just</STRONG> a mechanism for identifying objects,
156 * <STRONG>not</STRONG> a container for the objects themselves.
157 *
158 * <P>
159 * Each class that performs locale-sensitive operations 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:
374ca955 166 * \htmlonly<blockquote>\endhtmlonly
b75a7d8f
A
167 * <pre>
168 * static Locale* getAvailableLocales(int32_t& numLocales)
169 * static UnicodeString& getDisplayName(const Locale& objectLocale,
170 * const Locale& displayLocale,
171 * UnicodeString& displayName)
172 * static UnicodeString& getDisplayName(const Locale& objectLocale,
173 * UnicodeString& displayName)
174 * </pre>
374ca955 175 * \htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
176 *
177 * @stable ICU 2.0
178 * @see ResourceBundle
179 */
180U_NAMESPACE_BEGIN
181class U_COMMON_API Locale : public UObject {
182public:
729e4ab9
A
183 /** Useful constant for the Root locale. @stable ICU 4.4 */
184 static const Locale &U_EXPORT2 getRoot(void);
b75a7d8f 185 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 186 static const Locale &U_EXPORT2 getEnglish(void);
b75a7d8f 187 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 188 static const Locale &U_EXPORT2 getFrench(void);
b75a7d8f 189 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 190 static const Locale &U_EXPORT2 getGerman(void);
b75a7d8f 191 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 192 static const Locale &U_EXPORT2 getItalian(void);
b75a7d8f 193 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 194 static const Locale &U_EXPORT2 getJapanese(void);
b75a7d8f 195 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 196 static const Locale &U_EXPORT2 getKorean(void);
b75a7d8f 197 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 198 static const Locale &U_EXPORT2 getChinese(void);
b75a7d8f 199 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 200 static const Locale &U_EXPORT2 getSimplifiedChinese(void);
b75a7d8f 201 /** Useful constant for this language. @stable ICU 2.0 */
374ca955 202 static const Locale &U_EXPORT2 getTraditionalChinese(void);
b75a7d8f
A
203
204 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 205 static const Locale &U_EXPORT2 getFrance(void);
b75a7d8f 206 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 207 static const Locale &U_EXPORT2 getGermany(void);
b75a7d8f 208 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 209 static const Locale &U_EXPORT2 getItaly(void);
b75a7d8f 210 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 211 static const Locale &U_EXPORT2 getJapan(void);
b75a7d8f 212 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 213 static const Locale &U_EXPORT2 getKorea(void);
b75a7d8f 214 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 215 static const Locale &U_EXPORT2 getChina(void);
b75a7d8f 216 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 217 static const Locale &U_EXPORT2 getPRC(void);
b75a7d8f 218 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 219 static const Locale &U_EXPORT2 getTaiwan(void);
b75a7d8f 220 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 221 static const Locale &U_EXPORT2 getUK(void);
b75a7d8f 222 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 223 static const Locale &U_EXPORT2 getUS(void);
b75a7d8f 224 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 225 static const Locale &U_EXPORT2 getCanada(void);
b75a7d8f 226 /** Useful constant for this country/region. @stable ICU 2.0 */
374ca955 227 static const Locale &U_EXPORT2 getCanadaFrench(void);
b75a7d8f
A
228
229
230 /**
231 * Construct a default locale object, a Locale for the default locale ID.
232 *
233 * @see getDefault
234 * @see uloc_getDefault
235 * @stable ICU 2.0
236 */
374ca955 237 Locale();
b75a7d8f
A
238
239 /**
240 * Construct a locale from language, country, variant.
241 * If an error occurs, then the constructed object will be "bogus"
242 * (isBogus() will return TRUE).
243 *
244 * @param language Lowercase two-letter or three-letter ISO-639 code.
245 * This parameter can instead be an ICU style C locale (e.g. "en_US"),
246 * but the other parameters must not be used.
247 * This parameter can be NULL; if so,
248 * the locale is initialized to match the current default locale.
249 * (This is the same as using the default constructor.)
374ca955 250 * Please note: The Java Locale class does NOT accept the form
b75a7d8f 251 * 'new Locale("en_US")' but only 'new Locale("en","US")'
374ca955 252 *
b75a7d8f
A
253 * @param country Uppercase two-letter ISO-3166 code. (optional)
254 * @param variant Uppercase vendor and browser specific code. See class
255 * description. (optional)
374ca955
A
256 * @param keywordsAndValues A string consisting of keyword/values pairs, such as
257 * "collation=phonebook;currency=euro"
b75a7d8f
A
258 *
259 * @see getDefault
260 * @see uloc_getDefault
261 * @stable ICU 2.0
262 */
263 Locale( const char * language,
374ca955
A
264 const char * country = 0,
265 const char * variant = 0,
266 const char * keywordsAndValues = 0);
b75a7d8f
A
267
268 /**
269 * Initializes a Locale object from another Locale object.
270 *
271 * @param other The Locale object being copied in.
272 * @stable ICU 2.0
273 */
274 Locale(const Locale& other);
275
276
277 /**
278 * Destructor
279 * @stable ICU 2.0
280 */
374ca955 281 virtual ~Locale() ;
b75a7d8f
A
282
283 /**
284 * Replaces the entire contents of *this with the specified value.
285 *
286 * @param other The Locale object being copied in.
287 * @return *this
288 * @stable ICU 2.0
289 */
290 Locale& operator=(const Locale& other);
291
292 /**
293 * Checks if two locale keys are the same.
294 *
295 * @param other The locale key object to be compared with this.
296 * @return True if the two locale keys are the same, false otherwise.
297 * @stable ICU 2.0
298 */
299 UBool operator==(const Locale& other) const;
300
301 /**
302 * Checks if two locale keys are not the same.
303 *
304 * @param other The locale key object to be compared with this.
305 * @return True if the two locale keys are not the same, false
306 * otherwise.
307 * @stable ICU 2.0
308 */
309 UBool operator!=(const Locale& other) const;
310
374ca955
A
311 /**
312 * Clone this object.
313 * Clones can be used concurrently in multiple threads.
314 * If an error occurs, then NULL is returned.
315 * The caller must delete the clone.
316 *
317 * @return a clone of this object
318 *
319 * @see getDynamicClassID
73c04bcf 320 * @stable ICU 2.8
374ca955
A
321 */
322 Locale *clone() const;
323
4388f060 324#ifndef U_HIDE_SYSTEM_API
b75a7d8f
A
325 /**
326 * Common methods of getting the current default Locale. Used for the
327 * presentation: menus, dialogs, etc. Generally set once when your applet or
328 * application is initialized, then never reset. (If you do reset the
329 * default locale, you probably want to reload your GUI, so that the change
330 * is reflected in your interface.)
331 *
332 * More advanced programs will allow users to use different locales for
333 * different fields, e.g. in a spreadsheet.
334 *
335 * Note that the initial setting will match the host system.
336 * @return a reference to the Locale object for the default locale ID
337 * @system
338 * @stable ICU 2.0
339 */
374ca955 340 static const Locale& U_EXPORT2 getDefault(void);
b75a7d8f
A
341
342 /**
343 * Sets the default. Normally set once at the beginning of a process,
344 * then never reset.
345 * setDefault() only changes ICU's default locale ID, <strong>not</strong>
346 * the default locale ID of the runtime environment.
347 *
374ca955
A
348 * @param newLocale Locale to set to. If NULL, set to the value obtained
349 * from the runtime environement.
b75a7d8f
A
350 * @param success The error code.
351 * @system
352 * @stable ICU 2.0
353 */
374ca955
A
354 static void U_EXPORT2 setDefault(const Locale& newLocale,
355 UErrorCode& success);
4388f060 356#endif /* U_HIDE_SYSTEM_API */
b75a7d8f 357
b75a7d8f 358 /**
374ca955
A
359 * Creates a locale which has had minimal canonicalization
360 * as per uloc_getName().
b75a7d8f
A
361 * @param name The name to create from. If name is null,
362 * the default Locale is used.
363 * @return new locale object
364 * @stable ICU 2.0
365 * @see uloc_getName
366 */
374ca955
A
367 static Locale U_EXPORT2 createFromName(const char *name);
368
369 /**
370 * Creates a locale from the given string after canonicalizing
371 * the string by calling uloc_canonicalize().
372 * @param name the locale ID to create from. Must not be NULL.
373 * @return a new locale object corresponding to the given name
73c04bcf 374 * @stable ICU 3.0
374ca955
A
375 * @see uloc_canonicalize
376 */
377 static Locale U_EXPORT2 createCanonical(const char* name);
b75a7d8f 378
b75a7d8f
A
379 /**
380 * Returns the locale's ISO-639 language code.
381 * @return An alias to the code
382 * @stable ICU 2.0
383 */
384 inline const char * getLanguage( ) const;
385
374ca955
A
386 /**
387 * Returns the locale's ISO-15924 abbreviation script code.
388 * @return An alias to the code
389 * @see uscript_getShortName
390 * @see uscript_getCode
73c04bcf 391 * @stable ICU 2.8
374ca955
A
392 */
393 inline const char * getScript( ) const;
394
b75a7d8f
A
395 /**
396 * Returns the locale's ISO-3166 country code.
397 * @return An alias to the code
398 * @stable ICU 2.0
399 */
400 inline const char * getCountry( ) const;
401
402 /**
403 * Returns the locale's variant code.
404 * @return An alias to the code
405 * @stable ICU 2.0
406 */
407 inline const char * getVariant( ) const;
408
409 /**
410 * Returns the programmatic name of the entire locale, with the language,
411 * country and variant separated by underbars. If a field is missing, up
412 * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
413 * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
414 * @return A pointer to "name".
415 * @stable ICU 2.0
416 */
417 inline const char * getName() const;
418
374ca955
A
419 /**
420 * Returns the programmatic name of the entire locale as getName would return,
421 * but without keywords.
422 * @return A pointer to "name".
423 * @see getName
73c04bcf 424 * @stable ICU 2.8
374ca955
A
425 */
426 const char * getBaseName() const;
427
428
429 /**
430 * Gets the list of keywords for the specified locale.
431 *
729e4ab9
A
432 * @param status the status code
433 * @return pointer to StringEnumeration class, or NULL if there are no keywords.
434 * Client must dispose of it by calling delete.
73c04bcf 435 * @stable ICU 2.8
374ca955
A
436 */
437 StringEnumeration * createKeywords(UErrorCode &status) const;
438
439 /**
4388f060 440 * Gets the value for a keyword.
374ca955
A
441 *
442 * @param keywordName name of the keyword for which we want the value. Case insensitive.
374ca955
A
443 * @param buffer The buffer to receive the keyword value.
444 * @param bufferCapacity The capacity of receiving buffer
729e4ab9
A
445 * @param status Returns any error information while performing this operation.
446 * @return the length of the keyword value
374ca955 447 *
73c04bcf 448 * @stable ICU 2.8
374ca955
A
449 */
450 int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
451
4388f060 452#ifndef U_HIDE_DRAFT_API
729e4ab9 453 /**
4388f060 454 * Sets the value for a keyword.
729e4ab9
A
455 *
456 * @param keywordName name of the keyword to be set. Case insensitive.
457 * @param keywordValue value of the keyword to be set. If 0-length or
458 * NULL, will result in the keyword being removed. No error is given if
459 * that keyword does not exist.
460 * @param status Returns any error information while performing this operation.
461 *
4388f060 462 * @draft ICU 49
729e4ab9
A
463 */
464 void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
4388f060 465#endif /* U_HIDE_DRAFT_API */
729e4ab9 466
b75a7d8f
A
467 /**
468 * returns the locale's three-letter language code, as specified
73c04bcf 469 * in ISO draft standard ISO-639-2.
4388f060 470 * @return An alias to the code, or an empty string
b75a7d8f
A
471 * @stable ICU 2.0
472 */
473 const char * getISO3Language() const;
474
475 /**
476 * Fills in "name" with the locale's three-letter ISO-3166 country code.
4388f060 477 * @return An alias to the code, or an empty string
b75a7d8f
A
478 * @stable ICU 2.0
479 */
480 const char * getISO3Country() const;
481
482 /**
483 * Returns the Windows LCID value corresponding to this locale.
484 * This value is stored in the resource data for the locale as a one-to-four-digit
485 * hexadecimal number. If the resource is missing, in the wrong format, or
486 * there is no Windows LCID value that corresponds to this locale, returns 0.
487 * @stable ICU 2.0
488 */
489 uint32_t getLCID(void) const;
490
491 /**
492 * Fills in "dispLang" with the name of this locale's language in a format suitable for
493 * user display in the default locale. For example, if the locale's language code is
494 * "fr" and the default locale's language code is "en", this function would set
495 * dispLang to "French".
496 * @param dispLang Receives the language's display name.
497 * @return A reference to "dispLang".
498 * @stable ICU 2.0
499 */
500 UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
501
502 /**
503 * Fills in "dispLang" with the name of this locale's language in a format suitable for
374ca955
A
504 * user display in the locale specified by "displayLocale". For example, if the locale's
505 * language code is "en" and displayLocale's language code is "fr", this function would set
b75a7d8f 506 * dispLang to "Anglais".
374ca955 507 * @param displayLocale Specifies the locale to be used to display the name. In other words,
b75a7d8f 508 * if the locale's language code is "en", passing Locale::getFrench() for
374ca955
A
509 * displayLocale would result in "Anglais", while passing Locale::getGerman()
510 * for displayLocale would result in "Englisch".
b75a7d8f
A
511 * @param dispLang Receives the language's display name.
512 * @return A reference to "dispLang".
513 * @stable ICU 2.0
514 */
374ca955 515 UnicodeString& getDisplayLanguage( const Locale& displayLocale,
b75a7d8f
A
516 UnicodeString& dispLang) const;
517
374ca955
A
518 /**
519 * Fills in "dispScript" with the name of this locale's script in a format suitable
520 * for user display in the default locale. For example, if the locale's script code
521 * is "LATN" and the default locale's language code is "en", this function would set
522 * dispScript to "Latin".
523 * @param dispScript Receives the scripts's display name.
524 * @return A reference to "dispScript".
73c04bcf 525 * @stable ICU 2.8
374ca955
A
526 */
527 UnicodeString& getDisplayScript( UnicodeString& dispScript) const;
528
529 /**
530 * Fills in "dispScript" with the name of this locale's country in a format suitable
531 * for user display in the locale specified by "displayLocale". For example, if the locale's
532 * script code is "LATN" and displayLocale's language code is "en", this function would set
533 * dispScript to "Latin".
534 * @param displayLocale Specifies the locale to be used to display the name. In other
535 * words, if the locale's script code is "LATN", passing
536 * Locale::getFrench() for displayLocale would result in "", while
537 * passing Locale::getGerman() for displayLocale would result in
538 * "".
539 * @param dispScript Receives the scripts's display name.
540 * @return A reference to "dispScript".
73c04bcf 541 * @stable ICU 2.8
374ca955
A
542 */
543 UnicodeString& getDisplayScript( const Locale& displayLocale,
544 UnicodeString& dispScript) const;
545
b75a7d8f
A
546 /**
547 * Fills in "dispCountry" with the name of this locale's country in a format suitable
548 * for user display in the default locale. For example, if the locale's country code
549 * is "FR" and the default locale's language code is "en", this function would set
550 * dispCountry to "France".
551 * @param dispCountry Receives the country's display name.
552 * @return A reference to "dispCountry".
553 * @stable ICU 2.0
554 */
555 UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
556
557 /**
558 * Fills in "dispCountry" with the name of this locale's country in a format suitable
374ca955
A
559 * for user display in the locale specified by "displayLocale". For example, if the locale's
560 * country code is "US" and displayLocale's language code is "fr", this function would set
73c04bcf 561 * dispCountry to "&Eacute;tats-Unis".
374ca955 562 * @param displayLocale Specifies the locale to be used to display the name. In other
b75a7d8f 563 * words, if the locale's country code is "US", passing
73c04bcf 564 * Locale::getFrench() for displayLocale would result in "&Eacute;tats-Unis", while
374ca955 565 * passing Locale::getGerman() for displayLocale would result in
b75a7d8f
A
566 * "Vereinigte Staaten".
567 * @param dispCountry Receives the country's display name.
568 * @return A reference to "dispCountry".
569 * @stable ICU 2.0
570 */
374ca955 571 UnicodeString& getDisplayCountry( const Locale& displayLocale,
b75a7d8f
A
572 UnicodeString& dispCountry) const;
573
574 /**
575 * Fills in "dispVar" with the name of this locale's variant code in a format suitable
576 * for user display in the default locale.
577 * @param dispVar Receives the variant's name.
578 * @return A reference to "dispVar".
579 * @stable ICU 2.0
580 */
581 UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
582
583 /**
584 * Fills in "dispVar" with the name of this locale's variant code in a format
374ca955
A
585 * suitable for user display in the locale specified by "displayLocale".
586 * @param displayLocale Specifies the locale to be used to display the name.
b75a7d8f
A
587 * @param dispVar Receives the variant's display name.
588 * @return A reference to "dispVar".
589 * @stable ICU 2.0
590 */
374ca955 591 UnicodeString& getDisplayVariant( const Locale& displayLocale,
b75a7d8f
A
592 UnicodeString& dispVar) const;
593
594 /**
374ca955 595 * Fills in "name" with the name of this locale in a format suitable for user display
b75a7d8f
A
596 * in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(),
597 * and getDisplayVariant() to do its work, and outputs the display name in the format
598 * "language (country[,variant])". For example, if the default locale is en_US, then
599 * fr_FR's display name would be "French (France)", and es_MX_Traditional's display name
600 * would be "Spanish (Mexico,Traditional)".
601 * @param name Receives the locale's display name.
602 * @return A reference to "name".
603 * @stable ICU 2.0
604 */
605 UnicodeString& getDisplayName( UnicodeString& name) const;
606
607 /**
374ca955
A
608 * Fills in "name" with the name of this locale in a format suitable for user display
609 * in the locale specfied by "displayLocale". This function uses getDisplayLanguage(),
b75a7d8f 610 * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display
374ca955 611 * name in the format "language (country[,variant])". For example, if displayLocale is
73c04bcf
A
612 * fr_FR, then en_US's display name would be "Anglais (&Eacute;tats-Unis)", and no_NO_NY's
613 * display name would be "norv&eacute;gien (Norv&egrave;ge,NY)".
374ca955 614 * @param displayLocale Specifies the locale to be used to display the name.
b75a7d8f
A
615 * @param name Receives the locale's display name.
616 * @return A reference to "name".
617 * @stable ICU 2.0
618 */
374ca955 619 UnicodeString& getDisplayName( const Locale& displayLocale,
b75a7d8f
A
620 UnicodeString& name) const;
621
622 /**
623 * Generates a hash code for the locale.
624 * @stable ICU 2.0
625 */
626 int32_t hashCode(void) const;
627
374ca955
A
628 /**
629 * Sets the locale to bogus
630 * A bogus locale represents a non-existing locale associated
631 * with services that can be instantiated from non-locale data
632 * in addition to locale (for example, collation can be
633 * instantiated from a locale and from a rule set).
b75a7d8f
A
634 * @stable ICU 2.1
635 */
636 void setToBogus();
637
638 /**
639 * Gets the bogus state. Locale object can be bogus if it doesn't exist
640 * @return FALSE if it is a real locale, TRUE if it is a bogus locale
641 * @stable ICU 2.1
642 */
643 UBool isBogus(void) const;
644
645 /**
646 * Returns a list of all installed locales.
647 * @param count Receives the number of locales in the list.
648 * @return A pointer to an array of Locale objects. This array is the list
649 * of all locales with installed resource files. The called does NOT
650 * get ownership of this list, and must NOT delete it.
651 * @stable ICU 2.0
652 */
374ca955 653 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
b75a7d8f
A
654
655 /**
729e4ab9 656 * Gets a list of all available 2-letter country codes defined in ISO 3166. This is a
b75a7d8f
A
657 * pointer to an array of pointers to arrays of char. All of these pointers are
658 * owned by ICU-- do not delete them, and do not write through them. The array is
659 * terminated with a null pointer.
660 * @return a list of all available country codes
661 * @stable ICU 2.0
662 */
374ca955 663 static const char* const* U_EXPORT2 getISOCountries();
b75a7d8f
A
664
665 /**
666 * Gets a list of all available language codes defined in ISO 639. This is a pointer
667 * to an array of pointers to arrays of char. All of these pointers are owned
668 * by ICU-- do not delete them, and do not write through them. The array is
669 * terminated with a null pointer.
670 * @return a list of all available language codes
671 * @stable ICU 2.0
672 */
374ca955 673 static const char* const* U_EXPORT2 getISOLanguages();
b75a7d8f
A
674
675 /**
374ca955 676 * ICU "poor man's RTTI", returns a UClassID for this class.
b75a7d8f 677 *
374ca955 678 * @stable ICU 2.2
b75a7d8f 679 */
374ca955 680 static UClassID U_EXPORT2 getStaticClassID();
b75a7d8f
A
681
682 /**
374ca955 683 * ICU "poor man's RTTI", returns a UClassID for the actual class.
b75a7d8f 684 *
374ca955 685 * @stable ICU 2.2
b75a7d8f 686 */
374ca955 687 virtual UClassID getDynamicClassID() const;
b75a7d8f
A
688
689protected: /* only protected for testing purposes. DO NOT USE. */
4388f060 690#ifndef U_HIDE_INTERNAL_API
b75a7d8f
A
691 /**
692 * Set this from a single POSIX style locale string.
693 * @internal
694 */
695 void setFromPOSIXID(const char *posixID);
4388f060 696#endif /* U_HIDE_INTERNAL_API */
b75a7d8f
A
697
698private:
699 /**
700 * Initialize the locale object with a new name.
701 * Was deprecated - used in implementation - moved internal
702 *
703 * @param cLocaleID The new locale name.
4388f060 704 * @param canonicalize whether to call uloc_canonicalize on cLocaleID
b75a7d8f 705 */
374ca955 706 Locale& init(const char* cLocaleID, UBool canonicalize);
b75a7d8f
A
707
708 /*
709 * Internal constructor to allow construction of a locale object with
710 * NO side effects. (Default constructor tries to get
711 * the default locale.)
712 */
713 enum ELocaleType {
714 eBOGUS
715 };
716 Locale(ELocaleType);
717
718 /**
719 * Initialize the locale cache for commonly used locales
720 */
721 static Locale *getLocaleCache(void);
722
723 char language[ULOC_LANG_CAPACITY];
374ca955 724 char script[ULOC_SCRIPT_CAPACITY];
b75a7d8f
A
725 char country[ULOC_COUNTRY_CAPACITY];
726 int32_t variantBegin;
727 char* fullName;
728 char fullNameBuffer[ULOC_FULLNAME_CAPACITY];
374ca955
A
729 // name without keywords
730 char* baseName;
731 char baseNameBuffer[ULOC_FULLNAME_CAPACITY];
b75a7d8f
A
732
733 UBool fIsBogus;
734
b75a7d8f
A
735 static const Locale &getLocale(int locid);
736
374ca955
A
737 /**
738 * A friend to allow the default locale to be set by either the C or C++ API.
739 * @internal
740 */
b75a7d8f
A
741 friend void locale_set_default_internal(const char *);
742};
743
b75a7d8f
A
744inline UBool
745Locale::operator!=(const Locale& other) const
746{
747 return !operator==(other);
748}
749
750inline const char *
751Locale::getCountry() const
752{
753 return country;
754}
755
756inline const char *
757Locale::getLanguage() const
758{
759 return language;
760}
761
374ca955
A
762inline const char *
763Locale::getScript() const
764{
765 return script;
766}
767
b75a7d8f
A
768inline const char *
769Locale::getVariant() const
770{
729e4ab9
A
771 getBaseName(); // lazy init
772 return &baseName[variantBegin];
b75a7d8f
A
773}
774
374ca955 775inline const char *
b75a7d8f
A
776Locale::getName() const
777{
778 return fullName;
779}
780
374ca955 781inline UBool
b75a7d8f
A
782Locale::isBogus(void) const {
783 return fIsBogus;
784}
785
786U_NAMESPACE_END
787
788#endif