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