use of sun.util.locale.BaseLocale in project j2objc by google.
the class Locale method forLanguageTag.
/**
* Returns a locale for the specified IETF BCP 47 language tag string.
*
* <p>If the specified language tag contains any ill-formed subtags,
* the first such subtag and all following subtags are ignored. Compare
* to {@link Locale.Builder#setLanguageTag} which throws an exception
* in this case.
*
* <p>The following <b>conversions</b> are performed:<ul>
*
* <li>The language code "und" is mapped to language "".
*
* <li>The language codes "he", "yi", and "id" are mapped to "iw",
* "ji", and "in" respectively. (This is the same canonicalization
* that's done in Locale's constructors.)
*
* <li>The portion of a private use subtag prefixed by "lvariant",
* if any, is removed and appended to the variant field in the
* result locale (without case normalization). If it is then
* empty, the private use subtag is discarded:
*
* <pre>
* Locale loc;
* loc = Locale.forLanguageTag("en-US-x-lvariant-POSIX");
* loc.getVariant(); // returns "POSIX"
* loc.getExtension('x'); // returns null
*
* loc = Locale.forLanguageTag("de-POSIX-x-URP-lvariant-Abc-Def");
* loc.getVariant(); // returns "POSIX_Abc_Def"
* loc.getExtension('x'); // returns "urp"
* </pre>
*
* <li>When the languageTag argument contains an extlang subtag,
* the first such subtag is used as the language, and the primary
* language subtag and other extlang subtags are ignored:
*
* <pre>
* Locale.forLanguageTag("ar-aao").getLanguage(); // returns "aao"
* Locale.forLanguageTag("en-abc-def-us").toString(); // returns "abc_US"
* </pre>
*
* <li>Case is normalized except for variant tags, which are left
* unchanged. Language is normalized to lower case, script to
* title case, country to upper case, and extensions to lower
* case.
*
* <li>If, after processing, the locale would exactly match either
* ja_JP_JP or th_TH_TH with no extensions, the appropriate
* extensions are added as though the constructor had been called:
*
* <pre>
* Locale.forLanguageTag("ja-JP-x-lvariant-JP").toLanguageTag();
* // returns "ja-JP-u-ca-japanese-x-lvariant-JP"
* Locale.forLanguageTag("th-TH-x-lvariant-TH").toLanguageTag();
* // returns "th-TH-u-nu-thai-x-lvariant-TH"
* <pre></ul>
*
* <p>This implements the 'Language-Tag' production of BCP47, and
* so supports grandfathered (regular and irregular) as well as
* private use language tags. Stand alone private use tags are
* represented as empty language and extension 'x-whatever',
* and grandfathered tags are converted to their canonical replacements
* where they exist.
*
* <p>Grandfathered tags with canonical replacements are as follows:
*
* <table>
* <tbody align="center">
* <tr><th>grandfathered tag</th><th> </th><th>modern replacement</th></tr>
* <tr><td>art-lojban</td><td> </td><td>jbo</td></tr>
* <tr><td>i-ami</td><td> </td><td>ami</td></tr>
* <tr><td>i-bnn</td><td> </td><td>bnn</td></tr>
* <tr><td>i-hak</td><td> </td><td>hak</td></tr>
* <tr><td>i-klingon</td><td> </td><td>tlh</td></tr>
* <tr><td>i-lux</td><td> </td><td>lb</td></tr>
* <tr><td>i-navajo</td><td> </td><td>nv</td></tr>
* <tr><td>i-pwn</td><td> </td><td>pwn</td></tr>
* <tr><td>i-tao</td><td> </td><td>tao</td></tr>
* <tr><td>i-tay</td><td> </td><td>tay</td></tr>
* <tr><td>i-tsu</td><td> </td><td>tsu</td></tr>
* <tr><td>no-bok</td><td> </td><td>nb</td></tr>
* <tr><td>no-nyn</td><td> </td><td>nn</td></tr>
* <tr><td>sgn-BE-FR</td><td> </td><td>sfb</td></tr>
* <tr><td>sgn-BE-NL</td><td> </td><td>vgt</td></tr>
* <tr><td>sgn-CH-DE</td><td> </td><td>sgg</td></tr>
* <tr><td>zh-guoyu</td><td> </td><td>cmn</td></tr>
* <tr><td>zh-hakka</td><td> </td><td>hak</td></tr>
* <tr><td>zh-min-nan</td><td> </td><td>nan</td></tr>
* <tr><td>zh-xiang</td><td> </td><td>hsn</td></tr>
* </tbody>
* </table>
*
* <p>Grandfathered tags with no modern replacement will be
* converted as follows:
*
* <table>
* <tbody align="center">
* <tr><th>grandfathered tag</th><th> </th><th>converts to</th></tr>
* <tr><td>cel-gaulish</td><td> </td><td>xtg-x-cel-gaulish</td></tr>
* <tr><td>en-GB-oed</td><td> </td><td>en-GB-x-oed</td></tr>
* <tr><td>i-default</td><td> </td><td>en-x-i-default</td></tr>
* <tr><td>i-enochian</td><td> </td><td>und-x-i-enochian</td></tr>
* <tr><td>i-mingo</td><td> </td><td>see-x-i-mingo</td></tr>
* <tr><td>zh-min</td><td> </td><td>nan-x-zh-min</td></tr>
* </tbody>
* </table>
*
* <p>For a list of all grandfathered tags, see the
* IANA Language Subtag Registry (search for "Type: grandfathered").
*
* <p><b>Note</b>: there is no guarantee that <code>toLanguageTag</code>
* and <code>forLanguageTag</code> will round-trip.
*
* @param languageTag the language tag
* @return The locale that best represents the language tag.
* @throws NullPointerException if <code>languageTag</code> is <code>null</code>
* @see #toLanguageTag()
* @see java.util.Locale.Builder#setLanguageTag(String)
* @since 1.7
*/
public static Locale forLanguageTag(String languageTag) {
LanguageTag tag = LanguageTag.parse(languageTag, null);
InternalLocaleBuilder bldr = new InternalLocaleBuilder();
bldr.setLanguageTag(tag);
BaseLocale base = bldr.getBaseLocale();
LocaleExtensions exts = bldr.getLocaleExtensions();
if (exts == null && base.getVariant().length() > 0) {
exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(), base.getRegion(), base.getVariant());
}
return getInstance(base, exts);
}
use of sun.util.locale.BaseLocale in project jdk8u_jdk by JetBrains.
the class Locale method forLanguageTag.
/**
* Returns a locale for the specified IETF BCP 47 language tag string.
*
* <p>If the specified language tag contains any ill-formed subtags,
* the first such subtag and all following subtags are ignored. Compare
* to {@link Locale.Builder#setLanguageTag} which throws an exception
* in this case.
*
* <p>The following <b>conversions</b> are performed:<ul>
*
* <li>The language code "und" is mapped to language "".
*
* <li>The language codes "he", "yi", and "id" are mapped to "iw",
* "ji", and "in" respectively. (This is the same canonicalization
* that's done in Locale's constructors.)
*
* <li>The portion of a private use subtag prefixed by "lvariant",
* if any, is removed and appended to the variant field in the
* result locale (without case normalization). If it is then
* empty, the private use subtag is discarded:
*
* <pre>
* Locale loc;
* loc = Locale.forLanguageTag("en-US-x-lvariant-POSIX");
* loc.getVariant(); // returns "POSIX"
* loc.getExtension('x'); // returns null
*
* loc = Locale.forLanguageTag("de-POSIX-x-URP-lvariant-Abc-Def");
* loc.getVariant(); // returns "POSIX_Abc_Def"
* loc.getExtension('x'); // returns "urp"
* </pre>
*
* <li>When the languageTag argument contains an extlang subtag,
* the first such subtag is used as the language, and the primary
* language subtag and other extlang subtags are ignored:
*
* <pre>
* Locale.forLanguageTag("ar-aao").getLanguage(); // returns "aao"
* Locale.forLanguageTag("en-abc-def-us").toString(); // returns "abc_US"
* </pre>
*
* <li>Case is normalized except for variant tags, which are left
* unchanged. Language is normalized to lower case, script to
* title case, country to upper case, and extensions to lower
* case.
*
* <li>If, after processing, the locale would exactly match either
* ja_JP_JP or th_TH_TH with no extensions, the appropriate
* extensions are added as though the constructor had been called:
*
* <pre>
* Locale.forLanguageTag("ja-JP-x-lvariant-JP").toLanguageTag();
* // returns "ja-JP-u-ca-japanese-x-lvariant-JP"
* Locale.forLanguageTag("th-TH-x-lvariant-TH").toLanguageTag();
* // returns "th-TH-u-nu-thai-x-lvariant-TH"
* </pre></ul>
*
* <p>This implements the 'Language-Tag' production of BCP47, and
* so supports grandfathered (regular and irregular) as well as
* private use language tags. Stand alone private use tags are
* represented as empty language and extension 'x-whatever',
* and grandfathered tags are converted to their canonical replacements
* where they exist.
*
* <p>Grandfathered tags with canonical replacements are as follows:
*
* <table summary="Grandfathered tags with canonical replacements">
* <tbody align="center">
* <tr><th>grandfathered tag</th><th> </th><th>modern replacement</th></tr>
* <tr><td>art-lojban</td><td> </td><td>jbo</td></tr>
* <tr><td>i-ami</td><td> </td><td>ami</td></tr>
* <tr><td>i-bnn</td><td> </td><td>bnn</td></tr>
* <tr><td>i-hak</td><td> </td><td>hak</td></tr>
* <tr><td>i-klingon</td><td> </td><td>tlh</td></tr>
* <tr><td>i-lux</td><td> </td><td>lb</td></tr>
* <tr><td>i-navajo</td><td> </td><td>nv</td></tr>
* <tr><td>i-pwn</td><td> </td><td>pwn</td></tr>
* <tr><td>i-tao</td><td> </td><td>tao</td></tr>
* <tr><td>i-tay</td><td> </td><td>tay</td></tr>
* <tr><td>i-tsu</td><td> </td><td>tsu</td></tr>
* <tr><td>no-bok</td><td> </td><td>nb</td></tr>
* <tr><td>no-nyn</td><td> </td><td>nn</td></tr>
* <tr><td>sgn-BE-FR</td><td> </td><td>sfb</td></tr>
* <tr><td>sgn-BE-NL</td><td> </td><td>vgt</td></tr>
* <tr><td>sgn-CH-DE</td><td> </td><td>sgg</td></tr>
* <tr><td>zh-guoyu</td><td> </td><td>cmn</td></tr>
* <tr><td>zh-hakka</td><td> </td><td>hak</td></tr>
* <tr><td>zh-min-nan</td><td> </td><td>nan</td></tr>
* <tr><td>zh-xiang</td><td> </td><td>hsn</td></tr>
* </tbody>
* </table>
*
* <p>Grandfathered tags with no modern replacement will be
* converted as follows:
*
* <table summary="Grandfathered tags with no modern replacement">
* <tbody align="center">
* <tr><th>grandfathered tag</th><th> </th><th>converts to</th></tr>
* <tr><td>cel-gaulish</td><td> </td><td>xtg-x-cel-gaulish</td></tr>
* <tr><td>en-GB-oed</td><td> </td><td>en-GB-x-oed</td></tr>
* <tr><td>i-default</td><td> </td><td>en-x-i-default</td></tr>
* <tr><td>i-enochian</td><td> </td><td>und-x-i-enochian</td></tr>
* <tr><td>i-mingo</td><td> </td><td>see-x-i-mingo</td></tr>
* <tr><td>zh-min</td><td> </td><td>nan-x-zh-min</td></tr>
* </tbody>
* </table>
*
* <p>For a list of all grandfathered tags, see the
* IANA Language Subtag Registry (search for "Type: grandfathered").
*
* <p><b>Note</b>: there is no guarantee that <code>toLanguageTag</code>
* and <code>forLanguageTag</code> will round-trip.
*
* @param languageTag the language tag
* @return The locale that best represents the language tag.
* @throws NullPointerException if <code>languageTag</code> is <code>null</code>
* @see #toLanguageTag()
* @see java.util.Locale.Builder#setLanguageTag(String)
* @since 1.7
*/
public static Locale forLanguageTag(String languageTag) {
LanguageTag tag = LanguageTag.parse(languageTag, null);
InternalLocaleBuilder bldr = new InternalLocaleBuilder();
bldr.setLanguageTag(tag);
BaseLocale base = bldr.getBaseLocale();
LocaleExtensions exts = bldr.getLocaleExtensions();
if (exts == null && base.getVariant().length() > 0) {
exts = getCompatibilityExtensions(base.getLanguage(), base.getScript(), base.getRegion(), base.getVariant());
}
return getInstance(base, exts);
}
Aggregations