locid.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. // Copyright (C) 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. *
  6. * Copyright (C) 1996-2015, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. *
  11. * File locid.h
  12. *
  13. * Created by: Helena Shih
  14. *
  15. * Modification History:
  16. *
  17. * Date Name Description
  18. * 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
  19. * get and set it.
  20. * 04/02/97 aliu Made operator!= inline; fixed return value of getName().
  21. * 04/15/97 aliu Cleanup for AIX/Win32.
  22. * 04/24/97 aliu Numerous changes per code review.
  23. * 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
  24. * 09/08/98 stephen Moved definition of kEmptyString for Mac Port
  25. * 11/09/99 weiv Added const char * getName() const;
  26. * 04/12/00 srl removing unicodestring api's and cached hash code
  27. * 08/10/01 grhoten Change the static Locales to accessor functions
  28. ******************************************************************************
  29. */
  30. #ifndef LOCID_H
  31. #define LOCID_H
  32. #include "utypes.h"
  33. #include "uobject.h"
  34. #include "unistr.h"
  35. #include "putil.h"
  36. #include "uloc.h"
  37. #include "strenum.h"
  38. /**
  39. * \file
  40. * \brief C++ API: Locale ID object.
  41. */
  42. U_NAMESPACE_BEGIN
  43. // Forward Declarations
  44. void U_CALLCONV locale_available_init(); /**< @internal */
  45. /**
  46. * A <code>Locale</code> object represents a specific geographical, political,
  47. * or cultural region. An operation that requires a <code>Locale</code> to perform
  48. * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
  49. * to tailor information for the user. For example, displaying a number
  50. * is a locale-sensitive operation--the number should be formatted
  51. * according to the customs/conventions of the user's native country,
  52. * region, or culture.
  53. *
  54. * The Locale class is not suitable for subclassing.
  55. *
  56. * <P>
  57. * You can create a <code>Locale</code> object using the constructor in
  58. * this class:
  59. * \htmlonly<blockquote>\endhtmlonly
  60. * <pre>
  61. * Locale( const char* language,
  62. * const char* country,
  63. * const char* variant);
  64. * </pre>
  65. * \htmlonly</blockquote>\endhtmlonly
  66. * The first argument to the constructors is a valid <STRONG>ISO
  67. * Language Code.</STRONG> These codes are the lower-case two-letter
  68. * codes as defined by ISO-639.
  69. * You can find a full list of these codes at:
  70. * <BR><a href ="http://www.loc.gov/standards/iso639-2/">
  71. * http://www.loc.gov/standards/iso639-2/</a>
  72. *
  73. * <P>
  74. * The second argument to the constructors is a valid <STRONG>ISO Country
  75. * Code.</STRONG> These codes are the upper-case two-letter codes
  76. * as defined by ISO-3166.
  77. * You can find a full list of these codes at a number of sites, such as:
  78. * <BR><a href="http://www.iso.org/iso/en/prods-services/iso3166ma/index.html">
  79. * http://www.iso.org/iso/en/prods-services/iso3166ma/index.html</a>
  80. *
  81. * <P>
  82. * The third constructor requires a third argument--the <STRONG>Variant.</STRONG>
  83. * The Variant codes are vendor and browser-specific.
  84. * For example, use REVISED for a langauge's revised script orthography, and POSIX for POSIX.
  85. * Where there are two variants, separate them with an underscore, and
  86. * put the most important one first. For
  87. * example, a Traditional Spanish collation might be referenced, with
  88. * "ES", "ES", "Traditional_POSIX".
  89. *
  90. * <P>
  91. * Because a <code>Locale</code> object is just an identifier for a region,
  92. * no validity check is performed when you construct a <code>Locale</code>.
  93. * If you want to see whether particular resources are available for the
  94. * <code>Locale</code> you construct, you must query those resources. For
  95. * example, ask the <code>NumberFormat</code> for the locales it supports
  96. * using its <code>getAvailableLocales</code> method.
  97. * <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
  98. * locale, you get back the best available match, not necessarily
  99. * precisely what you asked for. For more information, look at
  100. * <code>ResourceBundle</code>.
  101. *
  102. * <P>
  103. * The <code>Locale</code> class provides a number of convenient constants
  104. * that you can use to create <code>Locale</code> objects for commonly used
  105. * locales. For example, the following refers to a <code>Locale</code> object
  106. * for the United States:
  107. * \htmlonly<blockquote>\endhtmlonly
  108. * <pre>
  109. * Locale::getUS()
  110. * </pre>
  111. * \htmlonly</blockquote>\endhtmlonly
  112. *
  113. * <P>
  114. * Once you've created a <code>Locale</code> you can query it for information about
  115. * itself. Use <code>getCountry</code> to get the ISO Country Code and
  116. * <code>getLanguage</code> to get the ISO Language Code. You can
  117. * use <code>getDisplayCountry</code> to get the
  118. * name of the country suitable for displaying to the user. Similarly,
  119. * you can use <code>getDisplayLanguage</code> to get the name of
  120. * the language suitable for displaying to the user. Interestingly,
  121. * the <code>getDisplayXXX</code> methods are themselves locale-sensitive
  122. * and have two versions: one that uses the default locale and one
  123. * that takes a locale as an argument and displays the name or country in
  124. * a language appropriate to that locale.
  125. *
  126. * <P>
  127. * ICU provides a number of classes that perform locale-sensitive
  128. * operations. For example, the <code>NumberFormat</code> class formats
  129. * numbers, currency, or percentages in a locale-sensitive manner. Classes
  130. * such as <code>NumberFormat</code> have a number of convenience methods
  131. * for creating a default object of that type. For example, the
  132. * <code>NumberFormat</code> class provides these three convenience methods
  133. * for creating a default <code>NumberFormat</code> object:
  134. * \htmlonly<blockquote>\endhtmlonly
  135. * <pre>
  136. * UErrorCode success = U_ZERO_ERROR;
  137. * Locale myLocale;
  138. * NumberFormat *nf;
  139. *
  140. * nf = NumberFormat::createInstance( success ); delete nf;
  141. * nf = NumberFormat::createCurrencyInstance( success ); delete nf;
  142. * nf = NumberFormat::createPercentInstance( success ); delete nf;
  143. * </pre>
  144. * \htmlonly</blockquote>\endhtmlonly
  145. * Each of these methods has two variants; one with an explicit locale
  146. * and one without; the latter using the default locale.
  147. * \htmlonly<blockquote>\endhtmlonly
  148. * <pre>
  149. * nf = NumberFormat::createInstance( myLocale, success ); delete nf;
  150. * nf = NumberFormat::createCurrencyInstance( myLocale, success ); delete nf;
  151. * nf = NumberFormat::createPercentInstance( myLocale, success ); delete nf;
  152. * </pre>
  153. * \htmlonly</blockquote>\endhtmlonly
  154. * A <code>Locale</code> is the mechanism for identifying the kind of object
  155. * (<code>NumberFormat</code>) that you would like to get. The locale is
  156. * <STRONG>just</STRONG> a mechanism for identifying objects,
  157. * <STRONG>not</STRONG> a container for the objects themselves.
  158. *
  159. * <P>
  160. * Each class that performs locale-sensitive operations allows you
  161. * to get all the available objects of that type. You can sift
  162. * through these objects by language, country, or variant,
  163. * and use the display names to present a menu to the user.
  164. * For example, you can create a menu of all the collation objects
  165. * suitable for a given language. Such classes implement these
  166. * three class methods:
  167. * \htmlonly<blockquote>\endhtmlonly
  168. * <pre>
  169. * static Locale* getAvailableLocales(int32_t& numLocales)
  170. * static UnicodeString& getDisplayName(const Locale& objectLocale,
  171. * const Locale& displayLocale,
  172. * UnicodeString& displayName)
  173. * static UnicodeString& getDisplayName(const Locale& objectLocale,
  174. * UnicodeString& displayName)
  175. * </pre>
  176. * \htmlonly</blockquote>\endhtmlonly
  177. *
  178. * @stable ICU 2.0
  179. * @see ResourceBundle
  180. */
  181. class U_COMMON_API Locale : public UObject {
  182. public:
  183. /** Useful constant for the Root locale. @stable ICU 4.4 */
  184. static const Locale &U_EXPORT2 getRoot(void);
  185. /** Useful constant for this language. @stable ICU 2.0 */
  186. static const Locale &U_EXPORT2 getEnglish(void);
  187. /** Useful constant for this language. @stable ICU 2.0 */
  188. static const Locale &U_EXPORT2 getFrench(void);
  189. /** Useful constant for this language. @stable ICU 2.0 */
  190. static const Locale &U_EXPORT2 getGerman(void);
  191. /** Useful constant for this language. @stable ICU 2.0 */
  192. static const Locale &U_EXPORT2 getItalian(void);
  193. /** Useful constant for this language. @stable ICU 2.0 */
  194. static const Locale &U_EXPORT2 getJapanese(void);
  195. /** Useful constant for this language. @stable ICU 2.0 */
  196. static const Locale &U_EXPORT2 getKorean(void);
  197. /** Useful constant for this language. @stable ICU 2.0 */
  198. static const Locale &U_EXPORT2 getChinese(void);
  199. /** Useful constant for this language. @stable ICU 2.0 */
  200. static const Locale &U_EXPORT2 getSimplifiedChinese(void);
  201. /** Useful constant for this language. @stable ICU 2.0 */
  202. static const Locale &U_EXPORT2 getTraditionalChinese(void);
  203. /** Useful constant for this country/region. @stable ICU 2.0 */
  204. static const Locale &U_EXPORT2 getFrance(void);
  205. /** Useful constant for this country/region. @stable ICU 2.0 */
  206. static const Locale &U_EXPORT2 getGermany(void);
  207. /** Useful constant for this country/region. @stable ICU 2.0 */
  208. static const Locale &U_EXPORT2 getItaly(void);
  209. /** Useful constant for this country/region. @stable ICU 2.0 */
  210. static const Locale &U_EXPORT2 getJapan(void);
  211. /** Useful constant for this country/region. @stable ICU 2.0 */
  212. static const Locale &U_EXPORT2 getKorea(void);
  213. /** Useful constant for this country/region. @stable ICU 2.0 */
  214. static const Locale &U_EXPORT2 getChina(void);
  215. /** Useful constant for this country/region. @stable ICU 2.0 */
  216. static const Locale &U_EXPORT2 getPRC(void);
  217. /** Useful constant for this country/region. @stable ICU 2.0 */
  218. static const Locale &U_EXPORT2 getTaiwan(void);
  219. /** Useful constant for this country/region. @stable ICU 2.0 */
  220. static const Locale &U_EXPORT2 getUK(void);
  221. /** Useful constant for this country/region. @stable ICU 2.0 */
  222. static const Locale &U_EXPORT2 getUS(void);
  223. /** Useful constant for this country/region. @stable ICU 2.0 */
  224. static const Locale &U_EXPORT2 getCanada(void);
  225. /** Useful constant for this country/region. @stable ICU 2.0 */
  226. static const Locale &U_EXPORT2 getCanadaFrench(void);
  227. /**
  228. * Construct a default locale object, a Locale for the default locale ID.
  229. *
  230. * @see getDefault
  231. * @see uloc_getDefault
  232. * @stable ICU 2.0
  233. */
  234. Locale();
  235. /**
  236. * Construct a locale from language, country, variant.
  237. * If an error occurs, then the constructed object will be "bogus"
  238. * (isBogus() will return TRUE).
  239. *
  240. * @param language Lowercase two-letter or three-letter ISO-639 code.
  241. * This parameter can instead be an ICU style C locale (e.g. "en_US"),
  242. * but the other parameters must not be used.
  243. * This parameter can be NULL; if so,
  244. * the locale is initialized to match the current default locale.
  245. * (This is the same as using the default constructor.)
  246. * Please note: The Java Locale class does NOT accept the form
  247. * 'new Locale("en_US")' but only 'new Locale("en","US")'
  248. *
  249. * @param country Uppercase two-letter ISO-3166 code. (optional)
  250. * @param variant Uppercase vendor and browser specific code. See class
  251. * description. (optional)
  252. * @param keywordsAndValues A string consisting of keyword/values pairs, such as
  253. * "collation=phonebook;currency=euro"
  254. *
  255. * @see getDefault
  256. * @see uloc_getDefault
  257. * @stable ICU 2.0
  258. */
  259. Locale( const char * language,
  260. const char * country = 0,
  261. const char * variant = 0,
  262. const char * keywordsAndValues = 0);
  263. /**
  264. * Initializes a Locale object from another Locale object.
  265. *
  266. * @param other The Locale object being copied in.
  267. * @stable ICU 2.0
  268. */
  269. Locale(const Locale& other);
  270. /**
  271. * Destructor
  272. * @stable ICU 2.0
  273. */
  274. virtual ~Locale() ;
  275. /**
  276. * Replaces the entire contents of *this with the specified value.
  277. *
  278. * @param other The Locale object being copied in.
  279. * @return *this
  280. * @stable ICU 2.0
  281. */
  282. Locale& operator=(const Locale& other);
  283. /**
  284. * Checks if two locale keys are the same.
  285. *
  286. * @param other The locale key object to be compared with this.
  287. * @return True if the two locale keys are the same, false otherwise.
  288. * @stable ICU 2.0
  289. */
  290. UBool operator==(const Locale& other) const;
  291. /**
  292. * Checks if two locale keys are not the same.
  293. *
  294. * @param other The locale key object to be compared with this.
  295. * @return True if the two locale keys are not the same, false
  296. * otherwise.
  297. * @stable ICU 2.0
  298. */
  299. UBool operator!=(const Locale& other) const;
  300. /**
  301. * Clone this object.
  302. * Clones can be used concurrently in multiple threads.
  303. * If an error occurs, then NULL is returned.
  304. * The caller must delete the clone.
  305. *
  306. * @return a clone of this object
  307. *
  308. * @see getDynamicClassID
  309. * @stable ICU 2.8
  310. */
  311. Locale *clone() const;
  312. #ifndef U_HIDE_SYSTEM_API
  313. /**
  314. * Common methods of getting the current default Locale. Used for the
  315. * presentation: menus, dialogs, etc. Generally set once when your applet or
  316. * application is initialized, then never reset. (If you do reset the
  317. * default locale, you probably want to reload your GUI, so that the change
  318. * is reflected in your interface.)
  319. *
  320. * More advanced programs will allow users to use different locales for
  321. * different fields, e.g. in a spreadsheet.
  322. *
  323. * Note that the initial setting will match the host system.
  324. * @return a reference to the Locale object for the default locale ID
  325. * @system
  326. * @stable ICU 2.0
  327. */
  328. static const Locale& U_EXPORT2 getDefault(void);
  329. /**
  330. * Sets the default. Normally set once at the beginning of a process,
  331. * then never reset.
  332. * setDefault() only changes ICU's default locale ID, <strong>not</strong>
  333. * the default locale ID of the runtime environment.
  334. *
  335. * @param newLocale Locale to set to. If NULL, set to the value obtained
  336. * from the runtime environement.
  337. * @param success The error code.
  338. * @system
  339. * @stable ICU 2.0
  340. */
  341. static void U_EXPORT2 setDefault(const Locale& newLocale,
  342. UErrorCode& success);
  343. #endif /* U_HIDE_SYSTEM_API */
  344. /**
  345. * Creates a locale which has had minimal canonicalization
  346. * as per uloc_getName().
  347. * @param name The name to create from. If name is null,
  348. * the default Locale is used.
  349. * @return new locale object
  350. * @stable ICU 2.0
  351. * @see uloc_getName
  352. */
  353. static Locale U_EXPORT2 createFromName(const char *name);
  354. /**
  355. * Creates a locale from the given string after canonicalizing
  356. * the string by calling uloc_canonicalize().
  357. * @param name the locale ID to create from. Must not be NULL.
  358. * @return a new locale object corresponding to the given name
  359. * @stable ICU 3.0
  360. * @see uloc_canonicalize
  361. */
  362. static Locale U_EXPORT2 createCanonical(const char* name);
  363. /**
  364. * Returns the locale's ISO-639 language code.
  365. * @return An alias to the code
  366. * @stable ICU 2.0
  367. */
  368. inline const char * getLanguage( ) const;
  369. /**
  370. * Returns the locale's ISO-15924 abbreviation script code.
  371. * @return An alias to the code
  372. * @see uscript_getShortName
  373. * @see uscript_getCode
  374. * @stable ICU 2.8
  375. */
  376. inline const char * getScript( ) const;
  377. /**
  378. * Returns the locale's ISO-3166 country code.
  379. * @return An alias to the code
  380. * @stable ICU 2.0
  381. */
  382. inline const char * getCountry( ) const;
  383. /**
  384. * Returns the locale's variant code.
  385. * @return An alias to the code
  386. * @stable ICU 2.0
  387. */
  388. inline const char * getVariant( ) const;
  389. /**
  390. * Returns the programmatic name of the entire locale, with the language,
  391. * country and variant separated by underbars. If a field is missing, up
  392. * to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN",
  393. * "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
  394. * @return A pointer to "name".
  395. * @stable ICU 2.0
  396. */
  397. inline const char * getName() const;
  398. /**
  399. * Returns the programmatic name of the entire locale as getName() would return,
  400. * but without keywords.
  401. * @return A pointer to "name".
  402. * @see getName
  403. * @stable ICU 2.8
  404. */
  405. const char * getBaseName() const;
  406. /**
  407. * Gets the list of keywords for the specified locale.
  408. *
  409. * @param status the status code
  410. * @return pointer to StringEnumeration class, or NULL if there are no keywords.
  411. * Client must dispose of it by calling delete.
  412. * @stable ICU 2.8
  413. */
  414. StringEnumeration * createKeywords(UErrorCode &status) const;
  415. /**
  416. * Gets the value for a keyword.
  417. *
  418. * @param keywordName name of the keyword for which we want the value. Case insensitive.
  419. * @param buffer The buffer to receive the keyword value.
  420. * @param bufferCapacity The capacity of receiving buffer
  421. * @param status Returns any error information while performing this operation.
  422. * @return the length of the keyword value
  423. *
  424. * @stable ICU 2.8
  425. */
  426. int32_t getKeywordValue(const char* keywordName, char *buffer, int32_t bufferCapacity, UErrorCode &status) const;
  427. /**
  428. * Sets or removes the value for a keyword.
  429. *
  430. * For removing all keywords, use getBaseName(),
  431. * and construct a new Locale if it differs from getName().
  432. *
  433. * @param keywordName name of the keyword to be set. Case insensitive.
  434. * @param keywordValue value of the keyword to be set. If 0-length or
  435. * NULL, will result in the keyword being removed. No error is given if
  436. * that keyword does not exist.
  437. * @param status Returns any error information while performing this operation.
  438. *
  439. * @stable ICU 49
  440. */
  441. void setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status);
  442. /**
  443. * returns the locale's three-letter language code, as specified
  444. * in ISO draft standard ISO-639-2.
  445. * @return An alias to the code, or an empty string
  446. * @stable ICU 2.0
  447. */
  448. const char * getISO3Language() const;
  449. /**
  450. * Fills in "name" with the locale's three-letter ISO-3166 country code.
  451. * @return An alias to the code, or an empty string
  452. * @stable ICU 2.0
  453. */
  454. const char * getISO3Country() const;
  455. /**
  456. * Returns the Windows LCID value corresponding to this locale.
  457. * This value is stored in the resource data for the locale as a one-to-four-digit
  458. * hexadecimal number. If the resource is missing, in the wrong format, or
  459. * there is no Windows LCID value that corresponds to this locale, returns 0.
  460. * @stable ICU 2.0
  461. */
  462. uint32_t getLCID(void) const;
  463. /**
  464. * Returns whether this locale's script is written right-to-left.
  465. * If there is no script subtag, then the likely script is used, see uloc_addLikelySubtags().
  466. * If no likely script is known, then FALSE is returned.
  467. *
  468. * A script is right-to-left according to the CLDR script metadata
  469. * which corresponds to whether the script's letters have Bidi_Class=R or AL.
  470. *
  471. * Returns TRUE for "ar" and "en-Hebr", FALSE for "zh" and "fa-Cyrl".
  472. *
  473. * @return TRUE if the locale's script is written right-to-left
  474. * @stable ICU 54
  475. */
  476. UBool isRightToLeft() const;
  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