Search in sources :

Example 21 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class DateTimeFormatObject method createDateFormat.

private DateFormat createDateFormat() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    // calendar and numberingSystem are already handled in language-tag
    // assert locale.getKeywordValue("calendar").equals(calendar);
    // assert locale.getKeywordValue("numbers").equals(numberingSystem);
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern.get(), locale);
    if (timeZone != null) {
        dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    }
    Calendar calendar = dateFormat.getCalendar();
    if (calendar instanceof GregorianCalendar) {
        // format uses a proleptic Gregorian calendar with no year 0
        GregorianCalendar gregorian = (GregorianCalendar) calendar;
        gregorian.setGregorianChange(new Date(Long.MIN_VALUE));
    }
    return dateFormat;
}
Also used : ULocale(com.ibm.icu.util.ULocale) Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat) Date(java.util.Date)

Example 22 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class DateTimeFormatConstructor method BestFitFormatMatcher.

/**
 * 12.1.4 BestFitFormatMatcher (options, formats)
 *
 * @param formatRecord
 *            the format matcher record
 * @param dataLocale
 *            the locale
 * @return the best applicable pattern
 */
public static String BestFitFormatMatcher(FormatMatcherRecord formatRecord, String dataLocale) {
    // Let ICU4J compute the best applicable pattern for the requested input values
    ULocale locale = ULocale.forLanguageTag(dataLocale);
    DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale);
    String pattern = generator.getBestPattern(formatRecord.toSkeleton());
    // Fixup the hour representation to match the expected hour cycle.
    if (formatRecord.isTime() && formatRecord.hasNonDefaultHourCycle(locale)) {
        pattern = modifyHour(formatRecord, pattern);
    }
    return pattern;
}
Also used : ULocale(com.ibm.icu.util.ULocale) DateTimePatternGenerator(com.ibm.icu.text.DateTimePatternGenerator)

Example 23 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class IntlAbstractOperations method addLikelySubtagsWithDefaults.

private static ULocale addLikelySubtagsWithDefaults(ULocale locale) {
    ULocale maximized = ULocale.addLikelySubtags(locale);
    if (maximized == locale) {
        // If already in maximal form or no data available for maximization, make sure
        // language, script and region are not undefined (ICU4J expects all are defined).
        String language = locale.getLanguage();
        String script = locale.getScript();
        String region = locale.getCountry();
        if (language.isEmpty() || script.isEmpty() || region.isEmpty()) {
            return new ULocale(toLocaleId(language, script, region));
        }
    }
    return maximized;
}
Also used : ULocale(com.ibm.icu.util.ULocale)

Example 24 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class NumberFormatObject method createNumberFormat.

private NumberFormat createNumberFormat() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    int choice;
    if ("decimal".equals(style)) {
        choice = NumberFormat.NUMBERSTYLE;
    } else if ("percent".equals(style)) {
        choice = NumberFormat.PERCENTSTYLE;
    } else {
        if ("code".equals(currencyDisplay)) {
            choice = NumberFormat.ISOCURRENCYSTYLE;
        } else if ("symbol".equals(currencyDisplay)) {
            choice = NumberFormat.CURRENCYSTYLE;
        } else {
            choice = NumberFormat.PLURALCURRENCYSTYLE;
        }
    }
    DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, choice);
    if ("currency".equals(style)) {
        numberFormat.setCurrency(Currency.getInstance(currency));
    }
    // assert locale.getKeywordValue("numbers").equals(numberingSystem);
    if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) {
        numberFormat.setSignificantDigitsUsed(true);
        numberFormat.setMinimumSignificantDigits(minimumSignificantDigits);
        numberFormat.setMaximumSignificantDigits(maximumSignificantDigits);
    } else {
        numberFormat.setSignificantDigitsUsed(false);
        numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
        numberFormat.setMinimumFractionDigits(minimumFractionDigits);
        numberFormat.setMaximumFractionDigits(maximumFractionDigits);
    }
    numberFormat.setGroupingUsed(useGrouping);
    // as required by ToRawPrecision/ToRawFixed
    // FIXME: ICU4J bug:
    // new Intl.NumberFormat("en",{useGrouping:false}).format(111111111111111)
    // returns "111111111111111.02"
    numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP);
    return numberFormat;
}
Also used : ULocale(com.ibm.icu.util.ULocale) DecimalFormat(com.ibm.icu.text.DecimalFormat)

Example 25 with ULocale

use of com.ibm.icu.util.ULocale in project es6draft by anba.

the class SegmenterObject method createBreakIterator.

private BreakIterator createBreakIterator() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    if ("line".equals(granularity)) {
        // "strictness" cannot be set through unicode extensions (u-lb-strict), handle here:
        locale = locale.setKeywordValue("lb", strictness);
    }
    BreakIterator breakIterator;
    switch(granularity) {
        case "grapheme":
            breakIterator = BreakIterator.getCharacterInstance(locale);
            break;
        case "word":
            breakIterator = BreakIterator.getWordInstance(locale);
            break;
        case "sentence":
            breakIterator = BreakIterator.getSentenceInstance(locale);
            break;
        case "line":
            breakIterator = BreakIterator.getLineInstance(locale);
            break;
        default:
            throw new AssertionError();
    }
    return breakIterator;
}
Also used : ULocale(com.ibm.icu.util.ULocale) BreakIterator(com.ibm.icu.text.BreakIterator)

Aggregations

ULocale (com.ibm.icu.util.ULocale)25 RuleBasedCollator (com.ibm.icu.text.RuleBasedCollator)5 Collator (com.ibm.icu.text.Collator)2 DateTimePatternGenerator (com.ibm.icu.text.DateTimePatternGenerator)2 DecimalFormat (com.ibm.icu.text.DecimalFormat)2 SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Detector (com.cybozu.labs.langdetect.Detector)1 LangDetectException (com.cybozu.labs.langdetect.LangDetectException)1 Language (com.cybozu.labs.langdetect.Language)1 Skeleton (com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.Skeleton)1 CacheLoader (com.google.common.cache.CacheLoader)1 LocaleString (com.google.template.soy.shared.restricted.ApiCallScopeBindingAnnotations.LocaleString)1 ICUResourceBundle (com.ibm.icu.impl.ICUResourceBundle)1 BreakIterator (com.ibm.icu.text.BreakIterator)1 ListFormatter (com.ibm.icu.text.ListFormatter)1