]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
3 | /* |
4 | ****************************************************************************** | |
5 | * | |
b331163b | 6 | * Copyright (C) 1996-2015, International Business Machines |
b75a7d8f A |
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" | |
b75a7d8f A |
36 | #include "unicode/putil.h" |
37 | #include "unicode/uloc.h" | |
38 | ||
39 | /** | |
40 | * \file | |
41 | * \brief C++ API: Locale ID object. | |
42 | */ | |
43 | ||
f3c0d7a5 | 44 | #if U_SHOW_CPLUSPLUS_API |
51004dcb A |
45 | U_NAMESPACE_BEGIN |
46 | ||
57a6839d A |
47 | // Forward Declarations |
48 | void U_CALLCONV locale_available_init(); /**< @internal */ | |
49 | ||
f3c0d7a5 A |
50 | class StringEnumeration; |
51 | class UnicodeString; | |
52 | ||
b75a7d8f A |
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> | |
374ca955 | 65 | * You can create a <code>Locale</code> object using the constructor in |
b75a7d8f | 66 | * this class: |
374ca955 | 67 | * \htmlonly<blockquote>\endhtmlonly |
b75a7d8f | 68 | * <pre> |
73c04bcf A |
69 | * Locale( const char* language, |
70 | * const char* country, | |
71 | * const char* variant); | |
b75a7d8f | 72 | * </pre> |
374ca955 | 73 | * \htmlonly</blockquote>\endhtmlonly |
b75a7d8f A |
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. | |
374ca955 A |
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> | |
b75a7d8f 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: | |
73c04bcf A |
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> | |
b75a7d8f 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. | |
0f5d89e8 | 92 | * For example, use REVISED for a language's revised script orthography, and POSIX for POSIX. |
b75a7d8f A |
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 | |
73c04bcf | 96 | * "ES", "ES", "Traditional_POSIX". |
b75a7d8f A |
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: | |
374ca955 | 115 | * \htmlonly<blockquote>\endhtmlonly |
b75a7d8f A |
116 | * <pre> |
117 | * Locale::getUS() | |
118 | * </pre> | |
374ca955 | 119 | * \htmlonly</blockquote>\endhtmlonly |
b75a7d8f A |
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> | |
374ca955 | 135 | * ICU provides a number of classes that perform locale-sensitive |
b75a7d8f A |
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: | |
374ca955 | 142 | * \htmlonly<blockquote>\endhtmlonly |
b75a7d8f A |
143 | * <pre> |
144 | * UErrorCode success = U_ZERO_ERROR; | |
145 | * Locale myLocale; | |
146 | * NumberFormat *nf; | |
374ca955 | 147 | * |
b75a7d8f A |
148 | * nf = NumberFormat::createInstance( success ); delete nf; |
149 | * nf = NumberFormat::createCurrencyInstance( success ); delete nf; | |
150 | * nf = NumberFormat::createPercentInstance( success ); delete nf; | |
151 | * </pre> | |
374ca955 | 152 | * \htmlonly</blockquote>\endhtmlonly |
b75a7d8f A |
153 | * Each of these methods has two variants; one with an explicit locale |
154 | * and one without; the latter using the default locale. | |
374ca955 | 155 | * \htmlonly<blockquote>\endhtmlonly |
b75a7d8f A |
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> | |
374ca955 | 161 | * \htmlonly</blockquote>\endhtmlonly |
b75a7d8f A |
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: | |
374ca955 | 175 | * \htmlonly<blockquote>\endhtmlonly |
b75a7d8f A |
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> | |
374ca955 | 184 | * \htmlonly</blockquote>\endhtmlonly |
b75a7d8f A |
185 | * |
186 | * @stable ICU 2.0 | |
187 | * @see ResourceBundle | |
188 | */ | |
b75a7d8f A |
189 | class U_COMMON_API Locale : public UObject { |
190 | public: | |
729e4ab9 A |
191 | /** Useful constant for the Root locale. @stable ICU 4.4 */ |
192 | static const Locale &U_EXPORT2 getRoot(void); | |
b75a7d8f | 193 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 194 | static const Locale &U_EXPORT2 getEnglish(void); |
b75a7d8f | 195 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 196 | static const Locale &U_EXPORT2 getFrench(void); |
b75a7d8f | 197 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 198 | static const Locale &U_EXPORT2 getGerman(void); |
b75a7d8f | 199 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 200 | static const Locale &U_EXPORT2 getItalian(void); |
b75a7d8f | 201 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 202 | static const Locale &U_EXPORT2 getJapanese(void); |
b75a7d8f | 203 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 204 | static const Locale &U_EXPORT2 getKorean(void); |
b75a7d8f | 205 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 206 | static const Locale &U_EXPORT2 getChinese(void); |
b75a7d8f | 207 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 208 | static const Locale &U_EXPORT2 getSimplifiedChinese(void); |
b75a7d8f | 209 | /** Useful constant for this language. @stable ICU 2.0 */ |
374ca955 | 210 | static const Locale &U_EXPORT2 getTraditionalChinese(void); |
b75a7d8f A |
211 | |
212 | /** Useful constant for this country/region. @stable ICU 2.0 */ | |
374ca955 | 213 | static const Locale &U_EXPORT2 getFrance(void); |
b75a7d8f | 214 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 215 | static const Locale &U_EXPORT2 getGermany(void); |
b75a7d8f | 216 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 217 | static const Locale &U_EXPORT2 getItaly(void); |
b75a7d8f | 218 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 219 | static const Locale &U_EXPORT2 getJapan(void); |
b75a7d8f | 220 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 221 | static const Locale &U_EXPORT2 getKorea(void); |
b75a7d8f | 222 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 223 | static const Locale &U_EXPORT2 getChina(void); |
b75a7d8f | 224 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 225 | static const Locale &U_EXPORT2 getPRC(void); |
b75a7d8f | 226 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 227 | static const Locale &U_EXPORT2 getTaiwan(void); |
b75a7d8f | 228 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 229 | static const Locale &U_EXPORT2 getUK(void); |
b75a7d8f | 230 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 231 | static const Locale &U_EXPORT2 getUS(void); |
b75a7d8f | 232 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 233 | static const Locale &U_EXPORT2 getCanada(void); |
b75a7d8f | 234 | /** Useful constant for this country/region. @stable ICU 2.0 */ |
374ca955 | 235 | static const Locale &U_EXPORT2 getCanadaFrench(void); |
b75a7d8f A |
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 | */ | |
374ca955 | 245 | Locale(); |
b75a7d8f A |
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.) | |
374ca955 | 258 | * Please note: The Java Locale class does NOT accept the form |
b75a7d8f | 259 | * 'new Locale("en_US")' but only 'new Locale("en","US")' |
374ca955 | 260 | * |
b75a7d8f A |
261 | * @param country Uppercase two-letter ISO-3166 code. (optional) |
262 | * @param variant Uppercase vendor and browser specific code. See class | |
263 | * description. (optional) | |
374ca955 A |
264 | * @param keywordsAndValues A string consisting of keyword/values pairs, such as |
265 | * "collation=phonebook;currency=euro" | |
b75a7d8f A |
266 | * |
267 | * @see getDefault | |
268 | * @see uloc_getDefault | |
269 | * @stable ICU 2.0 | |
270 | */ | |
271 | Locale( const char * language, | |
374ca955 A |
272 | const char * country = 0, |
273 | const char * variant = 0, | |
274 | const char * keywordsAndValues = 0); | |
b75a7d8f A |
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 | */ | |
374ca955 | 289 | virtual ~Locale() ; |
b75a7d8f A |
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 | ||
374ca955 A |
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 | |
73c04bcf | 328 | * @stable ICU 2.8 |
374ca955 A |
329 | */ |
330 | Locale *clone() const; | |
331 | ||
4388f060 | 332 | #ifndef U_HIDE_SYSTEM_API |
b75a7d8f A |
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 | */ | |
374ca955 | 348 | static const Locale& U_EXPORT2 getDefault(void); |
b75a7d8f A |
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 | * | |
374ca955 | 356 | * @param newLocale Locale to set to. If NULL, set to the value obtained |
0f5d89e8 | 357 | * from the runtime environment. |
b75a7d8f A |
358 | * @param success The error code. |
359 | * @system | |
360 | * @stable ICU 2.0 | |
361 | */ | |
374ca955 A |
362 | static void U_EXPORT2 setDefault(const Locale& newLocale, |
363 | UErrorCode& success); | |
4388f060 | 364 | #endif /* U_HIDE_SYSTEM_API */ |
b75a7d8f | 365 | |
b75a7d8f | 366 | /** |
374ca955 A |
367 | * Creates a locale which has had minimal canonicalization |
368 | * as per uloc_getName(). | |
b75a7d8f A |
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 | */ | |
374ca955 A |
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 | |
73c04bcf | 382 | * @stable ICU 3.0 |
374ca955 A |
383 | * @see uloc_canonicalize |
384 | */ | |
385 | static Locale U_EXPORT2 createCanonical(const char* name); | |
b75a7d8f | 386 | |
b75a7d8f A |
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 | ||
374ca955 A |
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 | |
73c04bcf | 399 | * @stable ICU 2.8 |
374ca955 A |
400 | */ |
401 | inline const char * getScript( ) const; | |
402 | ||
b75a7d8f A |
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 | ||
374ca955 | 427 | /** |
57a6839d | 428 | * Returns the programmatic name of the entire locale as getName() would return, |
374ca955 A |
429 | * but without keywords. |
430 | * @return A pointer to "name". | |
431 | * @see getName | |
73c04bcf | 432 | * @stable ICU 2.8 |
374ca955 A |
433 | */ |
434 | const char * getBaseName() const; | |
435 | ||
436 | ||
437 | /** | |
438 | * Gets the list of keywords for the specified locale. | |
439 | * | |
729e4ab9 A |
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. | |
73c04bcf | 443 | * @stable ICU 2.8 |
374ca955 A |
444 | */ |
445 | StringEnumeration * createKeywords(UErrorCode &status) const; | |
446 | ||
447 | /** | |
4388f060 | 448 | * Gets the value for a keyword. |
374ca955 A |
449 | * |
450 | * @param keywordName name of the keyword for which we want the value. Case insensitive. | |
374ca955 A |
451 | * @param buffer The buffer to receive the keyword value. |
452 | * @param bufferCapacity The capacity of receiving buffer | |
729e4ab9 A |
453 | * @param status Returns any error information while performing this operation. |
454 | * @return the length of the keyword value | |
374ca955 | 455 | * |
73c04bcf | 456 | * @stable ICU 2.8 |
374ca955 A |
457 | */ |
458 | int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const; | |
459 | ||
729e4ab9 | 460 | /** |
57a6839d A |
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(). | |
729e4ab9 A |
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 | * | |
51004dcb | 472 | * @stable ICU 49 |
729e4ab9 A |
473 | */ |
474 | void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status); | |
475 | ||
b75a7d8f A |
476 | /** |
477 | * returns the locale's three-letter language code, as specified | |
73c04bcf | 478 | * in ISO draft standard ISO-639-2. |
4388f060 | 479 | * @return An alias to the code, or an empty string |
b75a7d8f A |
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. | |
4388f060 | 486 | * @return An alias to the code, or an empty string |
b75a7d8f A |
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 | ||
b331163b A |
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 | |
2ca993e8 | 511 | * @stable ICU 54 |
b331163b A |
512 | */ |
513 | UBool isRightToLeft() const; | |
b331163b | 514 | |
b75a7d8f A |
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 | |
374ca955 A |
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 | |
b75a7d8f | 530 | * dispLang to "Anglais". |
374ca955 | 531 | * @param displayLocale Specifies the locale to be used to display the name. In other words, |
b75a7d8f | 532 | * if the locale's language code is "en", passing Locale::getFrench() for |
374ca955 A |
533 | * displayLocale would result in "Anglais", while passing Locale::getGerman() |
534 | * for displayLocale would result in "Englisch". | |
b75a7d8f A |
535 | * @param dispLang Receives the language's display name. |
536 | * @return A reference to "dispLang". | |
537 | * @stable ICU 2.0 | |
538 | */ | |
374ca955 | 539 | UnicodeString& getDisplayLanguage( const Locale& displayLocale, |
b75a7d8f A |
540 | UnicodeString& dispLang) const; |
541 | ||
374ca955 A |
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". | |
73c04bcf | 549 | * @stable ICU 2.8 |
374ca955 A |
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". | |
73c04bcf | 565 | * @stable ICU 2.8 |
374ca955 A |
566 | */ |
567 | UnicodeString& getDisplayScript( const Locale& displayLocale, | |
568 | UnicodeString& dispScript) const; | |
569 | ||
b75a7d8f A |
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 | |
374ca955 A |
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 | |
73c04bcf | 585 | * dispCountry to "États-Unis". |
374ca955 | 586 | * @param displayLocale Specifies the locale to be used to display the name. In other |
b75a7d8f | 587 | * words, if the locale's country code is "US", passing |
73c04bcf | 588 | * Locale::getFrench() for displayLocale would result in "États-Unis", while |
374ca955 | 589 | * passing Locale::getGerman() for displayLocale would result in |
b75a7d8f A |
590 | * "Vereinigte Staaten". |
591 | * @param dispCountry Receives the country's display name. | |
592 | * @return A reference to "dispCountry". | |
593 | * @stable ICU 2.0 | |
594 | */ | |
374ca955 | 595 | UnicodeString& getDisplayCountry( const Locale& displayLocale, |
b75a7d8f A |
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 | |
374ca955 A |
609 | * suitable for user display in the locale specified by "displayLocale". |
610 | * @param displayLocale Specifies the locale to be used to display the name. | |
b75a7d8f A |
611 | * @param dispVar Receives the variant's display name. |
612 | * @return A reference to "dispVar". | |
613 | * @stable ICU 2.0 | |
614 | */ | |
374ca955 | 615 | UnicodeString& getDisplayVariant( const Locale& displayLocale, |
b75a7d8f A |
616 | UnicodeString& dispVar) const; |
617 | ||
618 | /** | |
374ca955 | 619 | * Fills in "name" with the name of this locale in a format suitable for user display |
b75a7d8f A |
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 | /** | |
374ca955 | 632 | * Fills in "name" with the name of this locale in a format suitable for user display |
0f5d89e8 | 633 | * in the locale specified by "displayLocale". This function uses getDisplayLanguage(), |
b75a7d8f | 634 | * getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display |
374ca955 | 635 | * name in the format "language (country[,variant])". For example, if displayLocale is |
73c04bcf A |
636 | * fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's |
637 | * display name would be "norvégien (Norvège,NY)". | |
374ca955 | 638 | * @param displayLocale Specifies the locale to be used to display the name. |
b75a7d8f A |
639 | * @param name Receives the locale's display name. |
640 | * @return A reference to "name". | |
641 | * @stable ICU 2.0 | |
642 | */ | |
374ca955 | 643 | UnicodeString& getDisplayName( const Locale& displayLocale, |
b75a7d8f A |
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 | ||
374ca955 A |
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). | |
b75a7d8f A |
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 | */ | |
374ca955 | 677 | static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); |
b75a7d8f A |
678 | |
679 | /** | |
729e4ab9 | 680 | * Gets a list of all available 2-letter country codes defined in ISO 3166. This is a |
b75a7d8f 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 | */ | |
374ca955 | 687 | static const char* const* U_EXPORT2 getISOCountries(); |
b75a7d8f A |
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 | */ | |
374ca955 | 697 | static const char* const* U_EXPORT2 getISOLanguages(); |
b75a7d8f A |
698 | |
699 | /** | |
374ca955 | 700 | * ICU "poor man's RTTI", returns a UClassID for this class. |
b75a7d8f | 701 | * |
374ca955 | 702 | * @stable ICU 2.2 |
b75a7d8f | 703 | */ |
374ca955 | 704 | static UClassID U_EXPORT2 getStaticClassID(); |
b75a7d8f A |
705 | |
706 | /** | |
374ca955 | 707 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
b75a7d8f | 708 | * |
374ca955 | 709 | * @stable ICU 2.2 |
b75a7d8f | 710 | */ |
374ca955 | 711 | virtual UClassID getDynamicClassID() const; |
b75a7d8f A |
712 | |
713 | protected: /* only protected for testing purposes. DO NOT USE. */ | |
4388f060 | 714 | #ifndef U_HIDE_INTERNAL_API |
b75a7d8f A |
715 | /** |
716 | * Set this from a single POSIX style locale string. | |
717 | * @internal | |
718 | */ | |
719 | void setFromPOSIXID(const char *posixID); | |
4388f060 | 720 | #endif /* U_HIDE_INTERNAL_API */ |
b75a7d8f A |
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. | |
4388f060 | 728 | * @param canonicalize whether to call uloc_canonicalize on cLocaleID |
b75a7d8f | 729 | */ |
374ca955 | 730 | Locale& init(const char* cLocaleID, UBool canonicalize); |
b75a7d8f A |
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]; | |
374ca955 | 748 | char script[ULOC_SCRIPT_CAPACITY]; |
b75a7d8f A |
749 | char country[ULOC_COUNTRY_CAPACITY]; |
750 | int32_t variantBegin; | |
751 | char* fullName; | |
752 | char fullNameBuffer[ULOC_FULLNAME_CAPACITY]; | |
374ca955 A |
753 | // name without keywords |
754 | char* baseName; | |
b331163b | 755 | void initBaseName(UErrorCode& status); |
b75a7d8f A |
756 | |
757 | UBool fIsBogus; | |
758 | ||
b75a7d8f A |
759 | static const Locale &getLocale(int locid); |
760 | ||
374ca955 A |
761 | /** |
762 | * A friend to allow the default locale to be set by either the C or C++ API. | |
763 | * @internal | |
764 | */ | |
51004dcb | 765 | friend Locale *locale_set_default_internal(const char *, UErrorCode& status); |
57a6839d A |
766 | |
767 | /** | |
768 | * @internal | |
769 | */ | |
770 | friend void U_CALLCONV locale_available_init(); | |
b75a7d8f A |
771 | }; |
772 | ||
b75a7d8f A |
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 | ||
374ca955 A |
791 | inline const char * |
792 | Locale::getScript() const | |
793 | { | |
794 | return script; | |
795 | } | |
796 | ||
b75a7d8f A |
797 | inline const char * |
798 | Locale::getVariant() const | |
799 | { | |
729e4ab9 | 800 | return &baseName[variantBegin]; |
b75a7d8f A |
801 | } |
802 | ||
374ca955 | 803 | inline const char * |
b75a7d8f A |
804 | Locale::getName() const |
805 | { | |
806 | return fullName; | |
807 | } | |
808 | ||
374ca955 | 809 | inline UBool |
b75a7d8f A |
810 | Locale::isBogus(void) const { |
811 | return fIsBogus; | |
812 | } | |
813 | ||
814 | U_NAMESPACE_END | |
f3c0d7a5 | 815 | #endif // U_SHOW_CPLUSPLUS_API |
b75a7d8f A |
816 | |
817 | #endif |