public final class CalendarText extends Object
Source for localized calendrical informations on enum basis like month or weekday names.
This class is a facade for an underlying implementation of
TextProvider which will be loaded as SPI-interface
by help of a ServiceLoader. If no such SPI-interface can be
found then this class will resort to the sources of JDK (usually
as wrapper around java.text.DateFormatSymbols).
Furthermore, an instance of CalendarText can also access
the UTF-8 text resources in the folder "calendar" relative to
the class path which are not based on JDK-defaults. In this case the
presence of the i18n-module is required. In all ISO-systems the
"iso8601_{locale}.properties"-files will override the
JDK-defaults unless it is the ROOT-locale. Example:
If you wish to use the name "Sonnabend" instead of the standard word "Samstag" in german locale (english: Saturday) then you can copy the existing file "calendar/iso8601_de.properties" from the content of "time4j-i18n-v{version}.jar"-file into a new directory with the same path. Then you can insert these lines extra (all seven entries must be inserted, not just the sixth line):
DAY_OF_WEEK(WIDE)_1=Montag DAY_OF_WEEK(WIDE)_2=Dienstag DAY_OF_WEEK(WIDE)_3=Mittwoch DAY_OF_WEEK(WIDE)_4=Donnerstag DAY_OF_WEEK(WIDE)_5=Freitag DAY_OF_WEEK(WIDE)_6=Sonnabend DAY_OF_WEEK(WIDE)_7=Sonntag
The general format of these lines is:
{element-name}({text-width}[|STANDALONE])_{one-based-integer}={text}
STANDALONE is optional. As element name in the context of ISO-8601 following names are supported:
| Modifier and Type | Field and Description |
|---|---|
static String |
ISO_CALENDAR_TYPE
Default calendar type for all ISO systems.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
clearCache()
Clears the internal cache.
|
TextAccessor |
getEras(TextWidth textWidth)
Yields an
Accessor for all era names. |
static FormatPatternProvider |
getFormatPatterns()
Deprecated.
Use one of methods
patternForXYZ instead |
static String |
getGMTPrefix(Locale locale)
Deprecated.
Use
ZonalOffset.getStdFormatPattern(Locale) instead |
static CalendarText |
getInstance(Chronology<?> chronology,
Locale locale)
Returns an instance of
CalendarText for given chronology
and language. |
static CalendarText |
getInstance(String calendarType,
Locale locale)
Returns an instance of
CalendarText for given calendar type
and language. |
static CalendarText |
getIsoInstance(Locale locale)
Returns an instance of
CalendarText for ISO calendar systems and given language. |
TextAccessor |
getLeapMonths(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all months if a leap month
is relevant. |
TextAccessor |
getMeridiems(TextWidth textWidth)
Deprecated.
Use
getMeridiems(textWidth, OutputContext.FORMAT) |
TextAccessor |
getMeridiems(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all am/pm-names. |
TextAccessor |
getQuarters(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all quarter years. |
TextAccessor |
getStdMonths(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all standard months. |
Map<String,String> |
getTextForms()
Yields all text forms in raw format.
|
<V extends Enum<V>> |
getTextForms(ChronoElement<V> element,
String... variants)
Yields an
Accessor for all text forms of given
chronological element. |
<V extends Enum<V>> |
getTextForms(String name,
Class<V> type,
String... variants)
|
static String |
getTimestampPattern(DisplayMode dateMode,
DisplayMode timeMode,
Locale locale)
Deprecated.
Use
patternForTimestamp instead |
TextAccessor |
getWeekdays(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all weekday names. |
static boolean |
isRTL(Locale locale)
Determines if given language is written in right-to-left direction.
|
static String |
patternForDate(DisplayMode mode,
Locale locale)
Returns the localized date pattern suitable for formatting of objects
of type
PlainDate. |
static String |
patternForInterval(Locale locale)
Returns the localized interval pattern.
|
static String |
patternForMoment(DisplayMode dateMode,
DisplayMode timeMode,
Locale locale)
Returns the localized date-time pattern suitable for formatting of objects
of type
Moment. |
static String |
patternForTime(DisplayMode mode,
Locale locale)
Returns the localized time pattern suitable for formatting of objects
of type
PlainTime. |
static String |
patternForTimestamp(DisplayMode dateMode,
DisplayMode timeMode,
Locale locale)
Yields a format pattern without any timezone symbols for plain timestamps.
|
String |
toString()
Yields the name of the internal
TextProvider in conjunction with the configuring locale. |
public static final String ISO_CALENDAR_TYPE
Default calendar type for all ISO systems.
public static CalendarText getIsoInstance(Locale locale)
Returns an instance of CalendarText for ISO calendar systems and given language.
locale - languageCalendarText object maybe cachedpublic static CalendarText getInstance(Chronology<?> chronology, Locale locale)
Returns an instance of CalendarText for given chronology
and language.
chronology - chronology (with calendar system)locale - languageCalendarText object maybe cachedpublic static CalendarText getInstance(String calendarType, Locale locale)
Returns an instance of CalendarText for given calendar type
and language.
calendarType - name of calendar systemlocale - languageCalendarText object maybe cachedCalendarTypepublic TextAccessor getStdMonths(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all standard months.
The underlying list is sorted such that it will obey to the typical order of months in given calendar system. ISO-systems define January as first month and at whole 12 months. Other calendar systems can also define for example 13 months. The order of element value enums must be in agreement with the order of the text forms contained here.
The default implementation handles SHORT as synonym for ABBREVIATED in the context of ISO-8601.
textWidth - text width of displayed month nameoutputContext - output context (stand-alone?)Monthpublic TextAccessor getLeapMonths(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all months if a leap month
is relevant.
Note: Leap months are defined in some calendar systems like the hebrew calendar ("Adar II") else there is no difference between standard and leap months escpecially not in ISO-8601.
textWidth - text width of displayed month nameoutputContext - output context (stand-alone?)Month,
getStdMonths(TextWidth, OutputContext)public TextAccessor getQuarters(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all quarter years.
The underlying list of text forms is sorted in the same order
as the enum Quarter and uses its ordinal index as list
index. ISO systems define the range January-March as first quarter
etc. and at whole four quarters per calendar year.
The default implementation handles SHORT as synonym for ABBREVIATED in the context of ISO-8601.
textWidth - text width of displayed quarter nameoutputContext - output context (stand-alone?)Quarterpublic TextAccessor getWeekdays(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all weekday names.
The underlying list of text forms is sorted such that the typical order of weekdays is used in given calendar system. ISO systems define Monday as first day of week and at whole 7 weekdays. This order is also valid for US in the context of this class although in US Sunday is considered as start of a week. The order element value enums must be in agreement with the order of text forms contained here.
textWidth - text width of displayed weekday nameoutputContext - output context (stand-alone?)Weekdaypublic TextAccessor getEras(TextWidth textWidth)
Yields an Accessor for all era names.
The underlying list of text forms is sorted such that the
typical order of eras is used in given calendar system. ISO systems
define era names based on their historical extensions (eras of
gregorian/historic calendar) because they themselves have no internal
concept of eras. The order of element value enums must be in agreement
with the text forms contained here. If an era is not defined on enum
basis then the format API will not evaluate this class but the
CalendarSystem to get the right text forms.
textWidth - text width of displayed era nameCalendarSystem.getEras()@Deprecated public TextAccessor getMeridiems(TextWidth textWidth)
getMeridiems(textWidth, OutputContext.FORMAT)Yields an Accessor for all am/pm-names.
The underlying list of text forms is sorted in AM-PM-order. The order of element value enums must be the same.
textWidth - text width of displayed AM/PM namegetMeridiems(TextWidth, OutputContext)public TextAccessor getMeridiems(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all am/pm-names.
The underlying list of text forms is sorted in AM-PM-order. The order of element value enums must be the same.
textWidth - text width of displayed AM/PM nameoutputContext - output context (stand-alone?)Meridiempublic Map<String,String> getTextForms()
Yields all text forms in raw format.
public <V extends Enum<V>> TextAccessor getTextForms(ChronoElement<V> element, String... variants)
Yields an Accessor for all text forms of given
chronological element.
Text forms might exist in different variations. In case of
enum-based variants the name of the enum (example "WIDE" in
the variant TextWidth) is to be used, in case of boolean-based
variants the literals "true" and "false" are to be
used.
While the methods getStdMonths(), getWeekdays()
etc. are mainly based on JDK-defaults, this method is escpecially
designed for querying chronological texts which are not contained in
JDK. Text forms will be stored internally in the resource folder
"calendar" relative to class path in properties-files using
UTF-8 encoding. The basic name of these resources is the calendar type.
The combination of element name and optionally variants in the form
"(variant1|variant2|...|variantN)" and the underscore and
finally a numerical suffix with base 1 (for era elements base 0) serves
as resource text key. If there is no entry for given key in the resources
then this method will simply yield the name of enum value associated
with given element value.
As example, the search for abbreviated historic era HistoricEra.AD of alternative form
looks up keys in this order (using E if there is an entry "useShortKeys=true"):
V - generic type of element values based on enumselement - element text forms are searched forvariants - text form variants (optional)MissingResourceException - if for given calendar type there are no text resource filespublic <V extends Enum<V>> TextAccessor getTextForms(String name, Class<V> type, String... variants)
V - generic type of element values based on enumsname - name of text entries in resource filetype - type of enum valuesvariants - text form variants (optional)MissingResourceException - if for given calendar type there are no text resource files@Deprecated public static String getGMTPrefix(Locale locale)
ZonalOffset.getStdFormatPattern(Locale) insteadYields the localized GMT-prefix which is used in the localized GMT format of CLDR.
locale - language and country configuration@Deprecated public static FormatPatternProvider getFormatPatterns()
patternForXYZ insteadYields the best available format patterns.
@Deprecated public static String getTimestampPattern(DisplayMode dateMode, DisplayMode timeMode, Locale locale)
patternForTimestamp insteadYields a format pattern without any timezone symbols for plain timestamps.
dateMode - display mode of date parttimeMode - display mode of time partlocale - language and country settingpublic static String patternForDate(DisplayMode mode, Locale locale)
Returns the localized date pattern suitable for formatting of objects
of type PlainDate.
mode - display modelocale - language and country settingPlainDatepublic static String patternForTime(DisplayMode mode, Locale locale)
Returns the localized time pattern suitable for formatting of objects
of type PlainTime.
mode - display modelocale - language and country settingPlainTimepublic static String patternForTimestamp(DisplayMode dateMode, DisplayMode timeMode, Locale locale)
Yields a format pattern without any timezone symbols for plain timestamps.
dateMode - display mode of date parttimeMode - display mode of time partlocale - language and country settingPlainTimestamppublic static String patternForMoment(DisplayMode dateMode, DisplayMode timeMode, Locale locale)
Returns the localized date-time pattern suitable for formatting of objects
of type Moment.
dateMode - display mode of date parttimeMode - display mode of time partlocale - language and country settingMomentpublic static String patternForInterval(Locale locale)
Returns the localized interval pattern.
Expressions of the form "{0}" will be interpreted as the start boundary format and expressions of the form "{1}" will be interpreted as the end boundary format. All other chars of the pattern will be treated as literals.
locale - language and country settingpublic String toString()
Yields the name of the internal TextProvider in conjunction with the configuring locale.
public static void clearCache()
Clears the internal cache.
This method should be called if the internal text resources have
changed and must be reloaded with a suitable ClassLoader.
public static boolean isRTL(Locale locale)
Determines if given language is written in right-to-left direction.
locale - language to be checkedtrue if right-to-left else falseCopyright © 2014–2017. All rights reserved.