Search in sources :

Example 6 with LanguageTag

use of sun.util.locale.LanguageTag in project jdk8u_jdk by JetBrains.

the class Locale method toLanguageTag.

/**
     * Returns a well-formed IETF BCP 47 language tag representing
     * this locale.
     *
     * <p>If this <code>Locale</code> has a language, country, or
     * variant that does not satisfy the IETF BCP 47 language tag
     * syntax requirements, this method handles these fields as
     * described below:
     *
     * <p><b>Language:</b> If language is empty, or not <a
     * href="#def_language" >well-formed</a> (for example "a" or
     * "e2"), it will be emitted as "und" (Undetermined).
     *
     * <p><b>Country:</b> If country is not <a
     * href="#def_region">well-formed</a> (for example "12" or "USA"),
     * it will be omitted.
     *
     * <p><b>Variant:</b> If variant <b>is</b> <a
     * href="#def_variant">well-formed</a>, each sub-segment
     * (delimited by '-' or '_') is emitted as a subtag.  Otherwise:
     * <ul>
     *
     * <li>if all sub-segments match <code>[0-9a-zA-Z]{1,8}</code>
     * (for example "WIN" or "Oracle_JDK_Standard_Edition"), the first
     * ill-formed sub-segment and all following will be appended to
     * the private use subtag.  The first appended subtag will be
     * "lvariant", followed by the sub-segments in order, separated by
     * hyphen. For example, "x-lvariant-WIN",
     * "Oracle-x-lvariant-JDK-Standard-Edition".
     *
     * <li>if any sub-segment does not match
     * <code>[0-9a-zA-Z]{1,8}</code>, the variant will be truncated
     * and the problematic sub-segment and all following sub-segments
     * will be omitted.  If the remainder is non-empty, it will be
     * emitted as a private use subtag as above (even if the remainder
     * turns out to be well-formed).  For example,
     * "Solaris_isjustthecoolestthing" is emitted as
     * "x-lvariant-Solaris", not as "solaris".</li></ul>
     *
     * <p><b>Special Conversions:</b> Java supports some old locale
     * representations, including deprecated ISO language codes,
     * for compatibility. This method performs the following
     * conversions:
     * <ul>
     *
     * <li>Deprecated ISO language codes "iw", "ji", and "in" are
     * converted to "he", "yi", and "id", respectively.
     *
     * <li>A locale with language "no", country "NO", and variant
     * "NY", representing Norwegian Nynorsk (Norway), is converted
     * to a language tag "nn-NO".</li></ul>
     *
     * <p><b>Note:</b> Although the language tag created by this
     * method is well-formed (satisfies the syntax requirements
     * defined by the IETF BCP 47 specification), it is not
     * necessarily a valid BCP 47 language tag.  For example,
     * <pre>
     *   new Locale("xx", "YY").toLanguageTag();</pre>
     *
     * will return "xx-YY", but the language subtag "xx" and the
     * region subtag "YY" are invalid because they are not registered
     * in the IANA Language Subtag Registry.
     *
     * @return a BCP47 language tag representing the locale
     * @see #forLanguageTag(String)
     * @since 1.7
     */
public String toLanguageTag() {
    if (languageTag != null) {
        return languageTag;
    }
    LanguageTag tag = LanguageTag.parseLocale(baseLocale, localeExtensions);
    StringBuilder buf = new StringBuilder();
    String subtag = tag.getLanguage();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.canonicalizeLanguage(subtag));
    }
    subtag = tag.getScript();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeScript(subtag));
    }
    subtag = tag.getRegion();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeRegion(subtag));
    }
    List<String> subtags = tag.getVariants();
    for (String s : subtags) {
        buf.append(LanguageTag.SEP);
        // preserve casing
        buf.append(s);
    }
    subtags = tag.getExtensions();
    for (String s : subtags) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeExtension(s));
    }
    subtag = tag.getPrivateuse();
    if (subtag.length() > 0) {
        if (buf.length() > 0) {
            buf.append(LanguageTag.SEP);
        }
        buf.append(LanguageTag.PRIVATEUSE).append(LanguageTag.SEP);
        // preserve casing
        buf.append(subtag);
    }
    String langTag = buf.toString();
    synchronized (this) {
        if (languageTag == null) {
            languageTag = langTag;
        }
    }
    return languageTag;
}
Also used : LanguageTag(sun.util.locale.LanguageTag)

Example 7 with LanguageTag

use of sun.util.locale.LanguageTag in project checker-framework by typetools.

the class Locale method toLanguageTag.

/**
 * Returns a well-formed IETF BCP 47 language tag representing
 * this locale.
 *
 * <p>If this <code>Locale</code> has a language, country, or
 * variant that does not satisfy the IETF BCP 47 language tag
 * syntax requirements, this method handles these fields as
 * described below:
 *
 * <p><b>Language:</b> If language is empty, or not <a
 * href="#def_language" >well-formed</a> (for example "a" or
 * "e2"), it will be emitted as "und" (Undetermined).
 *
 * <p><b>Country:</b> If country is not <a
 * href="#def_region">well-formed</a> (for example "12" or "USA"),
 * it will be omitted.
 *
 * <p><b>Variant:</b> If variant <b>is</b> <a
 * href="#def_variant">well-formed</a>, each sub-segment
 * (delimited by '-' or '_') is emitted as a subtag.  Otherwise:
 * <ul>
 *
 * <li>if all sub-segments match <code>[0-9a-zA-Z]{1,8}</code>
 * (for example "WIN" or "Oracle_JDK_Standard_Edition"), the first
 * ill-formed sub-segment and all following will be appended to
 * the private use subtag.  The first appended subtag will be
 * "lvariant", followed by the sub-segments in order, separated by
 * hyphen. For example, "x-lvariant-WIN",
 * "Oracle-x-lvariant-JDK-Standard-Edition".
 *
 * <li>if any sub-segment does not match
 * <code>[0-9a-zA-Z]{1,8}</code>, the variant will be truncated
 * and the problematic sub-segment and all following sub-segments
 * will be omitted.  If the remainder is non-empty, it will be
 * emitted as a private use subtag as above (even if the remainder
 * turns out to be well-formed).  For example,
 * "Solaris_isjustthecoolestthing" is emitted as
 * "x-lvariant-Solaris", not as "solaris".</li></ul>
 *
 * <p><b>Special Conversions:</b> Java supports some old locale
 * representations, including deprecated ISO language codes,
 * for compatibility. This method performs the following
 * conversions:
 * <ul>
 *
 * <li>Deprecated ISO language codes "iw", "ji", and "in" are
 * converted to "he", "yi", and "id", respectively.
 *
 * <li>A locale with language "no", country "NO", and variant
 * "NY", representing Norwegian Nynorsk (Norway), is converted
 * to a language tag "nn-NO".</li></ul>
 *
 * <p><b>Note:</b> Although the language tag created by this
 * method is well-formed (satisfies the syntax requirements
 * defined by the IETF BCP 47 specification), it is not
 * necessarily a valid BCP 47 language tag.  For example,
 * <pre>
 *   new Locale("xx", "YY").toLanguageTag();</pre>
 *
 * will return "xx-YY", but the language subtag "xx" and the
 * region subtag "YY" are invalid because they are not registered
 * in the IANA Language Subtag Registry.
 *
 * @return a BCP47 language tag representing the locale
 * @see #forLanguageTag(String)
 * @since 1.7
 */
public String toLanguageTag() {
    if (languageTag != null) {
        return languageTag;
    }
    LanguageTag tag = LanguageTag.parseLocale(baseLocale, localeExtensions);
    StringBuilder buf = new StringBuilder();
    String subtag = tag.getLanguage();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.canonicalizeLanguage(subtag));
    }
    subtag = tag.getScript();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeScript(subtag));
    }
    subtag = tag.getRegion();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeRegion(subtag));
    }
    List<String> subtags = tag.getVariants();
    for (String s : subtags) {
        buf.append(LanguageTag.SEP);
        // preserve casing
        buf.append(s);
    }
    subtags = tag.getExtensions();
    for (String s : subtags) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeExtension(s));
    }
    subtag = tag.getPrivateuse();
    if (subtag.length() > 0) {
        if (buf.length() > 0) {
            buf.append(LanguageTag.SEP);
        }
        buf.append(LanguageTag.PRIVATEUSE).append(LanguageTag.SEP);
        // preserve casing
        buf.append(subtag);
    }
    String langTag = buf.toString();
    synchronized (this) {
        if (languageTag == null) {
            languageTag = langTag;
        }
    }
    return languageTag;
}
Also used : LanguageTag(sun.util.locale.LanguageTag)

Example 8 with LanguageTag

use of sun.util.locale.LanguageTag in project Bytecoder by mirkosertic.

the class Locale method toLanguageTag.

/**
 * Returns a well-formed IETF BCP 47 language tag representing
 * this locale.
 *
 * <p>If this <code>Locale</code> has a language, country, or
 * variant that does not satisfy the IETF BCP 47 language tag
 * syntax requirements, this method handles these fields as
 * described below:
 *
 * <p><b>Language:</b> If language is empty, or not <a
 * href="#def_language" >well-formed</a> (for example "a" or
 * "e2"), it will be emitted as "und" (Undetermined).
 *
 * <p><b>Country:</b> If country is not <a
 * href="#def_region">well-formed</a> (for example "12" or "USA"),
 * it will be omitted.
 *
 * <p><b>Variant:</b> If variant <b>is</b> <a
 * href="#def_variant">well-formed</a>, each sub-segment
 * (delimited by '-' or '_') is emitted as a subtag.  Otherwise:
 * <ul>
 *
 * <li>if all sub-segments match <code>[0-9a-zA-Z]{1,8}</code>
 * (for example "WIN" or "Oracle_JDK_Standard_Edition"), the first
 * ill-formed sub-segment and all following will be appended to
 * the private use subtag.  The first appended subtag will be
 * "lvariant", followed by the sub-segments in order, separated by
 * hyphen. For example, "x-lvariant-WIN",
 * "Oracle-x-lvariant-JDK-Standard-Edition".
 *
 * <li>if any sub-segment does not match
 * <code>[0-9a-zA-Z]{1,8}</code>, the variant will be truncated
 * and the problematic sub-segment and all following sub-segments
 * will be omitted.  If the remainder is non-empty, it will be
 * emitted as a private use subtag as above (even if the remainder
 * turns out to be well-formed).  For example,
 * "Solaris_isjustthecoolestthing" is emitted as
 * "x-lvariant-Solaris", not as "solaris".</li></ul>
 *
 * <p><b>Special Conversions:</b> Java supports some old locale
 * representations, including deprecated ISO language codes,
 * for compatibility. This method performs the following
 * conversions:
 * <ul>
 *
 * <li>Deprecated ISO language codes "iw", "ji", and "in" are
 * converted to "he", "yi", and "id", respectively.
 *
 * <li>A locale with language "no", country "NO", and variant
 * "NY", representing Norwegian Nynorsk (Norway), is converted
 * to a language tag "nn-NO".</li></ul>
 *
 * <p><b>Note:</b> Although the language tag created by this
 * method is well-formed (satisfies the syntax requirements
 * defined by the IETF BCP 47 specification), it is not
 * necessarily a valid BCP 47 language tag.  For example,
 * <pre>
 *   new Locale("xx", "YY").toLanguageTag();</pre>
 *
 * will return "xx-YY", but the language subtag "xx" and the
 * region subtag "YY" are invalid because they are not registered
 * in the IANA Language Subtag Registry.
 *
 * @return a BCP47 language tag representing the locale
 * @see #forLanguageTag(String)
 * @since 1.7
 */
public String toLanguageTag() {
    if (languageTag != null) {
        return languageTag;
    }
    LanguageTag tag = LanguageTag.parseLocale(baseLocale, localeExtensions);
    StringBuilder buf = new StringBuilder();
    String subtag = tag.getLanguage();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.canonicalizeLanguage(subtag));
    }
    subtag = tag.getScript();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeScript(subtag));
    }
    subtag = tag.getRegion();
    if (subtag.length() > 0) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeRegion(subtag));
    }
    List<String> subtags = tag.getVariants();
    for (String s : subtags) {
        buf.append(LanguageTag.SEP);
        // preserve casing
        buf.append(s);
    }
    subtags = tag.getExtensions();
    for (String s : subtags) {
        buf.append(LanguageTag.SEP);
        buf.append(LanguageTag.canonicalizeExtension(s));
    }
    subtag = tag.getPrivateuse();
    if (subtag.length() > 0) {
        if (buf.length() > 0) {
            buf.append(LanguageTag.SEP);
        }
        buf.append(LanguageTag.PRIVATEUSE).append(LanguageTag.SEP);
        // preserve casing
        buf.append(subtag);
    }
    String langTag = buf.toString();
    synchronized (this) {
        if (languageTag == null) {
            languageTag = langTag;
        }
    }
    return languageTag;
}
Also used : LanguageTag(sun.util.locale.LanguageTag)

Aggregations

LanguageTag (sun.util.locale.LanguageTag)8 BaseLocale (sun.util.locale.BaseLocale)4 InternalLocaleBuilder (sun.util.locale.InternalLocaleBuilder)4 LocaleExtensions (sun.util.locale.LocaleExtensions)4