Package com.ibm.icu.impl.locale

Examples of com.ibm.icu.impl.locale.LanguageTag


         * @draft ICU 4.2
         * @provisional This API might change or be removed in a future release.
         */
        public Builder setLanguageTag(String langtag) {
            clear();
            LanguageTag tag = null;
            try {
                tag = LanguageTag.parse(langtag);
            } catch (LocaleSyntaxException e) {
                throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
            }

            // base locale fields
            String extlang = tag.getExtlang(0);
            String language = extlang == null ? tag.getLanguage() : extlang;
            setLanguage(language.equals("und") ? "": language).setScript(tag.getScript())
                .setRegion(tag.getRegion()).setVariant(tag.getVariant());

            // extensions
            Set exts = tag.getExtensions();
            if (exts != null) {
                Iterator itr = exts.iterator();
                while (itr.hasNext()) {
                    Extension e = (Extension)itr.next();
                    setExtension(e.getSingleton(), e.getValue());
                    //TODO: setExtension may throw an IllformedLocaleException.
                    //      In this csae, error index must be recalculated.
                }
            }
            // private use
            setExtension(PRIVATE_USE_EXTENSION, tag.getPrivateUse());
            return this;
        }
View Full Code Here


     * @provisional This API might change or be removed in a future release.
     */
    public static ULocale forLanguageTag(String langtag) {
//        ULocale locale = ULocale.ROOT;
        ULocale locale = new ULocale("");
        LanguageTag tag = null;
        while (true) {
            try {
                tag = LanguageTag.parse(langtag);

                Builder bldr = new Builder();

                String extlang = tag.getExtlang(0);
                String language = (extlang == null) ? tag.getLanguage() : extlang;
                // do nothing with language code "und"
                if (!language.equals("und")) {
                    bldr.setLanguage(language);
                }

                bldr.setScript(tag.getScript())
                    .setRegion(tag.getRegion()).setVariant(tag.getVariant());

                // setExtension may throw an exception if
                // it contains malformed LDML keys.
                Set exts = tag.getExtensions();
                if (exts != null) {
                    Iterator itr = exts.iterator();
                    while (itr.hasNext()) {
                        Extension e = (Extension)itr.next();
                        bldr.setExtension(e.getSingleton(), e.getValue());
                    }
                }
                bldr.setExtension(PRIVATE_USE_EXTENSION, tag.getPrivateUse());
                locale = bldr.create();
                break;
            } catch (LocaleSyntaxException e) {
                // this exception was thrown by LanguageTag#parse
                // - fall through
View Full Code Here

          throw new RuntimeException(e);
        }
      }
    }

    LanguageTag tag = LanguageTag.parseLocale(base, exts);

    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);
      buf.append(LanguageTag.canonicalizeVariant(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);
View Full Code Here

   * @see ULocale.Builder#setLanguageTag(String)
   *
   * @stable ICU 4.2
   */
  public static ULocale forLanguageTag(final String languageTag) {
    LanguageTag tag = LanguageTag.parse(languageTag, null);
    InternalLocaleBuilder bldr = new InternalLocaleBuilder();
    bldr.setLanguageTag(tag);
    return getInstance(bldr.getBaseLocale(), bldr.getLocaleExtensions());
  }
View Full Code Here

     *
     * @stable ICU 4.2
     */
    public Builder setLanguageTag(final String languageTag) {
      ParseStatus sts = new ParseStatus();
      LanguageTag tag = LanguageTag.parse(languageTag, sts);
      if (sts.isError()) {
        throw new IllformedLocaleException(sts.getErrorMessage(), sts.getErrorIndex());
      }
      _locbld.setLanguageTag(tag);

View Full Code Here

         * @draft ICU 4.2
         * @provisional This API might change or be removed in a future release.
         */
        public Builder setLanguageTag(String languageTag) {
            ParseStatus sts = new ParseStatus();
            LanguageTag tag = LanguageTag.parse(languageTag, sts);
            if (sts.isError()) {
                throw new IllformedLocaleException(sts.getErrorMessage(), sts.getErrorIndex());
            }
            _locbld.setLanguageTag(tag);

View Full Code Here

                    throw new RuntimeException(e);
                }
            }
        }

        LanguageTag tag = LanguageTag.parseLocale(base, exts);

        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);
            buf.append(LanguageTag.canonicalizeVariant(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);
View Full Code Here

     *
     * @draft ICU 4.2
     * @provisional This API might change or be removed in a future release.
     */
    public static ULocale forLanguageTag(String languageTag) {
        LanguageTag tag = LanguageTag.parse(languageTag, null);
        InternalLocaleBuilder bldr = new InternalLocaleBuilder();
        bldr.setLanguageTag(tag);
        return getInstance(bldr.getBaseLocale(), bldr.getLocaleExtensions());
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.impl.locale.LanguageTag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.