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