本文整理汇总了Java中com.ibm.icu.util.Calendar.getKeywordValuesForLocale方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.getKeywordValuesForLocale方法的具体用法?Java Calendar.getKeywordValuesForLocale怎么用?Java Calendar.getKeywordValuesForLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.Calendar
的用法示例。
在下文中一共展示了Calendar.getKeywordValuesForLocale方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCalendarTypeToUse
import com.ibm.icu.util.Calendar; //导入方法依赖的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;
}
示例2: setup
import com.ibm.icu.util.Calendar; //导入方法依赖的package包/类
private void setup(ULocale locale) {
int DEFAULT_HASH_SIZE = 19;
fIntervalPatterns = new HashMap<String, Map<String, PatternInfo>>(DEFAULT_HASH_SIZE);
// initialize to guard if there is no interval date format defined in
// resource files
fFallbackIntervalPattern = "{0} \u2013 {1}";
try {
// Get the correct calendar type
String calendarTypeToUse = locale.getKeywordValue("calendar");
if ( calendarTypeToUse == null ) {
String[] preferredCalendarTypes =
Calendar.getKeywordValuesForLocale("calendar", locale, true);
calendarTypeToUse = preferredCalendarTypes[0]; // the most preferred calendar
}
if ( calendarTypeToUse == null ) {
calendarTypeToUse = "gregorian"; // fallback
}
// Instantiate the sink to process the data and the resource bundle
DateIntervalSink sink = new DateIntervalSink(this);
ICUResourceBundle resource =
(ICUResourceBundle)UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
// Get the fallback pattern
String fallbackPattern = resource.getStringWithFallback(CALENDAR_KEY + "/" + calendarTypeToUse
+ "/" + INTERVAL_FORMATS_KEY + "/" + FALLBACK_STRING);
setFallbackIntervalPattern(fallbackPattern);
// Already loaded calendar types
Set<String> loadedCalendarTypes = new HashSet<String>();
while (calendarTypeToUse != null) {
// Throw an exception when a loop is detected
if (loadedCalendarTypes.contains(calendarTypeToUse)) {
throw new ICUException("Loop in calendar type fallback: " + calendarTypeToUse);
}
// Register the calendar type to avoid loops
loadedCalendarTypes.add(calendarTypeToUse);
// Get all resources for this calendar type
String pathToIntervalFormats = CALENDAR_KEY + "/" + calendarTypeToUse;
resource.getAllItemsWithFallback(pathToIntervalFormats, sink);
// Get next calendar type to load if there was an alias pointing at it
calendarTypeToUse = sink.getAndResetNextCalendarType();
}
} catch ( MissingResourceException e) {
// Will fallback to {data0} - {date1}
}
}