locid.h 31 KB

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