Locale.hx 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  1. package java.util;
  2. /*
  3. * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * This code is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 only, as
  8. * published by the Free Software Foundation. Oracle designates this
  9. * particular file as subject to the "Classpath" exception as provided
  10. * by Oracle in the LICENSE file that accompanied this code.
  11. *
  12. * This code is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * version 2 for more details (a copy is included in the LICENSE file that
  16. * accompanied this code).
  17. *
  18. * You should have received a copy of the GNU General Public License version
  19. * 2 along with this work; if not, write to the Free Software Foundation,
  20. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23. * or visit www.oracle.com if you need additional information or have any
  24. * questions.
  25. */
  26. /*
  27. * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  28. * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  29. *
  30. * The original version of this source code and documentation
  31. * is copyrighted and owned by Taligent, Inc., a wholly-owned
  32. * subsidiary of IBM. These materials are provided under terms
  33. * of a License Agreement between Taligent and Sun. This technology
  34. * is protected by multiple US and International patents.
  35. *
  36. * This notice and attribution to Taligent may not be removed.
  37. * Taligent is a registered trademark of Taligent, Inc.
  38. *
  39. */
  40. /**
  41. * A <code>Locale</code> object represents a specific geographical, political,
  42. * or cultural region. An operation that requires a <code>Locale</code> to perform
  43. * its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
  44. * to tailor information for the user. For example, displaying a number
  45. * is a locale-sensitive operation&mdash; the number should be formatted
  46. * according to the customs and conventions of the user's native country,
  47. * region, or culture.
  48. *
  49. * <p> The <code>Locale</code> class implements identifiers
  50. * interchangeable with BCP 47 (IETF BCP 47, "Tags for Identifying
  51. * Languages"), with support for the LDML (UTS#35, "Unicode Locale
  52. * Data Markup Language") BCP 47-compatible extensions for locale data
  53. * exchange.
  54. *
  55. * <p> A <code>Locale</code> object logically consists of the fields
  56. * described below.
  57. *
  58. * <dl>
  59. * <dt><a name="def_language"/><b>language</b></dt>
  60. *
  61. * <dd>ISO 639 alpha-2 or alpha-3 language code, or registered
  62. * language subtags up to 8 alpha letters (for future enhancements).
  63. * When a language has both an alpha-2 code and an alpha-3 code, the
  64. * alpha-2 code must be used. You can find a full list of valid
  65. * language codes in the IANA Language Subtag Registry (search for
  66. * "Type: language"). The language field is case insensitive, but
  67. * <code>Locale</code> always canonicalizes to lower case.</dd><br>
  68. *
  69. * <dd>Well-formed language values have the form
  70. * <code>[a-zA-Z]{2,8}</code>. Note that this is not the the full
  71. * BCP47 language production, since it excludes extlang. They are
  72. * not needed since modern three-letter language codes replace
  73. * them.</dd><br>
  74. *
  75. * <dd>Example: "en" (English), "ja" (Japanese), "kok" (Konkani)</dd><br>
  76. *
  77. * <dt><a name="def_script"/><b>script</b></dt>
  78. *
  79. * <dd>ISO 15924 alpha-4 script code. You can find a full list of
  80. * valid script codes in the IANA Language Subtag Registry (search
  81. * for "Type: script"). The script field is case insensitive, but
  82. * <code>Locale</code> always canonicalizes to title case (the first
  83. * letter is upper case and the rest of the letters are lower
  84. * case).</dd><br>
  85. *
  86. * <dd>Well-formed script values have the form
  87. * <code>[a-zA-Z]{4}</code></dd><br>
  88. *
  89. * <dd>Example: "Latn" (Latin), "Cyrl" (Cyrillic)</dd><br>
  90. *
  91. * <dt><a name="def_region"/><b>country (region)</b></dt>
  92. *
  93. * <dd>ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code.
  94. * You can find a full list of valid country and region codes in the
  95. * IANA Language Subtag Registry (search for "Type: region"). The
  96. * country (region) field is case insensitive, but
  97. * <code>Locale</code> always canonicalizes to upper case.</dd><br>
  98. *
  99. * <dd>Well-formed country/region values have
  100. * the form <code>[a-zA-Z]{2} | [0-9]{3}</code></dd><br>
  101. *
  102. * <dd>Example: "US" (United States), "FR" (France), "029"
  103. * (Caribbean)</dd><br>
  104. *
  105. * <dt><a name="def_variant"/><b>variant</b></dt>
  106. *
  107. * <dd>Any arbitrary value used to indicate a variation of a
  108. * <code>Locale</code>. Where there are two or more variant values
  109. * each indicating its own semantics, these values should be ordered
  110. * by importance, with most important first, separated by
  111. * underscore('_'). The variant field is case sensitive.</dd><br>
  112. *
  113. * <dd>Note: IETF BCP 47 places syntactic restrictions on variant
  114. * subtags. Also BCP 47 subtags are strictly used to indicate
  115. * additional variations that define a language or its dialects that
  116. * are not covered by any combinations of language, script and
  117. * region subtags. You can find a full list of valid variant codes
  118. * in the IANA Language Subtag Registry (search for "Type: variant").
  119. *
  120. * <p>However, the variant field in <code>Locale</code> has
  121. * historically been used for any kind of variation, not just
  122. * language variations. For example, some supported variants
  123. * available in Java SE Runtime Environments indicate alternative
  124. * cultural behaviors such as calendar type or number script. In
  125. * BCP 47 this kind of information, which does not identify the
  126. * language, is supported by extension subtags or private use
  127. * subtags.</dd><br>
  128. *
  129. * <dd>Well-formed variant values have the form <code>SUBTAG
  130. * (('_'|'-') SUBTAG)*</code> where <code>SUBTAG =
  131. * [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}</code>. (Note: BCP 47 only
  132. * uses hyphen ('-') as a delimiter, this is more lenient).</dd><br>
  133. *
  134. * <dd>Example: "polyton" (Polytonic Greek), "POSIX"</dd><br>
  135. *
  136. * <dt><a name="def_extensions"/><b>extensions</b></dt>
  137. *
  138. * <dd>A map from single character keys to string values, indicating
  139. * extensions apart from language identification. The extensions in
  140. * <code>Locale</code> implement the semantics and syntax of BCP 47
  141. * extension subtags and private use subtags. The extensions are
  142. * case insensitive, but <code>Locale</code> canonicalizes all
  143. * extension keys and values to lower case. Note that extensions
  144. * cannot have empty values.</dd><br>
  145. *
  146. * <dd>Well-formed keys are single characters from the set
  147. * <code>[0-9a-zA-Z]</code>. Well-formed values have the form
  148. * <code>SUBTAG ('-' SUBTAG)*</code> where for the key 'x'
  149. * <code>SUBTAG = [0-9a-zA-Z]{1,8}</code> and for other keys
  150. * <code>SUBTAG = [0-9a-zA-Z]{2,8}</code> (that is, 'x' allows
  151. * single-character subtags).</dd><br>
  152. *
  153. * <dd>Example: key="u"/value="ca-japanese" (Japanese Calendar),
  154. * key="x"/value="java-1-7"</dd>
  155. * </dl>
  156. *
  157. * <b>Note:</b> Although BCP 47 requires field values to be registered
  158. * in the IANA Language Subtag Registry, the <code>Locale</code> class
  159. * does not provide any validation features. The <code>Builder</code>
  160. * only checks if an individual field satisfies the syntactic
  161. * requirement (is well-formed), but does not validate the value
  162. * itself. See {@link Builder} for details.
  163. *
  164. * <h4><a name="def_locale_extension">Unicode locale/language extension</h4>
  165. *
  166. * <p>UTS#35, "Unicode Locale Data Markup Language" defines optional
  167. * attributes and keywords to override or refine the default behavior
  168. * associated with a locale. A keyword is represented by a pair of
  169. * key and type. For example, "nu-thai" indicates that Thai local
  170. * digits (value:"thai") should be used for formatting numbers
  171. * (key:"nu").
  172. *
  173. * <p>The keywords are mapped to a BCP 47 extension value using the
  174. * extension key 'u' ({@link #UNICODE_LOCALE_EXTENSION}). The above
  175. * example, "nu-thai", becomes the extension "u-nu-thai".code
  176. *
  177. * <p>Thus, when a <code>Locale</code> object contains Unicode locale
  178. * attributes and keywords,
  179. * <code>getExtension(UNICODE_LOCALE_EXTENSION)</code> will return a
  180. * String representing this information, for example, "nu-thai". The
  181. * <code>Locale</code> class also provides {@link
  182. * #getUnicodeLocaleAttributes}, {@link #getUnicodeLocaleKeys}, and
  183. * {@link #getUnicodeLocaleType} which allow you to access Unicode
  184. * locale attributes and key/type pairs directly. When represented as
  185. * a string, the Unicode Locale Extension lists attributes
  186. * alphabetically, followed by key/type sequences with keys listed
  187. * alphabetically (the order of subtags comprising a key's type is
  188. * fixed when the type is defined)
  189. *
  190. * <p>A well-formed locale key has the form
  191. * <code>[0-9a-zA-Z]{2}</code>. A well-formed locale type has the
  192. * form <code>"" | [0-9a-zA-Z]{3,8} ('-' [0-9a-zA-Z]{3,8})*</code> (it
  193. * can be empty, or a series of subtags 3-8 alphanums in length). A
  194. * well-formed locale attribute has the form
  195. * <code>[0-9a-zA-Z]{3,8}</code> (it is a single subtag with the same
  196. * form as a locale type subtag).
  197. *
  198. * <p>The Unicode locale extension specifies optional behavior in
  199. * locale-sensitive services. Although the LDML specification defines
  200. * various keys and values, actual locale-sensitive service
  201. * implementations in a Java Runtime Environment might not support any
  202. * particular Unicode locale attributes or key/type pairs.
  203. *
  204. * <h4>Creating a Locale</h4>
  205. *
  206. * <p>There are several different ways to create a <code>Locale</code>
  207. * object.
  208. *
  209. * <h5>Builder</h5>
  210. *
  211. * <p>Using {@link Builder} you can construct a <code>Locale</code> object
  212. * that conforms to BCP 47 syntax.
  213. *
  214. * <h5>Constructors</h5>
  215. *
  216. * <p>The <code>Locale</code> class provides three constructors:
  217. * <blockquote>
  218. * <pre>
  219. * {@link #Locale(String language)}
  220. * {@link #Locale(String language, String country)}
  221. * {@link #Locale(String language, String country, String variant)}
  222. * </pre>
  223. * </blockquote>
  224. * These constructors allow you to create a <code>Locale</code> object
  225. * with language, country and variant, but you cannot specify
  226. * script or extensions.
  227. *
  228. * <h5>Factory Methods</h5>
  229. *
  230. * <p>The method {@link #forLanguageTag} creates a <code>Locale</code>
  231. * object for a well-formed BCP 47 language tag.
  232. *
  233. * <h5>Locale Constants</h5>
  234. *
  235. * <p>The <code>Locale</code> class provides a number of convenient constants
  236. * that you can use to create <code>Locale</code> objects for commonly used
  237. * locales. For example, the following creates a <code>Locale</code> object
  238. * for the United States:
  239. * <blockquote>
  240. * <pre>
  241. * Locale.US
  242. * </pre>
  243. * </blockquote>
  244. *
  245. * <h4>Use of Locale</h4>
  246. *
  247. * <p>Once you've created a <code>Locale</code> you can query it for information
  248. * about itself. Use <code>getCountry</code> to get the country (or region)
  249. * code and <code>getLanguage</code> to get the language code.
  250. * You can use <code>getDisplayCountry</code> to get the
  251. * name of the country suitable for displaying to the user. Similarly,
  252. * you can use <code>getDisplayLanguage</code> to get the name of
  253. * the language suitable for displaying to the user. Interestingly,
  254. * the <code>getDisplayXXX</code> methods are themselves locale-sensitive
  255. * and have two versions: one that uses the default locale and one
  256. * that uses the locale specified as an argument.
  257. *
  258. * <p>The Java Platform provides a number of classes that perform locale-sensitive
  259. * operations. For example, the <code>NumberFormat</code> class formats
  260. * numbers, currency, and percentages in a locale-sensitive manner. Classes
  261. * such as <code>NumberFormat</code> have several convenience methods
  262. * for creating a default object of that type. For example, the
  263. * <code>NumberFormat</code> class provides these three convenience methods
  264. * for creating a default <code>NumberFormat</code> object:
  265. * <blockquote>
  266. * <pre>
  267. * NumberFormat.getInstance()
  268. * NumberFormat.getCurrencyInstance()
  269. * NumberFormat.getPercentInstance()
  270. * </pre>
  271. * </blockquote>
  272. * Each of these methods has two variants; one with an explicit locale
  273. * and one without; the latter uses the default locale:
  274. * <blockquote>
  275. * <pre>
  276. * NumberFormat.getInstance(myLocale)
  277. * NumberFormat.getCurrencyInstance(myLocale)
  278. * NumberFormat.getPercentInstance(myLocale)
  279. * </pre>
  280. * </blockquote>
  281. * A <code>Locale</code> is the mechanism for identifying the kind of object
  282. * (<code>NumberFormat</code>) that you would like to get. The locale is
  283. * <STRONG>just</STRONG> a mechanism for identifying objects,
  284. * <STRONG>not</STRONG> a container for the objects themselves.
  285. *
  286. * <h4>Compatibility</h4>
  287. *
  288. * <p>In order to maintain compatibility with existing usage, Locale's
  289. * constructors retain their behavior prior to the Java Runtime
  290. * Environment version 1.7. The same is largely true for the
  291. * <code>toString</code> method. Thus Locale objects can continue to
  292. * be used as they were. In particular, clients who parse the output
  293. * of toString into language, country, and variant fields can continue
  294. * to do so (although this is strongly discouraged), although the
  295. * variant field will have additional information in it if script or
  296. * extensions are present.
  297. *
  298. * <p>In addition, BCP 47 imposes syntax restrictions that are not
  299. * imposed by Locale's constructors. This means that conversions
  300. * between some Locales and BCP 47 language tags cannot be made without
  301. * losing information. Thus <code>toLanguageTag</code> cannot
  302. * represent the state of locales whose language, country, or variant
  303. * do not conform to BCP 47.
  304. *
  305. * <p>Because of these issues, it is recommended that clients migrate
  306. * away from constructing non-conforming locales and use the
  307. * <code>forLanguageTag</code> and <code>Locale.Builder</code> APIs instead.
  308. * Clients desiring a string representation of the complete locale can
  309. * then always rely on <code>toLanguageTag</code> for this purpose.
  310. *
  311. * <h5><a name="special_cases_constructor"/>Special cases</h5>
  312. *
  313. * <p>For compatibility reasons, two
  314. * non-conforming locales are treated as special cases. These are
  315. * <b><tt>ja_JP_JP</tt></b> and <b><tt>th_TH_TH</tt></b>. These are ill-formed
  316. * in BCP 47 since the variants are too short. To ease migration to BCP 47,
  317. * these are treated specially during construction. These two cases (and only
  318. * these) cause a constructor to generate an extension, all other values behave
  319. * exactly as they did prior to Java 7.
  320. *
  321. * <p>Java has used <tt>ja_JP_JP</tt> to represent Japanese as used in
  322. * Japan together with the Japanese Imperial calendar. This is now
  323. * representable using a Unicode locale extension, by specifying the
  324. * Unicode locale key <tt>ca</tt> (for "calendar") and type
  325. * <tt>japanese</tt>. When the Locale constructor is called with the
  326. * arguments "ja", "JP", "JP", the extension "u-ca-japanese" is
  327. * automatically added.
  328. *
  329. * <p>Java has used <tt>th_TH_TH</tt> to represent Thai as used in
  330. * Thailand together with Thai digits. This is also now representable using
  331. * a Unicode locale extension, by specifying the Unicode locale key
  332. * <tt>nu</tt> (for "number") and value <tt>thai</tt>. When the Locale
  333. * constructor is called with the arguments "th", "TH", "TH", the
  334. * extension "u-nu-thai" is automatically added.
  335. *
  336. * <h5>Serialization</h5>
  337. *
  338. * <p>During serialization, writeObject writes all fields to the output
  339. * stream, including extensions.
  340. *
  341. * <p>During deserialization, readResolve adds extensions as described
  342. * in <a href="#special_cases_constructor">Special Cases</a>, only
  343. * for the two cases th_TH_TH and ja_JP_JP.
  344. *
  345. * <h5>Legacy language codes</h5>
  346. *
  347. * <p>Locale's constructor has always converted three language codes to
  348. * their earlier, obsoleted forms: <tt>he</tt> maps to <tt>iw</tt>,
  349. * <tt>yi</tt> maps to <tt>ji</tt>, and <tt>id</tt> maps to
  350. * <tt>in</tt>. This continues to be the case, in order to not break
  351. * backwards compatibility.
  352. *
  353. * <p>The APIs added in 1.7 map between the old and new language codes,
  354. * maintaining the old codes internal to Locale (so that
  355. * <code>getLanguage</code> and <code>toString</code> reflect the old
  356. * code), but using the new codes in the BCP 47 language tag APIs (so
  357. * that <code>toLanguageTag</code> reflects the new one). This
  358. * preserves the equivalence between Locales no matter which code or
  359. * API is used to construct them. Java's default resource bundle
  360. * lookup mechanism also implements this mapping, so that resources
  361. * can be named using either convention, see {@link ResourceBundle.Control}.
  362. *
  363. * <h5>Three-letter language/country(region) codes</h5>
  364. *
  365. * <p>The Locale constructors have always specified that the language
  366. * and the country param be two characters in length, although in
  367. * practice they have accepted any length. The specification has now
  368. * been relaxed to allow language codes of two to eight characters and
  369. * country (region) codes of two to three characters, and in
  370. * particular, three-letter language codes and three-digit region
  371. * codes as specified in the IANA Language Subtag Registry. For
  372. * compatibility, the implementation still does not impose a length
  373. * constraint.
  374. *
  375. * @see Builder
  376. * @see ResourceBundle
  377. * @see java.text.Format
  378. * @see java.text.NumberFormat
  379. * @see java.text.Collator
  380. * @author Mark Davis
  381. * @since 1.1
  382. */
  383. @:require(java1) extern class Locale implements java.lang.Cloneable implements java.io.Serializable
  384. {
  385. /** Useful constant for language.
  386. */
  387. public static var ENGLISH(default, null) : Locale;
  388. /** Useful constant for language.
  389. */
  390. public static var FRENCH(default, null) : Locale;
  391. /** Useful constant for language.
  392. */
  393. public static var GERMAN(default, null) : Locale;
  394. /** Useful constant for language.
  395. */
  396. public static var ITALIAN(default, null) : Locale;
  397. /** Useful constant for language.
  398. */
  399. public static var JAPANESE(default, null) : Locale;
  400. /** Useful constant for language.
  401. */
  402. public static var KOREAN(default, null) : Locale;
  403. /** Useful constant for language.
  404. */
  405. public static var CHINESE(default, null) : Locale;
  406. /** Useful constant for language.
  407. */
  408. public static var SIMPLIFIED_CHINESE(default, null) : Locale;
  409. /** Useful constant for language.
  410. */
  411. public static var TRADITIONAL_CHINESE(default, null) : Locale;
  412. /** Useful constant for country.
  413. */
  414. public static var FRANCE(default, null) : Locale;
  415. /** Useful constant for country.
  416. */
  417. public static var GERMANY(default, null) : Locale;
  418. /** Useful constant for country.
  419. */
  420. public static var ITALY(default, null) : Locale;
  421. /** Useful constant for country.
  422. */
  423. public static var JAPAN(default, null) : Locale;
  424. /** Useful constant for country.
  425. */
  426. public static var KOREA(default, null) : Locale;
  427. /** Useful constant for country.
  428. */
  429. public static var CHINA(default, null) : Locale;
  430. /** Useful constant for country.
  431. */
  432. public static var PRC(default, null) : Locale;
  433. /** Useful constant for country.
  434. */
  435. public static var TAIWAN(default, null) : Locale;
  436. /** Useful constant for country.
  437. */
  438. public static var UK(default, null) : Locale;
  439. /** Useful constant for country.
  440. */
  441. public static var US(default, null) : Locale;
  442. /** Useful constant for country.
  443. */
  444. public static var CANADA(default, null) : Locale;
  445. /** Useful constant for country.
  446. */
  447. public static var CANADA_FRENCH(default, null) : Locale;
  448. /**
  449. * Useful constant for the root locale. The root locale is the locale whose
  450. * language, country, and variant are empty ("") strings. This is regarded
  451. * as the base locale of all locales, and is used as the language/country
  452. * neutral locale for the locale sensitive operations.
  453. *
  454. * @since 1.6
  455. */
  456. @:require(java6) public static var ROOT(default, null) : Locale;
  457. /**
  458. * The key for the private use extension ('x').
  459. *
  460. * @see #getExtension(char)
  461. * @see Builder#setExtension(char, String)
  462. * @since 1.7
  463. */
  464. @:require(java7) public static var PRIVATE_USE_EXTENSION(default, null) : java.StdTypes.Char16;
  465. /**
  466. * The key for Unicode locale extension ('u').
  467. *
  468. * @see #getExtension(char)
  469. * @see Builder#setExtension(char, String)
  470. * @since 1.7
  471. */
  472. @:require(java7) public static var UNICODE_LOCALE_EXTENSION(default, null) : java.StdTypes.Char16;
  473. /**
  474. * Construct a locale from language, country and variant.
  475. * This constructor normalizes the language value to lowercase and
  476. * the country value to uppercase.
  477. * <p>
  478. * <b>Note:</b>
  479. * <ul>
  480. * <li>ISO 639 is not a stable standard; some of the language codes it defines
  481. * (specifically "iw", "ji", and "in") have changed. This constructor accepts both the
  482. * old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other
  483. * API on Locale will return only the OLD codes.
  484. * <li>For backward compatibility reasons, this constructor does not make
  485. * any syntactic checks on the input.
  486. * <li>The two cases ("ja", "JP", "JP") and ("th", "TH", "TH") are handled specially,
  487. * see <a href="#special_cases_constructor">Special Cases</a> for more information.
  488. * </ul>
  489. *
  490. * @param language An ISO 639 alpha-2 or alpha-3 language code, or a language subtag
  491. * up to 8 characters in length. See the <code>Locale</code> class description about
  492. * valid language values.
  493. * @param country An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code.
  494. * See the <code>Locale</code> class description about valid country values.
  495. * @param variant Any arbitrary value used to indicate a variation of a <code>Locale</code>.
  496. * See the <code>Locale</code> class description for the details.
  497. * @exception NullPointerException thrown if any argument is null.
  498. */
  499. @:overload public function new(language : String, country : String, variant : String) : Void;
  500. /**
  501. * Construct a locale from language and country.
  502. * This constructor normalizes the language value to lowercase and
  503. * the country value to uppercase.
  504. * <p>
  505. * <b>Note:</b>
  506. * <ul>
  507. * <li>ISO 639 is not a stable standard; some of the language codes it defines
  508. * (specifically "iw", "ji", and "in") have changed. This constructor accepts both the
  509. * old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other
  510. * API on Locale will return only the OLD codes.
  511. * <li>For backward compatibility reasons, this constructor does not make
  512. * any syntactic checks on the input.
  513. * </ul>
  514. *
  515. * @param language An ISO 639 alpha-2 or alpha-3 language code, or a language subtag
  516. * up to 8 characters in length. See the <code>Locale</code> class description about
  517. * valid language values.
  518. * @param country An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code.
  519. * See the <code>Locale</code> class description about valid country values.
  520. * @exception NullPointerException thrown if either argument is null.
  521. */
  522. @:overload public function new(language : String, country : String) : Void;
  523. /**
  524. * Construct a locale from a language code.
  525. * This constructor normalizes the language value to lowercase.
  526. * <p>
  527. * <b>Note:</b>
  528. * <ul>
  529. * <li>ISO 639 is not a stable standard; some of the language codes it defines
  530. * (specifically "iw", "ji", and "in") have changed. This constructor accepts both the
  531. * old codes ("iw", "ji", and "in") and the new codes ("he", "yi", and "id"), but all other
  532. * API on Locale will return only the OLD codes.
  533. * <li>For backward compatibility reasons, this constructor does not make
  534. * any syntactic checks on the input.
  535. * </ul>
  536. *
  537. * @param language An ISO 639 alpha-2 or alpha-3 language code, or a language subtag
  538. * up to 8 characters in length. See the <code>Locale</code> class description about
  539. * valid language values.
  540. * @exception NullPointerException thrown if argument is null.
  541. * @since 1.4
  542. */
  543. @:require(java4) @:overload public function new(language : String) : Void;
  544. /**
  545. * Gets the current value of the default locale for this instance
  546. * of the Java Virtual Machine.
  547. * <p>
  548. * The Java Virtual Machine sets the default locale during startup
  549. * based on the host environment. It is used by many locale-sensitive
  550. * methods if no locale is explicitly specified.
  551. * It can be changed using the
  552. * {@link #setDefault(java.util.Locale) setDefault} method.
  553. *
  554. * @return the default locale for this instance of the Java Virtual Machine
  555. */
  556. @:overload public static function getDefault() : Locale;
  557. /**
  558. * Gets the current value of the default locale for the specified Category
  559. * for this instance of the Java Virtual Machine.
  560. * <p>
  561. * The Java Virtual Machine sets the default locale during startup based
  562. * on the host environment. It is used by many locale-sensitive methods
  563. * if no locale is explicitly specified. It can be changed using the
  564. * setDefault(Locale.Category, Locale) method.
  565. *
  566. * @param category - the specified category to get the default locale
  567. * @throws NullPointerException - if category is null
  568. * @return the default locale for the specified Category for this instance
  569. * of the Java Virtual Machine
  570. * @see #setDefault(Locale.Category, Locale)
  571. * @since 1.7
  572. */
  573. @:require(java7) @:overload public static function getDefault(category : Locale_Category) : Locale;
  574. /**
  575. * Sets the default locale for this instance of the Java Virtual Machine.
  576. * This does not affect the host locale.
  577. * <p>
  578. * If there is a security manager, its <code>checkPermission</code>
  579. * method is called with a <code>PropertyPermission("user.language", "write")</code>
  580. * permission before the default locale is changed.
  581. * <p>
  582. * The Java Virtual Machine sets the default locale during startup
  583. * based on the host environment. It is used by many locale-sensitive
  584. * methods if no locale is explicitly specified.
  585. * <p>
  586. * Since changing the default locale may affect many different areas
  587. * of functionality, this method should only be used if the caller
  588. * is prepared to reinitialize locale-sensitive code running
  589. * within the same Java Virtual Machine.
  590. * <p>
  591. * By setting the default locale with this method, all of the default
  592. * locales for each Category are also set to the specified default locale.
  593. *
  594. * @throws SecurityException
  595. * if a security manager exists and its
  596. * <code>checkPermission</code> method doesn't allow the operation.
  597. * @throws NullPointerException if <code>newLocale</code> is null
  598. * @param newLocale the new default locale
  599. * @see SecurityManager#checkPermission
  600. * @see java.util.PropertyPermission
  601. */
  602. @:overload @:synchronized public static function setDefault(newLocale : Locale) : Void;
  603. /**
  604. * Sets the default locale for the specified Category for this instance
  605. * of the Java Virtual Machine. This does not affect the host locale.
  606. * <p>
  607. * If there is a security manager, its checkPermission method is called
  608. * with a PropertyPermission("user.language", "write") permission before
  609. * the default locale is changed.
  610. * <p>
  611. * The Java Virtual Machine sets the default locale during startup based
  612. * on the host environment. It is used by many locale-sensitive methods
  613. * if no locale is explicitly specified.
  614. * <p>
  615. * Since changing the default locale may affect many different areas of
  616. * functionality, this method should only be used if the caller is
  617. * prepared to reinitialize locale-sensitive code running within the
  618. * same Java Virtual Machine.
  619. * <p>
  620. *
  621. * @param category - the specified category to set the default locale
  622. * @param newLocale - the new default locale
  623. * @throws SecurityException - if a security manager exists and its
  624. * checkPermission method doesn't allow the operation.
  625. * @throws NullPointerException - if category and/or newLocale is null
  626. * @see SecurityManager#checkPermission(java.security.Permission)
  627. * @see PropertyPermission
  628. * @see #getDefault(Locale.Category)
  629. * @since 1.7
  630. */
  631. @:require(java7) @:overload @:synchronized public static function setDefault(category : Locale_Category, newLocale : Locale) : Void;
  632. /**
  633. * Returns an array of all installed locales.
  634. * The returned array represents the union of locales supported
  635. * by the Java runtime environment and by installed
  636. * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
  637. * implementations. It must contain at least a <code>Locale</code>
  638. * instance equal to {@link java.util.Locale#US Locale.US}.
  639. *
  640. * @return An array of installed locales.
  641. */
  642. @:overload public static function getAvailableLocales() : java.NativeArray<Locale>;
  643. /**
  644. * Returns a list of all 2-letter country codes defined in ISO 3166.
  645. * Can be used to create Locales.
  646. * <p>
  647. * <b>Note:</b> The <code>Locale</code> class also supports other codes for
  648. * country (region), such as 3-letter numeric UN M.49 area codes.
  649. * Therefore, the list returned by this method does not contain ALL valid
  650. * codes that can be used to create Locales.
  651. */
  652. @:overload public static function getISOCountries() : java.NativeArray<String>;
  653. /**
  654. * Returns a list of all 2-letter language codes defined in ISO 639.
  655. * Can be used to create Locales.
  656. * <p>
  657. * <b>Note:</b>
  658. * <ul>
  659. * <li>ISO 639 is not a stable standard&mdash; some languages' codes have changed.
  660. * The list this function returns includes both the new and the old codes for the
  661. * languages whose codes have changed.
  662. * <li>The <code>Locale</code> class also supports language codes up to
  663. * 8 characters in length. Therefore, the list returned by this method does
  664. * not contain ALL valid codes that can be used to create Locales.
  665. * </ul>
  666. */
  667. @:overload public static function getISOLanguages() : java.NativeArray<String>;
  668. /**
  669. * Returns the language code of this Locale.
  670. *
  671. * <p><b>Note:</b> ISO 639 is not a stable standard&mdash; some languages' codes have changed.
  672. * Locale's constructor recognizes both the new and the old codes for the languages
  673. * whose codes have changed, but this function always returns the old code. If you
  674. * want to check for a specific language whose code has changed, don't do
  675. * <pre>
  676. * if (locale.getLanguage().equals("he")) // BAD!
  677. * ...
  678. * </pre>
  679. * Instead, do
  680. * <pre>
  681. * if (locale.getLanguage().equals(new Locale("he").getLanguage()))
  682. * ...
  683. * </pre>
  684. * @return The language code, or the empty string if none is defined.
  685. * @see #getDisplayLanguage
  686. */
  687. @:overload public function getLanguage() : String;
  688. /**
  689. * Returns the script for this locale, which should
  690. * either be the empty string or an ISO 15924 4-letter script
  691. * code. The first letter is uppercase and the rest are
  692. * lowercase, for example, 'Latn', 'Cyrl'.
  693. *
  694. * @return The script code, or the empty string if none is defined.
  695. * @see #getDisplayScript
  696. * @since 1.7
  697. */
  698. @:require(java7) @:overload public function getScript() : String;
  699. /**
  700. * Returns the country/region code for this locale, which should
  701. * either be the empty string, an uppercase ISO 3166 2-letter code,
  702. * or a UN M.49 3-digit code.
  703. *
  704. * @return The country/region code, or the empty string if none is defined.
  705. * @see #getDisplayCountry
  706. */
  707. @:overload public function getCountry() : String;
  708. /**
  709. * Returns the variant code for this locale.
  710. *
  711. * @return The variant code, or the empty string if none is defined.
  712. * @see #getDisplayVariant
  713. */
  714. @:overload public function getVariant() : String;
  715. /**
  716. * Returns the extension (or private use) value associated with
  717. * the specified key, or null if there is no extension
  718. * associated with the key. To be well-formed, the key must be one
  719. * of <code>[0-9A-Za-z]</code>. Keys are case-insensitive, so
  720. * for example 'z' and 'Z' represent the same extension.
  721. *
  722. * @param key the extension key
  723. * @return The extension, or null if this locale defines no
  724. * extension for the specified key.
  725. * @throws IllegalArgumentException if key is not well-formed
  726. * @see #PRIVATE_USE_EXTENSION
  727. * @see #UNICODE_LOCALE_EXTENSION
  728. * @since 1.7
  729. */
  730. @:require(java7) @:overload public function getExtension(key : java.StdTypes.Char16) : String;
  731. /**
  732. * Returns the set of extension keys associated with this locale, or the
  733. * empty set if it has no extensions. The returned set is unmodifiable.
  734. * The keys will all be lower-case.
  735. *
  736. * @return The set of extension keys, or the empty set if this locale has
  737. * no extensions.
  738. * @since 1.7
  739. */
  740. @:require(java7) @:overload public function getExtensionKeys() : java.util.Set<Null<java.StdTypes.Char16>>;
  741. /**
  742. * Returns the set of unicode locale attributes associated with
  743. * this locale, or the empty set if it has no attributes. The
  744. * returned set is unmodifiable.
  745. *
  746. * @return The set of attributes.
  747. * @since 1.7
  748. */
  749. @:require(java7) @:overload public function getUnicodeLocaleAttributes() : java.util.Set<String>;
  750. /**
  751. * Returns the Unicode locale type associated with the specified Unicode locale key
  752. * for this locale. Returns the empty string for keys that are defined with no type.
  753. * Returns null if the key is not defined. Keys are case-insensitive. The key must
  754. * be two alphanumeric characters ([0-9a-zA-Z]), or an IllegalArgumentException is
  755. * thrown.
  756. *
  757. * @param key the Unicode locale key
  758. * @return The Unicode locale type associated with the key, or null if the
  759. * locale does not define the key.
  760. * @throws IllegalArgumentException if the key is not well-formed
  761. * @throws NullPointerException if <code>key</code> is null
  762. * @since 1.7
  763. */
  764. @:require(java7) @:overload public function getUnicodeLocaleType(key : String) : String;
  765. /**
  766. * Returns the set of Unicode locale keys defined by this locale, or the empty set if
  767. * this locale has none. The returned set is immutable. Keys are all lower case.
  768. *
  769. * @return The set of Unicode locale keys, or the empty set if this locale has
  770. * no Unicode locale keywords.
  771. * @since 1.7
  772. */
  773. @:require(java7) @:overload public function getUnicodeLocaleKeys() : java.util.Set<String>;
  774. /**
  775. * Returns a string representation of this <code>Locale</code>
  776. * object, consisting of language, country, variant, script,
  777. * and extensions as below:
  778. * <p><blockquote>
  779. * language + "_" + country + "_" + (variant + "_#" | "#") + script + "-" + extensions
  780. * </blockquote>
  781. *
  782. * Language is always lower case, country is always upper case, script is always title
  783. * case, and extensions are always lower case. Extensions and private use subtags
  784. * will be in canonical order as explained in {@link #toLanguageTag}.
  785. *
  786. * <p>When the locale has neither script nor extensions, the result is the same as in
  787. * Java 6 and prior.
  788. *
  789. * <p>If both the language and country fields are missing, this function will return
  790. * the empty string, even if the variant, script, or extensions field is present (you
  791. * can't have a locale with just a variant, the variant must accompany a well-formed
  792. * language or country code).
  793. *
  794. * <p>If script or extensions are present and variant is missing, no underscore is
  795. * added before the "#".
  796. *
  797. * <p>This behavior is designed to support debugging and to be compatible with
  798. * previous uses of <code>toString</code> that expected language, country, and variant
  799. * fields only. To represent a Locale as a String for interchange purposes, use
  800. * {@link #toLanguageTag}.
  801. *
  802. * <p>Examples: <ul><tt>
  803. * <li>en
  804. * <li>de_DE
  805. * <li>_GB
  806. * <li>en_US_WIN
  807. * <li>de__POSIX
  808. * <li>zh_CN_#Hans
  809. * <li>zh_TW_#Hant-x-java
  810. * <li>th_TH_TH_#u-nu-thai</tt></ul>
  811. *
  812. * @return A string representation of the Locale, for debugging.
  813. * @see #getDisplayName
  814. * @see #toLanguageTag
  815. */
  816. @:overload @:final public function toString() : String;
  817. /**
  818. * Returns a well-formed IETF BCP 47 language tag representing
  819. * this locale.
  820. *
  821. * <p>If this <code>Locale</code> has a language, country, or
  822. * variant that does not satisfy the IETF BCP 47 language tag
  823. * syntax requirements, this method handles these fields as
  824. * described below:
  825. *
  826. * <p><b>Language:</b> If language is empty, or not <a
  827. * href="#def_language" >well-formed</a> (for example "a" or
  828. * "e2"), it will be emitted as "und" (Undetermined).
  829. *
  830. * <p><b>Country:</b> If country is not <a
  831. * href="#def_region">well-formed</a> (for example "12" or "USA"),
  832. * it will be omitted.
  833. *
  834. * <p><b>Variant:</b> If variant <b>is</b> <a
  835. * href="#def_variant">well-formed</a>, each sub-segment
  836. * (delimited by '-' or '_') is emitted as a subtag. Otherwise:
  837. * <ul>
  838. *
  839. * <li>if all sub-segments match <code>[0-9a-zA-Z]{1,8}</code>
  840. * (for example "WIN" or "Oracle_JDK_Standard_Edition"), the first
  841. * ill-formed sub-segment and all following will be appended to
  842. * the private use subtag. The first appended subtag will be
  843. * "lvariant", followed by the sub-segments in order, separated by
  844. * hyphen. For example, "x-lvariant-WIN",
  845. * "Oracle-x-lvariant-JDK-Standard-Edition".
  846. *
  847. * <li>if any sub-segment does not match
  848. * <code>[0-9a-zA-Z]{1,8}</code>, the variant will be truncated
  849. * and the problematic sub-segment and all following sub-segments
  850. * will be omitted. If the remainder is non-empty, it will be
  851. * emitted as a private use subtag as above (even if the remainder
  852. * turns out to be well-formed). For example,
  853. * "Solaris_isjustthecoolestthing" is emitted as
  854. * "x-lvariant-Solaris", not as "solaris".</li></ul>
  855. *
  856. * <p><b>Special Conversions:</b> Java supports some old locale
  857. * representations, including deprecated ISO language codes,
  858. * for compatibility. This method performs the following
  859. * conversions:
  860. * <ul>
  861. *
  862. * <li>Deprecated ISO language codes "iw", "ji", and "in" are
  863. * converted to "he", "yi", and "id", respectively.
  864. *
  865. * <li>A locale with language "no", country "NO", and variant
  866. * "NY", representing Norwegian Nynorsk (Norway), is converted
  867. * to a language tag "nn-NO".</li></ul>
  868. *
  869. * <p><b>Note:</b> Although the language tag created by this
  870. * method is well-formed (satisfies the syntax requirements
  871. * defined by the IETF BCP 47 specification), it is not
  872. * necessarily a valid BCP 47 language tag. For example,
  873. * <pre>
  874. * new Locale("xx", "YY").toLanguageTag();</pre>
  875. *
  876. * will return "xx-YY", but the language subtag "xx" and the
  877. * region subtag "YY" are invalid because they are not registered
  878. * in the IANA Language Subtag Registry.
  879. *
  880. * @return a BCP47 language tag representing the locale
  881. * @see #forLanguageTag(String)
  882. * @since 1.7
  883. */
  884. @:require(java7) @:overload public function toLanguageTag() : String;
  885. /**
  886. * Returns a locale for the specified IETF BCP 47 language tag string.
  887. *
  888. * <p>If the specified language tag contains any ill-formed subtags,
  889. * the first such subtag and all following subtags are ignored. Compare
  890. * to {@link Locale.Builder#setLanguageTag} which throws an exception
  891. * in this case.
  892. *
  893. * <p>The following <b>conversions</b> are performed:<ul>
  894. *
  895. * <li>The language code "und" is mapped to language "".
  896. *
  897. * <li>The language codes "he", "yi", and "id" are mapped to "iw",
  898. * "ji", and "in" respectively. (This is the same canonicalization
  899. * that's done in Locale's constructors.)
  900. *
  901. * <li>The portion of a private use subtag prefixed by "lvariant",
  902. * if any, is removed and appended to the variant field in the
  903. * result locale (without case normalization). If it is then
  904. * empty, the private use subtag is discarded:
  905. *
  906. * <pre>
  907. * Locale loc;
  908. * loc = Locale.forLanguageTag("en-US-x-lvariant-POSIX");
  909. * loc.getVariant(); // returns "POSIX"
  910. * loc.getExtension('x'); // returns null
  911. *
  912. * loc = Locale.forLanguageTag("de-POSIX-x-URP-lvariant-Abc-Def");
  913. * loc.getVariant(); // returns "POSIX_Abc_Def"
  914. * loc.getExtension('x'); // returns "urp"
  915. * </pre>
  916. *
  917. * <li>When the languageTag argument contains an extlang subtag,
  918. * the first such subtag is used as the language, and the primary
  919. * language subtag and other extlang subtags are ignored:
  920. *
  921. * <pre>
  922. * Locale.forLanguageTag("ar-aao").getLanguage(); // returns "aao"
  923. * Locale.forLanguageTag("en-abc-def-us").toString(); // returns "abc_US"
  924. * </pre>
  925. *
  926. * <li>Case is normalized except for variant tags, which are left
  927. * unchanged. Language is normalized to lower case, script to
  928. * title case, country to upper case, and extensions to lower
  929. * case.
  930. *
  931. * <li>If, after processing, the locale would exactly match either
  932. * ja_JP_JP or th_TH_TH with no extensions, the appropriate
  933. * extensions are added as though the constructor had been called:
  934. *
  935. * <pre>
  936. * Locale.forLanguageTag("ja-JP-x-lvariant-JP").toLanguageTag();
  937. * // returns "ja-JP-u-ca-japanese-x-lvariant-JP"
  938. * Locale.forLanguageTag("th-TH-x-lvariant-TH").toLanguageTag();
  939. * // returns "th-TH-u-nu-thai-x-lvariant-TH"
  940. * <pre></ul>
  941. *
  942. * <p>This implements the 'Language-Tag' production of BCP47, and
  943. * so supports grandfathered (regular and irregular) as well as
  944. * private use language tags. Stand alone private use tags are
  945. * represented as empty language and extension 'x-whatever',
  946. * and grandfathered tags are converted to their canonical replacements
  947. * where they exist.
  948. *
  949. * <p>Grandfathered tags with canonical replacements are as follows:
  950. *
  951. * <table>
  952. * <tbody align="center">
  953. * <tr><th>grandfathered tag</th><th>&nbsp;</th><th>modern replacement</th></tr>
  954. * <tr><td>art-lojban</td><td>&nbsp;</td><td>jbo</td></tr>
  955. * <tr><td>i-ami</td><td>&nbsp;</td><td>ami</td></tr>
  956. * <tr><td>i-bnn</td><td>&nbsp;</td><td>bnn</td></tr>
  957. * <tr><td>i-hak</td><td>&nbsp;</td><td>hak</td></tr>
  958. * <tr><td>i-klingon</td><td>&nbsp;</td><td>tlh</td></tr>
  959. * <tr><td>i-lux</td><td>&nbsp;</td><td>lb</td></tr>
  960. * <tr><td>i-navajo</td><td>&nbsp;</td><td>nv</td></tr>
  961. * <tr><td>i-pwn</td><td>&nbsp;</td><td>pwn</td></tr>
  962. * <tr><td>i-tao</td><td>&nbsp;</td><td>tao</td></tr>
  963. * <tr><td>i-tay</td><td>&nbsp;</td><td>tay</td></tr>
  964. * <tr><td>i-tsu</td><td>&nbsp;</td><td>tsu</td></tr>
  965. * <tr><td>no-bok</td><td>&nbsp;</td><td>nb</td></tr>
  966. * <tr><td>no-nyn</td><td>&nbsp;</td><td>nn</td></tr>
  967. * <tr><td>sgn-BE-FR</td><td>&nbsp;</td><td>sfb</td></tr>
  968. * <tr><td>sgn-BE-NL</td><td>&nbsp;</td><td>vgt</td></tr>
  969. * <tr><td>sgn-CH-DE</td><td>&nbsp;</td><td>sgg</td></tr>
  970. * <tr><td>zh-guoyu</td><td>&nbsp;</td><td>cmn</td></tr>
  971. * <tr><td>zh-hakka</td><td>&nbsp;</td><td>hak</td></tr>
  972. * <tr><td>zh-min-nan</td><td>&nbsp;</td><td>nan</td></tr>
  973. * <tr><td>zh-xiang</td><td>&nbsp;</td><td>hsn</td></tr>
  974. * </tbody>
  975. * </table>
  976. *
  977. * <p>Grandfathered tags with no modern replacement will be
  978. * converted as follows:
  979. *
  980. * <table>
  981. * <tbody align="center">
  982. * <tr><th>grandfathered tag</th><th>&nbsp;</th><th>converts to</th></tr>
  983. * <tr><td>cel-gaulish</td><td>&nbsp;</td><td>xtg-x-cel-gaulish</td></tr>
  984. * <tr><td>en-GB-oed</td><td>&nbsp;</td><td>en-GB-x-oed</td></tr>
  985. * <tr><td>i-default</td><td>&nbsp;</td><td>en-x-i-default</td></tr>
  986. * <tr><td>i-enochian</td><td>&nbsp;</td><td>und-x-i-enochian</td></tr>
  987. * <tr><td>i-mingo</td><td>&nbsp;</td><td>see-x-i-mingo</td></tr>
  988. * <tr><td>zh-min</td><td>&nbsp;</td><td>nan-x-zh-min</td></tr>
  989. * </tbody>
  990. * </table>
  991. *
  992. * <p>For a list of all grandfathered tags, see the
  993. * IANA Language Subtag Registry (search for "Type: grandfathered").
  994. *
  995. * <p><b>Note</b>: there is no guarantee that <code>toLanguageTag</code>
  996. * and <code>forLanguageTag</code> will round-trip.
  997. *
  998. * @param languageTag the language tag
  999. * @return The locale that best represents the language tag.
  1000. * @throws NullPointerException if <code>languageTag</code> is <code>null</code>
  1001. * @see #toLanguageTag()
  1002. * @see java.util.Locale.Builder#setLanguageTag(String)
  1003. * @since 1.7
  1004. */
  1005. @:require(java7) @:overload public static function forLanguageTag(languageTag : String) : Locale;
  1006. /**
  1007. * Returns a three-letter abbreviation of this locale's language.
  1008. * If the language matches an ISO 639-1 two-letter code, the
  1009. * corresponding ISO 639-2/T three-letter lowercase code is
  1010. * returned. The ISO 639-2 language codes can be found on-line,
  1011. * see "Codes for the Representation of Names of Languages Part 2:
  1012. * Alpha-3 Code". If the locale specifies a three-letter
  1013. * language, the language is returned as is. If the locale does
  1014. * not specify a language the empty string is returned.
  1015. *
  1016. * @return A three-letter abbreviation of this locale's language.
  1017. * @exception MissingResourceException Throws MissingResourceException if
  1018. * three-letter language abbreviation is not available for this locale.
  1019. */
  1020. @:overload public function getISO3Language() : String;
  1021. /**
  1022. * Returns a three-letter abbreviation for this locale's country.
  1023. * If the country matches an ISO 3166-1 alpha-2 code, the
  1024. * corresponding ISO 3166-1 alpha-3 uppercase code is returned.
  1025. * If the locale doesn't specify a country, this will be the empty
  1026. * string.
  1027. *
  1028. * <p>The ISO 3166-1 codes can be found on-line.
  1029. *
  1030. * @return A three-letter abbreviation of this locale's country.
  1031. * @exception MissingResourceException Throws MissingResourceException if the
  1032. * three-letter country abbreviation is not available for this locale.
  1033. */
  1034. @:overload public function getISO3Country() : String;
  1035. /**
  1036. * Returns a name for the locale's language that is appropriate for display to the
  1037. * user.
  1038. * If possible, the name returned will be localized for the default locale.
  1039. * For example, if the locale is fr_FR and the default locale
  1040. * is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and
  1041. * the default locale is fr_FR, getDisplayLanguage() will return "anglais".
  1042. * If the name returned cannot be localized for the default locale,
  1043. * (say, we don't have a Japanese name for Croatian),
  1044. * this function falls back on the English name, and uses the ISO code as a last-resort
  1045. * value. If the locale doesn't specify a language, this function returns the empty string.
  1046. */
  1047. @:overload @:final public function getDisplayLanguage() : String;
  1048. /**
  1049. * Returns a name for the locale's language that is appropriate for display to the
  1050. * user.
  1051. * If possible, the name returned will be localized according to inLocale.
  1052. * For example, if the locale is fr_FR and inLocale
  1053. * is en_US, getDisplayLanguage() will return "French"; if the locale is en_US and
  1054. * inLocale is fr_FR, getDisplayLanguage() will return "anglais".
  1055. * If the name returned cannot be localized according to inLocale,
  1056. * (say, we don't have a Japanese name for Croatian),
  1057. * this function falls back on the English name, and finally
  1058. * on the ISO code as a last-resort value. If the locale doesn't specify a language,
  1059. * this function returns the empty string.
  1060. *
  1061. * @exception NullPointerException if <code>inLocale</code> is <code>null</code>
  1062. */
  1063. @:overload public function getDisplayLanguage(inLocale : Locale) : String;
  1064. /**
  1065. * Returns a name for the the locale's script that is appropriate for display to
  1066. * the user. If possible, the name will be localized for the default locale. Returns
  1067. * the empty string if this locale doesn't specify a script code.
  1068. *
  1069. * @return the display name of the script code for the current default locale
  1070. * @since 1.7
  1071. */
  1072. @:require(java7) @:overload public function getDisplayScript() : String;
  1073. /**
  1074. * Returns a name for the locale's script that is appropriate
  1075. * for display to the user. If possible, the name will be
  1076. * localized for the given locale. Returns the empty string if
  1077. * this locale doesn't specify a script code.
  1078. *
  1079. * @return the display name of the script code for the current default locale
  1080. * @throws NullPointerException if <code>inLocale</code> is <code>null</code>
  1081. * @since 1.7
  1082. */
  1083. @:require(java7) @:overload public function getDisplayScript(inLocale : Locale) : String;
  1084. /**
  1085. * Returns a name for the locale's country that is appropriate for display to the
  1086. * user.
  1087. * If possible, the name returned will be localized for the default locale.
  1088. * For example, if the locale is fr_FR and the default locale
  1089. * is en_US, getDisplayCountry() will return "France"; if the locale is en_US and
  1090. * the default locale is fr_FR, getDisplayCountry() will return "Etats-Unis".
  1091. * If the name returned cannot be localized for the default locale,
  1092. * (say, we don't have a Japanese name for Croatia),
  1093. * this function falls back on the English name, and uses the ISO code as a last-resort
  1094. * value. If the locale doesn't specify a country, this function returns the empty string.
  1095. */
  1096. @:overload @:final public function getDisplayCountry() : String;
  1097. /**
  1098. * Returns a name for the locale's country that is appropriate for display to the
  1099. * user.
  1100. * If possible, the name returned will be localized according to inLocale.
  1101. * For example, if the locale is fr_FR and inLocale
  1102. * is en_US, getDisplayCountry() will return "France"; if the locale is en_US and
  1103. * inLocale is fr_FR, getDisplayCountry() will return "Etats-Unis".
  1104. * If the name returned cannot be localized according to inLocale.
  1105. * (say, we don't have a Japanese name for Croatia),
  1106. * this function falls back on the English name, and finally
  1107. * on the ISO code as a last-resort value. If the locale doesn't specify a country,
  1108. * this function returns the empty string.
  1109. *
  1110. * @exception NullPointerException if <code>inLocale</code> is <code>null</code>
  1111. */
  1112. @:overload public function getDisplayCountry(inLocale : Locale) : String;
  1113. /**
  1114. * Returns a name for the locale's variant code that is appropriate for display to the
  1115. * user. If possible, the name will be localized for the default locale. If the locale
  1116. * doesn't specify a variant code, this function returns the empty string.
  1117. */
  1118. @:overload @:final public function getDisplayVariant() : String;
  1119. /**
  1120. * Returns a name for the locale's variant code that is appropriate for display to the
  1121. * user. If possible, the name will be localized for inLocale. If the locale
  1122. * doesn't specify a variant code, this function returns the empty string.
  1123. *
  1124. * @exception NullPointerException if <code>inLocale</code> is <code>null</code>
  1125. */
  1126. @:overload public function getDisplayVariant(inLocale : Locale) : String;
  1127. /**
  1128. * Returns a name for the locale that is appropriate for display to the
  1129. * user. This will be the values returned by getDisplayLanguage(),
  1130. * getDisplayScript(), getDisplayCountry(), and getDisplayVariant() assembled
  1131. * into a single string. The the non-empty values are used in order,
  1132. * with the second and subsequent names in parentheses. For example:
  1133. * <blockquote>
  1134. * language (script, country, variant)<br>
  1135. * language (country)<br>
  1136. * language (variant)<br>
  1137. * script (country)<br>
  1138. * country<br>
  1139. * </blockquote>
  1140. * depending on which fields are specified in the locale. If the
  1141. * language, sacript, country, and variant fields are all empty,
  1142. * this function returns the empty string.
  1143. */
  1144. @:overload @:final public function getDisplayName() : String;
  1145. /**
  1146. * Returns a name for the locale that is appropriate for display
  1147. * to the user. This will be the values returned by
  1148. * getDisplayLanguage(), getDisplayScript(),getDisplayCountry(),
  1149. * and getDisplayVariant() assembled into a single string.
  1150. * The non-empty values are used in order,
  1151. * with the second and subsequent names in parentheses. For example:
  1152. * <blockquote>
  1153. * language (script, country, variant)<br>
  1154. * language (country)<br>
  1155. * language (variant)<br>
  1156. * script (country)<br>
  1157. * country<br>
  1158. * </blockquote>
  1159. * depending on which fields are specified in the locale. If the
  1160. * language, script, country, and variant fields are all empty,
  1161. * this function returns the empty string.
  1162. *
  1163. * @throws NullPointerException if <code>inLocale</code> is <code>null</code>
  1164. */
  1165. @:overload public function getDisplayName(inLocale : Locale) : String;
  1166. /**
  1167. * Overrides Cloneable.
  1168. */
  1169. @:overload public function clone() : Dynamic;
  1170. /**
  1171. * Override hashCode.
  1172. * Since Locales are often used in hashtables, caches the value
  1173. * for speed.
  1174. */
  1175. @:overload public function hashCode() : Int;
  1176. /**
  1177. * Returns true if this Locale is equal to another object. A Locale is
  1178. * deemed equal to another Locale with identical language, script, country,
  1179. * variant and extensions, and unequal to all other objects.
  1180. *
  1181. * @return true if this Locale is equal to the specified object.
  1182. */
  1183. @:overload public function equals(obj : Dynamic) : Bool;
  1184. }
  1185. /**
  1186. * Enum for locale categories. These locale categories are used to get/set
  1187. * the default locale for the specific functionality represented by the
  1188. * category.
  1189. *
  1190. * @see #getDefault(Locale.Category)
  1191. * @see #setDefault(Locale.Category, Locale)
  1192. * @since 1.7
  1193. */
  1194. @:require(java7) @:native('java.util.Locale.Category') extern enum Locale_Category
  1195. {
  1196. /**
  1197. * Category used to represent the default locale for
  1198. * displaying user interfaces.
  1199. */
  1200. DISPLAY;
  1201. /**
  1202. * Category used to represent the default locale for
  1203. * formatting dates, numbers, and/or currencies.
  1204. */
  1205. FORMAT;
  1206. }
  1207. /**
  1208. * <code>Builder</code> is used to build instances of <code>Locale</code>
  1209. * from values configured by the setters. Unlike the <code>Locale</code>
  1210. * constructors, the <code>Builder</code> checks if a value configured by a
  1211. * setter satisfies the syntax requirements defined by the <code>Locale</code>
  1212. * class. A <code>Locale</code> object created by a <code>Builder</code> is
  1213. * well-formed and can be transformed to a well-formed IETF BCP 47 language tag
  1214. * without losing information.
  1215. *
  1216. * <p><b>Note:</b> The <code>Locale</code> class does not provide any
  1217. * syntactic restrictions on variant, while BCP 47 requires each variant
  1218. * subtag to be 5 to 8 alphanumerics or a single numeric followed by 3
  1219. * alphanumerics. The method <code>setVariant</code> throws
  1220. * <code>IllformedLocaleException</code> for a variant that does not satisfy
  1221. * this restriction. If it is necessary to support such a variant, use a
  1222. * Locale constructor. However, keep in mind that a <code>Locale</code>
  1223. * object created this way might lose the variant information when
  1224. * transformed to a BCP 47 language tag.
  1225. *
  1226. * <p>The following example shows how to create a <code>Locale</code> object
  1227. * with the <code>Builder</code>.
  1228. * <blockquote>
  1229. * <pre>
  1230. * Locale aLocale = new Builder().setLanguage("sr").setScript("Latn").setRegion("RS").build();
  1231. * </pre>
  1232. * </blockquote>
  1233. *
  1234. * <p>Builders can be reused; <code>clear()</code> resets all
  1235. * fields to their default values.
  1236. *
  1237. * @see Locale#forLanguageTag
  1238. * @since 1.7
  1239. */
  1240. @:require(java7) @:native('java.util.Locale.Builder') extern class Locale_Builder
  1241. {
  1242. /**
  1243. * Constructs an empty Builder. The default value of all
  1244. * fields, extensions, and private use information is the
  1245. * empty string.
  1246. */
  1247. @:overload public function new() : Void;
  1248. /**
  1249. * Resets the <code>Builder</code> to match the provided
  1250. * <code>locale</code>. Existing state is discarded.
  1251. *
  1252. * <p>All fields of the locale must be well-formed, see {@link Locale}.
  1253. *
  1254. * <p>Locales with any ill-formed fields cause
  1255. * <code>IllformedLocaleException</code> to be thrown, except for the
  1256. * following three cases which are accepted for compatibility
  1257. * reasons:<ul>
  1258. * <li>Locale("ja", "JP", "JP") is treated as "ja-JP-u-ca-japanese"
  1259. * <li>Locale("th", "TH", "TH") is treated as "th-TH-u-nu-thai"
  1260. * <li>Locale("no", "NO", "NY") is treated as "nn-NO"</ul>
  1261. *
  1262. * @param locale the locale
  1263. * @return This builder.
  1264. * @throws IllformedLocaleException if <code>locale</code> has
  1265. * any ill-formed fields.
  1266. * @throws NullPointerException if <code>locale</code> is null.
  1267. */
  1268. @:overload public function setLocale(locale : Locale) : Locale_Builder;
  1269. /**
  1270. * Resets the Builder to match the provided IETF BCP 47
  1271. * language tag. Discards the existing state. Null and the
  1272. * empty string cause the builder to be reset, like {@link
  1273. * #clear}. Grandfathered tags (see {@link
  1274. * Locale#forLanguageTag}) are converted to their canonical
  1275. * form before being processed. Otherwise, the language tag
  1276. * must be well-formed (see {@link Locale}) or an exception is
  1277. * thrown (unlike <code>Locale.forLanguageTag</code>, which
  1278. * just discards ill-formed and following portions of the
  1279. * tag).
  1280. *
  1281. * @param languageTag the language tag
  1282. * @return This builder.
  1283. * @throws IllformedLocaleException if <code>languageTag</code> is ill-formed
  1284. * @see Locale#forLanguageTag(String)
  1285. */
  1286. @:overload public function setLanguageTag(languageTag : String) : Locale_Builder;
  1287. /**
  1288. * Sets the language. If <code>language</code> is the empty string or
  1289. * null, the language in this <code>Builder</code> is removed. Otherwise,
  1290. * the language must be <a href="./Locale.html#def_language">well-formed</a>
  1291. * or an exception is thrown.
  1292. *
  1293. * <p>The typical language value is a two or three-letter language
  1294. * code as defined in ISO639.
  1295. *
  1296. * @param language the language
  1297. * @return This builder.
  1298. * @throws IllformedLocaleException if <code>language</code> is ill-formed
  1299. */
  1300. @:overload public function setLanguage(language : String) : Locale_Builder;
  1301. /**
  1302. * Sets the script. If <code>script</code> is null or the empty string,
  1303. * the script in this <code>Builder</code> is removed.
  1304. * Otherwise, the script must be <a href="./Locale.html#def_script">well-formed</a> or an
  1305. * exception is thrown.
  1306. *
  1307. * <p>The typical script value is a four-letter script code as defined by ISO 15924.
  1308. *
  1309. * @param script the script
  1310. * @return This builder.
  1311. * @throws IllformedLocaleException if <code>script</code> is ill-formed
  1312. */
  1313. @:overload public function setScript(script : String) : Locale_Builder;
  1314. /**
  1315. * Sets the region. If region is null or the empty string, the region
  1316. * in this <code>Builder</code> is removed. Otherwise,
  1317. * the region must be <a href="./Locale.html#def_region">well-formed</a> or an
  1318. * exception is thrown.
  1319. *
  1320. * <p>The typical region value is a two-letter ISO 3166 code or a
  1321. * three-digit UN M.49 area code.
  1322. *
  1323. * <p>The country value in the <code>Locale</code> created by the
  1324. * <code>Builder</code> is always normalized to upper case.
  1325. *
  1326. * @param region the region
  1327. * @return This builder.
  1328. * @throws IllformedLocaleException if <code>region</code> is ill-formed
  1329. */
  1330. @:overload public function setRegion(region : String) : Locale_Builder;
  1331. /**
  1332. * Sets the variant. If variant is null or the empty string, the
  1333. * variant in this <code>Builder</code> is removed. Otherwise, it
  1334. * must consist of one or more <a href="./Locale.html#def_variant">well-formed</a>
  1335. * subtags, or an exception is thrown.
  1336. *
  1337. * <p><b>Note:</b> This method checks if <code>variant</code>
  1338. * satisfies the IETF BCP 47 variant subtag's syntax requirements,
  1339. * and normalizes the value to lowercase letters. However,
  1340. * the <code>Locale</code> class does not impose any syntactic
  1341. * restriction on variant, and the variant value in
  1342. * <code>Locale</code> is case sensitive. To set such a variant,
  1343. * use a Locale constructor.
  1344. *
  1345. * @param variant the variant
  1346. * @return This builder.
  1347. * @throws IllformedLocaleException if <code>variant</code> is ill-formed
  1348. */
  1349. @:overload public function setVariant(variant : String) : Locale_Builder;
  1350. /**
  1351. * Sets the extension for the given key. If the value is null or the
  1352. * empty string, the extension is removed. Otherwise, the extension
  1353. * must be <a href="./Locale.html#def_extensions">well-formed</a> or an exception
  1354. * is thrown.
  1355. *
  1356. * <p><b>Note:</b> The key {@link Locale#UNICODE_LOCALE_EXTENSION
  1357. * UNICODE_LOCALE_EXTENSION} ('u') is used for the Unicode locale extension.
  1358. * Setting a value for this key replaces any existing Unicode locale key/type
  1359. * pairs with those defined in the extension.
  1360. *
  1361. * <p><b>Note:</b> The key {@link Locale#PRIVATE_USE_EXTENSION
  1362. * PRIVATE_USE_EXTENSION} ('x') is used for the private use code. To be
  1363. * well-formed, the value for this key needs only to have subtags of one to
  1364. * eight alphanumeric characters, not two to eight as in the general case.
  1365. *
  1366. * @param key the extension key
  1367. * @param value the extension value
  1368. * @return This builder.
  1369. * @throws IllformedLocaleException if <code>key</code> is illegal
  1370. * or <code>value</code> is ill-formed
  1371. * @see #setUnicodeLocaleKeyword(String, String)
  1372. */
  1373. @:overload public function setExtension(key : java.StdTypes.Char16, value : String) : Locale_Builder;
  1374. /**
  1375. * Sets the Unicode locale keyword type for the given key. If the type
  1376. * is null, the Unicode keyword is removed. Otherwise, the key must be
  1377. * non-null and both key and type must be <a
  1378. * href="./Locale.html#def_locale_extension">well-formed</a> or an exception
  1379. * is thrown.
  1380. *
  1381. * <p>Keys and types are converted to lower case.
  1382. *
  1383. * <p><b>Note</b>:Setting the 'u' extension via {@link #setExtension}
  1384. * replaces all Unicode locale keywords with those defined in the
  1385. * extension.
  1386. *
  1387. * @param key the Unicode locale key
  1388. * @param type the Unicode locale type
  1389. * @return This builder.
  1390. * @throws IllformedLocaleException if <code>key</code> or <code>type</code>
  1391. * is ill-formed
  1392. * @throws NullPointerException if <code>key</code> is null
  1393. * @see #setExtension(char, String)
  1394. */
  1395. @:overload public function setUnicodeLocaleKeyword(key : String, type : String) : Locale_Builder;
  1396. /**
  1397. * Adds a unicode locale attribute, if not already present, otherwise
  1398. * has no effect. The attribute must not be null and must be <a
  1399. * href="./Locale.html#def_locale_extension">well-formed</a> or an exception
  1400. * is thrown.
  1401. *
  1402. * @param attribute the attribute
  1403. * @return This builder.
  1404. * @throws NullPointerException if <code>attribute</code> is null
  1405. * @throws IllformedLocaleException if <code>attribute</code> is ill-formed
  1406. * @see #setExtension(char, String)
  1407. */
  1408. @:overload public function addUnicodeLocaleAttribute(attribute : String) : Locale_Builder;
  1409. /**
  1410. * Removes a unicode locale attribute, if present, otherwise has no
  1411. * effect. The attribute must not be null and must be <a
  1412. * href="./Locale.html#def_locale_extension">well-formed</a> or an exception
  1413. * is thrown.
  1414. *
  1415. * <p>Attribute comparision for removal is case-insensitive.
  1416. *
  1417. * @param attribute the attribute
  1418. * @return This builder.
  1419. * @throws NullPointerException if <code>attribute</code> is null
  1420. * @throws IllformedLocaleException if <code>attribute</code> is ill-formed
  1421. * @see #setExtension(char, String)
  1422. */
  1423. @:overload public function removeUnicodeLocaleAttribute(attribute : String) : Locale_Builder;
  1424. /**
  1425. * Resets the builder to its initial, empty state.
  1426. *
  1427. * @return This builder.
  1428. */
  1429. @:overload public function clear() : Locale_Builder;
  1430. /**
  1431. * Resets the extensions to their initial, empty state.
  1432. * Language, script, region and variant are unchanged.
  1433. *
  1434. * @return This builder.
  1435. * @see #setExtension(char, String)
  1436. */
  1437. @:overload public function clearExtensions() : Locale_Builder;
  1438. /**
  1439. * Returns an instance of <code>Locale</code> created from the fields set
  1440. * on this builder.
  1441. *
  1442. * <p>This applies the conversions listed in {@link Locale#forLanguageTag}
  1443. * when constructing a Locale. (Grandfathered tags are handled in
  1444. * {@link #setLanguageTag}.)
  1445. *
  1446. * @return A Locale.
  1447. */
  1448. @:overload public function build() : Locale;
  1449. }