当前位置: 首页>>代码示例>>Java>>正文


Java ULocale类代码示例

本文整理汇总了Java中com.ibm.icu.util.ULocale的典型用法代码示例。如果您正苦于以下问题:Java ULocale类的具体用法?Java ULocale怎么用?Java ULocale使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ULocale类属于com.ibm.icu.util包,在下文中一共展示了ULocale类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomRules

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
public void testCustomRules() throws Exception {
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE"));
    String DIN5007_2_tailorings =
            "& ae , a\u0308 & AE , A\u0308"+
                    "& oe , o\u0308 & OE , O\u0308"+
                    "& ue , u\u0308 & UE , u\u0308";

    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();

    Settings settings = Settings.builder()
            .put("index.analysis.filter.myCollator.type", "icu_collation")
            .put("index.analysis.filter.myCollator.rules", tailoredRules)
            .put("index.analysis.filter.myCollator.strength", "primary")
            .build();
    TestAnalysis analysis = createTestAnalysis(new Index("test", "_na_"), settings, new AnalysisICUPlugin());

    TokenFilterFactory filterFactory = analysis.tokenFilter.get("myCollator");
    assertCollatesToSame(filterFactory, "Töne", "Toene");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SimpleIcuCollationTokenFilterTests.java

示例2: getCalendarTypeToUse

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
private String getCalendarTypeToUse(ULocale uLocale) {
    // Get the correct calendar type
    // TODO: C++ and Java are inconsistent (see #9952).
    String calendarTypeToUse = uLocale.getKeywordValue("calendar");
    if ( calendarTypeToUse == null ) {
        String[] preferredCalendarTypes = Calendar.getKeywordValuesForLocale("calendar", uLocale, true);
        calendarTypeToUse = preferredCalendarTypes[0]; // the most preferred calendar
    }
    if ( calendarTypeToUse == null ) {
        calendarTypeToUse = "gregorian"; // fallback
    }
    return calendarTypeToUse;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:14,代码来源:DateTimePatternGenerator.java

示例3: getCaseLocale

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
static final int getCaseLocale(ULocale locale, int[] locCache) {
    int result;

    if(locCache!=null && (result=locCache[0])!=LOC_UNKNOWN) {
        return result;
    }

    result=LOC_ROOT;

    String language=locale.getLanguage();
    if(language.equals("tr") || language.equals("tur") || language.equals("az") || language.equals("aze")) {
        result=LOC_TURKISH;
    } else if(language.equals("el") || language.equals("ell")) {
        result=LOC_GREEK;
    } else if(language.equals("lt") || language.equals("lit")) {
        result=LOC_LITHUANIAN;
    }

    if(locCache!=null) {
        locCache[0]=result;
    }
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:24,代码来源:UCaseProps.java

示例4: getDisplayName

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Given a visible id, return the display name in the requested locale.
 * If there is no directly supported id corresponding to this id, return
 * null.
 */
public String getDisplayName(String id, ULocale locale) {
    Map<String, Factory> m = getVisibleIDMap();
    Factory f = m.get(id);
    if (f != null) {
        return f.getDisplayName(id, locale);
    }

    Key key = createKey(id);
    while (key.fallback()) {
        f = m.get(key.currentID());
        if (f != null) {
            return f.getDisplayName(id, locale);
        }
    }

    return null;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:23,代码来源:ICUService.java

示例5: getInstance

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Returns a RelativeDateTimeFormatter for a particular locale that uses a particular
 * NumberFormat object, style, and capitalization context
 *
 * @param locale the locale
 * @param nf the number format object. It is defensively copied to ensure thread-safety
 * and immutability of this class. May be null.
 * @param style the style.
 * @param capitalizationContext the capitalization context.
 * @stable ICU 54
 */
public static RelativeDateTimeFormatter getInstance(
        ULocale locale,
        NumberFormat nf,
        Style style,
        DisplayContext capitalizationContext) {
    RelativeDateTimeFormatterData data = cache.get(locale);
    if (nf == null) {
        nf = NumberFormat.getInstance(locale);
    } else {
        nf = (NumberFormat) nf.clone();
    }
    return new RelativeDateTimeFormatter(
            data.qualitativeUnitMap,
            data.relUnitPatternMap,
            SimpleFormatterImpl.compileToStringMinMaxArguments(
                    data.dateTimePattern, new StringBuilder(), 2, 2),
            PluralRules.forLocale(locale),
            nf,
            style,
            capitalizationContext,
            capitalizationContext == DisplayContext.CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE ?
                BreakIterator.getSentenceInstance(locale) : null,
            locale);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:36,代码来源:RelativeDateTimeFormatter.java

示例6: RelativeDateTimeFormatter

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
private RelativeDateTimeFormatter(
        EnumMap<Style, EnumMap<AbsoluteUnit, EnumMap<Direction, String>>> qualitativeUnitMap,
        EnumMap<Style, EnumMap<RelativeUnit, String[][]>> patternMap,
        String combinedDateAndTime,
        PluralRules pluralRules,
        NumberFormat numberFormat,
        Style style,
        DisplayContext capitalizationContext,
        BreakIterator breakIterator,
        ULocale locale) {
    this.qualitativeUnitMap = qualitativeUnitMap;
    this.patternMap = patternMap;
    this.combinedDateAndTime = combinedDateAndTime;
    this.pluralRules = pluralRules;
    this.numberFormat = numberFormat;
    this.style = style;
    if (capitalizationContext.type() != DisplayContext.Type.CAPITALIZATION) {
        throw new IllegalArgumentException(capitalizationContext.toString());
    }
    this.capitalizationContext = capitalizationContext;
    this.breakIterator = breakIterator;
    this.locale = locale;
    this.dateFormatSymbols = new DateFormatSymbols(locale);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:25,代码来源:RelativeDateTimeFormatter.java

示例7: setNumberFormat

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Set the format used for formatting or parsing. Passing null is equivalent to passing
 * {@link NumberFormat#getNumberInstance(ULocale)}.
 * @param format   the number formatter.
 * @return this, for chaining.
 * @deprecated ICU 53 see {@link MeasureFormat}.
 */
@Deprecated
public TimeUnitFormat setNumberFormat(NumberFormat format) {
    if (format == this.format) {
        return this;
    }
    if (format == null) {
        if (locale == null) {
            isReady = false;
            mf = mf.withLocale(ULocale.getDefault());
        } else {
            this.format = NumberFormat.getNumberInstance(locale);
            mf = mf.withNumberFormat(this.format);
        }
    } else {
        this.format = format;
        mf = mf.withNumberFormat(this.format);
    }
    return this;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:27,代码来源:TimeUnitFormat.java

示例8: getFunctionalEquivalent

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Returns the functionally equivalent locale.
 */
public ULocale getFunctionalEquivalent(ULocale locale, boolean[] isAvailable) {
    if (isAvailable != null && isAvailable.length > 0) {
        String localeId = ULocale.canonicalize(locale.getBaseName());
        Map<String, String> idMap = getLocaleIdToRulesIdMap(PluralType.CARDINAL);
        isAvailable[0] = idMap.containsKey(localeId);
    }

    String rulesId = getRulesIdForLocale(locale, PluralType.CARDINAL);
    if (rulesId == null || rulesId.trim().length() == 0) {
        return ULocale.ROOT; // ultimate fallback
    }

    ULocale result = getRulesIdToEquivalentULocaleMap().get(
            rulesId);
    if (result == null) {
        return ULocale.ROOT; // ultimate fallback
    }

    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:24,代码来源:PluralRulesLoader.java

示例9: getFrozenInstance

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Construct a frozen instance of DateTimePatternGenerator for a
 * given locale.  This method returns a cached frozen instance of
 * DateTimePatternGenerator, so less expensive than the regular
 * factory method.
 * @param uLocale The locale to pass.
 * @return A frozen DateTimePatternGenerator.
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
public static DateTimePatternGenerator getFrozenInstance(ULocale uLocale) {
    String localeKey = uLocale.toString();
    DateTimePatternGenerator result = DTPNG_CACHE.get(localeKey);
    if (result != null) {
        return result;
    }

    result = new DateTimePatternGenerator();
    result.initData(uLocale);

    // freeze and cache
    result.freeze();
    DTPNG_CACHE.put(localeKey, result);
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:27,代码来源:DateTimePatternGenerator.java

示例10: setAllowedLocales

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Limit characters that are acceptable in identifiers being checked to those normally used with the languages
 * associated with the specified locales. Any previously specified list of locales is replaced by the new
 * settings.
 *
 * A set of languages is determined from the locale(s), and from those a set of acceptable Unicode scripts is
 * determined. Characters from this set of scripts, along with characters from the "common" and "inherited"
 * Unicode Script categories will be permitted.
 *
 * Supplying an empty string removes all restrictions; characters from any script will be allowed.
 *
 * The {@link #CHAR_LIMIT} test is automatically enabled for this SpoofChecker when calling this function with a
 * non-empty list of locales.
 *
 * The Unicode Set of characters that will be allowed is accessible via the {@link #getAllowedChars} function.
 * setAllowedLocales() will <i>replace</i> any previously applied set of allowed characters.
 *
 * Adjustments, such as additions or deletions of certain classes of characters, can be made to the result of
 * {@link #setAllowedChars} by fetching the resulting set with {@link #getAllowedChars}, manipulating it with
 * the Unicode Set API, then resetting the spoof detectors limits with {@link #setAllowedChars}.
 *
 * @param locales
 *            A Set of ULocales, from which the language and associated script are extracted. If the locales Set
 *            is null, no restrictions will be placed on the allowed characters.
 *
 * @return self
 * @stable ICU 4.6
 */
public Builder setAllowedLocales(Set<ULocale> locales) {
    fAllowedCharsSet.clear();

    for (ULocale locale : locales) {
        // Add the script chars for this locale to the accumulating set
        // of allowed chars.
        addScriptChars(locale, fAllowedCharsSet);
    }

    // If our caller provided an empty list of locales, we disable the
    // allowed characters checking
    fAllowedLocales.clear();
    if (locales.size() == 0) {
        fAllowedCharsSet.add(0, 0x10ffff);
        fChecks &= ~CHAR_LIMIT;
        return this;
    }

    // Add all common and inherited characters to the set of allowed
    // chars.
    UnicodeSet tempSet = new UnicodeSet();
    tempSet.applyIntPropertyValue(UProperty.SCRIPT, UScript.COMMON);
    fAllowedCharsSet.addAll(tempSet);
    tempSet.applyIntPropertyValue(UProperty.SCRIPT, UScript.INHERITED);
    fAllowedCharsSet.addAll(tempSet);

    // Store the updated spoof checker state.
    fAllowedLocales.clear();
    fAllowedLocales.addAll(locales);
    fChecks |= CHAR_LIMIT;
    return this;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:61,代码来源:SpoofChecker.java

示例11: getDefaultPattern

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
private static synchronized String getDefaultPattern() {
    ULocale defaultLocale = ULocale.getDefault(Category.FORMAT);
    if (!defaultLocale.equals(cachedDefaultLocale)) {
        cachedDefaultLocale = defaultLocale;
        Calendar cal = Calendar.getInstance(cachedDefaultLocale);

        try {
            // Load the calendar data directly.
            ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(
                    ICUData.ICU_BASE_NAME, cachedDefaultLocale);
            String resourcePath = "calendar/" + cal.getType() + "/DateTimePatterns";
            ICUResourceBundle patternsRb= rb.findWithFallback(resourcePath);

            if (patternsRb == null) {
                patternsRb = rb.findWithFallback("calendar/gregorian/DateTimePatterns");
            }
            if (patternsRb == null || patternsRb.getSize() < 9) {
                cachedDefaultPattern = FALLBACKPATTERN;
            } else {
                int defaultIndex = 8;
                if (patternsRb.getSize() >= 13) {
                    defaultIndex += (SHORT + 1);
                }
                String basePattern = patternsRb.getString(defaultIndex);

                cachedDefaultPattern = SimpleFormatterImpl.formatRawPattern(
                        basePattern, 2, 2,
                        patternsRb.getString(SHORT), patternsRb.getString(SHORT + 4));
            }
        } catch (MissingResourceException e) {
            cachedDefaultPattern = FALLBACKPATTERN;
        }
    }
    return cachedDefaultPattern;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:36,代码来源:SimpleDateFormat.java

示例12: get

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Fetch data for a particular locale. Clients must not modify any part of the returned data. Portions of returned
 * data may be shared so modifying it will have unpredictable results.
 */
DataBundle get(ULocale locale) {
    DataBundle result = cache.get(locale);
    if (result == null) {
        result = load(locale);
        cache.put(locale, result);
    }
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:13,代码来源:CompactDecimalDataCache.java

示例13: get

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
public ListFormatter get(ULocale locale, String style) {
    String key = String.format("%s:%s", locale.toString(), style);
    ListFormatter result = cache.get(key);
    if (result == null) {
        result = load(locale, style);
        cache.put(key, result);
    }
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:10,代码来源:ListFormatter.java

示例14: RuleBasedNumberFormat

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
/**
 * Creates a RuleBasedNumberFormat from a predefined description.  The selector
 * code chooses among three possible predefined formats: spellout, ordinal,
 * and duration.
 * @param locale The locale for the formatter.
 * @param format A selector code specifying which kind of formatter to create for that
 * locale.  There are four legal values: SPELLOUT, which creates a formatter that
 * spells out a value in words in the desired language, ORDINAL, which attaches
 * an ordinal suffix from the desired language to the end of a number (e.g. "123rd"),
 * DURATION, which formats a duration in seconds as hours, minutes, and seconds, and
 * NUMBERING_SYSTEM, which is used to invoke rules for alternate numbering
 * systems such as the Hebrew numbering system, or for Roman numerals, etc..
 * @stable ICU 3.2
 */
public RuleBasedNumberFormat(ULocale locale, int format) {
    this.locale = locale;

    ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.
        getBundleInstance(ICUData.ICU_RBNF_BASE_NAME, locale);

    // TODO: determine correct actual/valid locale.  Note ambiguity
    // here -- do actual/valid refer to pattern, DecimalFormatSymbols,
    // or Collator?
    ULocale uloc = bundle.getULocale();
    setLocale(uloc, uloc);

    StringBuilder description = new StringBuilder();
    String[][] localizations = null;

    try {
        ICUResourceBundle rules = bundle.getWithFallback("RBNFRules/"+rulenames[format-1]);
        UResourceBundleIterator it = rules.getIterator();
        while (it.hasNext()) {
           description.append(it.nextString());
        }
    }
    catch (MissingResourceException e1) {
    }

    // We use findTopLevel() instead of get() because
    // it's faster when we know that it's usually going to fail.
    UResourceBundle locNamesBundle = bundle.findTopLevel(locnames[format - 1]);
    if (locNamesBundle != null) {
        localizations = new String[locNamesBundle.getSize()][];
        for (int i = 0; i < localizations.length; ++i) {
            localizations[i] = locNamesBundle.get(i).getStringArray();
        }
    }
    // else there are no localized names. It's not that important.

    init(description.toString(), localizations);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:53,代码来源:RuleBasedNumberFormat.java

示例15: RuleBasedCollator

import com.ibm.icu.util.ULocale; //导入依赖的package包/类
RuleBasedCollator(CollationTailoring t, ULocale vl) {
    data = t.data;
    settings = t.settings.clone();
    tailoring = t;
    validLocale = vl;
    actualLocaleIsSameAsValid = false;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:8,代码来源:RuleBasedCollator.java


注:本文中的com.ibm.icu.util.ULocale类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。