868 * @param category - the specified category to set the default locale |
868 * @param category - the specified category to set the default locale |
869 * @param newLocale - the new default locale |
869 * @param newLocale - the new default locale |
870 * @throws SecurityException - if a security manager exists and its |
870 * @throws SecurityException - if a security manager exists and its |
871 * checkPermission method doesn't allow the operation. |
871 * checkPermission method doesn't allow the operation. |
872 * @throws NullPointerException - if category and/or newLocale is null |
872 * @throws NullPointerException - if category and/or newLocale is null |
873 * @see SecurityManager.checkPermission(java.security.Permission) |
873 * @see SecurityManager#checkPermission(java.security.Permission) |
874 * @see PropertyPermission |
874 * @see PropertyPermission |
875 * @see #getDefault(Locale.Category) |
875 * @see #getDefault(Locale.Category) |
876 * @since 1.7 |
876 * @since 1.7 |
877 */ |
877 */ |
878 public static synchronized void setDefault(Locale.Category category, |
878 public static synchronized void setDefault(Locale.Category category, |
1230 * emitted as a private use subtag as above (even if the remainder |
1230 * emitted as a private use subtag as above (even if the remainder |
1231 * turns out to be well-formed). For example, |
1231 * turns out to be well-formed). For example, |
1232 * "Solaris_isjustthecoolestthing" is emitted as |
1232 * "Solaris_isjustthecoolestthing" is emitted as |
1233 * "x-lvariant-Solaris", not as "solaris".</li></ul> |
1233 * "x-lvariant-Solaris", not as "solaris".</li></ul> |
1234 * |
1234 * |
1235 * <p><b>Compatibility special cases:</b><ul> |
1235 * <p><b>Special Conversions:</b> Java supports some old locale |
1236 * |
1236 * representations, including deprecated ISO language codes, |
1237 * <li>The language codes "iw", "ji", and "in" are handled |
1237 * for compatibility. This method performs the following |
1238 * specially. Java uses these deprecated codes for compatibility |
1238 * conversions: |
1239 * reasons. The <code>toLanguageTag</code> method converts these |
1239 * <ul> |
1240 * three codes (and only these three) to "he", "yi", and "id" |
1240 * |
1241 * respectively. |
1241 * <li>Deprecated ISO language codes "iw", "ji", and "in" are |
|
1242 * converted to "he", "yi", and "id", respectively. |
1242 * |
1243 * |
1243 * <li>A locale with language "no", country "NO", and variant |
1244 * <li>A locale with language "no", country "NO", and variant |
1244 * "NY", representing Norwegian Nynorsk, will be represented as |
1245 * "NY", representing Norwegian Nynorsk (Norway), is converted |
1245 * having language "nn", country "NO", and empty variant. This is |
1246 * to a language tag "nn-NO".</li></ul> |
1246 * because some JVMs used the deprecated form to represent the |
|
1247 * user's default locale, and for compatibility reasons that Take a has |
|
1248 * not been changed.</ul> |
|
1249 * |
1247 * |
1250 * <p><b>Note:</b> Although the language tag created by this |
1248 * <p><b>Note:</b> Although the language tag created by this |
1251 * method is well-formed (satisfies the syntax requirements |
1249 * method is well-formed (satisfies the syntax requirements |
1252 * defined by the IETF BCP 47 specification), it is not |
1250 * defined by the IETF BCP 47 specification), it is not |
1253 * necessarily a valid BCP 47 language tag. For example, |
1251 * necessarily a valid BCP 47 language tag. For example, |
1325 * result locale (without case normalization). If it is then |
1323 * result locale (without case normalization). If it is then |
1326 * empty, the private use subtag is discarded: |
1324 * empty, the private use subtag is discarded: |
1327 * |
1325 * |
1328 * <pre> |
1326 * <pre> |
1329 * Locale loc; |
1327 * Locale loc; |
1330 * loc = Locale.forLanguageTag("en-US-x-lvariant-POSIX); |
1328 * loc = Locale.forLanguageTag("en-US-x-lvariant-POSIX"); |
1331 * loc.getVariant(); // returns "POSIX" |
1329 * loc.getVariant(); // returns "POSIX" |
1332 * loc.getExtension('x'); // returns null |
1330 * loc.getExtension('x'); // returns null |
1333 * |
1331 * |
1334 * loc = Locale.forLanguageTag("de-POSIX-x-URP-lvariant-Abc-Def"); |
1332 * loc = Locale.forLanguageTag("de-POSIX-x-URP-lvariant-Abc-Def"); |
1335 * loc.getVariant(); // returns "POSIX_Abc_Def" |
1333 * loc.getVariant(); // returns "POSIX_Abc_Def" |
1353 * <li>If, after processing, the locale would exactly match either |
1351 * <li>If, after processing, the locale would exactly match either |
1354 * ja_JP_JP or th_TH_TH with no extensions, the appropriate |
1352 * ja_JP_JP or th_TH_TH with no extensions, the appropriate |
1355 * extensions are added as though the constructor had been called: |
1353 * extensions are added as though the constructor had been called: |
1356 * |
1354 * |
1357 * <pre> |
1355 * <pre> |
1358 * Locale.forLanguageTag("ja-JP-x-lvariant-JP).toLanguageTag(); |
1356 * Locale.forLanguageTag("ja-JP-x-lvariant-JP").toLanguageTag(); |
1359 * // returns ja-JP-u-ca-japanese-x-lvariant-JP |
1357 * // returns "ja-JP-u-ca-japanese-x-lvariant-JP" |
1360 * Locale.forLanguageTag("th-TH-x-lvariant-TH).toLanguageTag(); |
1358 * Locale.forLanguageTag("th-TH-x-lvariant-TH").toLanguageTag(); |
1361 * // returns th-TH-u-nu-thai-x-lvariant-TH |
1359 * // returns "th-TH-u-nu-thai-x-lvariant-TH" |
1362 * <pre></ul> |
1360 * <pre></ul> |
1363 * |
1361 * |
1364 * <p>This implements the 'Language-Tag' production of BCP47, and |
1362 * <p>This implements the 'Language-Tag' production of BCP47, and |
1365 * so supports grandfathered (regular and irregular) as well as |
1363 * so supports grandfathered (regular and irregular) as well as |
1366 * private use language tags. Stand alone private use tags are |
1364 * private use language tags. Stand alone private use tags are |
1426 */ |
1424 */ |
1427 public static Locale forLanguageTag(String languageTag) { |
1425 public static Locale forLanguageTag(String languageTag) { |
1428 LanguageTag tag = LanguageTag.parse(languageTag, null); |
1426 LanguageTag tag = LanguageTag.parse(languageTag, null); |
1429 InternalLocaleBuilder bldr = new InternalLocaleBuilder(); |
1427 InternalLocaleBuilder bldr = new InternalLocaleBuilder(); |
1430 bldr.setLanguageTag(tag); |
1428 bldr.setLanguageTag(tag); |
1431 return getInstance(bldr.getBaseLocale(), bldr.getLocaleExtensions()); |
1429 BaseLocale base = bldr.getBaseLocale(); |
|
1430 LocaleExtensions exts = bldr.getLocaleExtensions(); |
|
1431 if (exts.isEmpty() && base.getVariant().length() > 0) { |
|
1432 exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(), base.getRegion(), base.getVariant()); |
|
1433 } |
|
1434 return getInstance(base, exts); |
1432 } |
1435 } |
1433 |
1436 |
1434 /** |
1437 /** |
1435 * Returns a three-letter abbreviation of this locale's language. |
1438 * Returns a three-letter abbreviation of this locale's language. |
1436 * If the language matches an ISO 639-1 two-letter code, the |
1439 * If the language matches an ISO 639-1 two-letter code, the |
2485 * @return A Locale. |
2488 * @return A Locale. |
2486 */ |
2489 */ |
2487 public Locale build() { |
2490 public Locale build() { |
2488 BaseLocale baseloc = _locbld.getBaseLocale(); |
2491 BaseLocale baseloc = _locbld.getBaseLocale(); |
2489 LocaleExtensions extensions = _locbld.getLocaleExtensions(); |
2492 LocaleExtensions extensions = _locbld.getLocaleExtensions(); |
|
2493 if (extensions.isEmpty() && baseloc.getVariant().length() > 0) { |
|
2494 extensions = getCompatibilityExtensions(baseloc.getLanguage(), baseloc.getScript(), |
|
2495 baseloc.getRegion(), baseloc.getVariant()); |
|
2496 } |
2490 return Locale.getInstance(baseloc, extensions); |
2497 return Locale.getInstance(baseloc, extensions); |
2491 } |
2498 } |
2492 } |
2499 } |
2493 } |
2500 } |