public class BaseLocalizer extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
BaseLocalizer.LocalOrGmt
Simple enum + convenience methods for asking Date questions in Local or GMT.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
CHINESE_LANGUAGE |
protected NumberFormat |
currencyFormat |
protected DateFormat |
dateTimeFormat |
static Date |
EARLIEST |
static String |
ENGLISH_LANGUAGE |
static BaseLocalizer.LocalOrGmt |
GMT |
static TimeZone |
GMT_TZ |
protected DateFormat |
gmtDateFormat
these elements aren't initialized on construction.
|
protected DateFormat |
gmtTimeFormat |
protected DateFormat |
inputDateTimeFormat |
protected DateFormat |
inputGmtDateFormat |
protected DateFormat |
inputLocalDateFormat |
static String |
JAPANESE_LANGUAGE |
static String |
KOREAN_LANGUAGE |
protected SharedLabelSet |
labelSet |
static Date |
LATEST |
static BaseLocalizer.LocalOrGmt |
LOCAL |
protected DateFormat |
localDateFormat |
protected DateFormat |
localLongDateFormat |
protected DateFormat |
localTimeFormat |
protected DateFormat |
longDateTimeFormat |
protected LruCache<String,MessageFormat> |
messageFormatCache |
protected NumberFormat |
numberFormat |
static Date |
OLD_EARLIEST |
static Date |
OLD_LATEST |
| Constructor and Description |
|---|
BaseLocalizer(Locale locale,
Locale currencyLocale,
TimeZone timeZone,
HumanLanguage language,
SharedLabelSet labelSet)
This constructor is used to create a BaseLocalizer
|
| Modifier and Type | Method and Description |
|---|---|
static Date |
doParseDate(String input,
DateFormat df)
Parse the given input string using the given format, and make sure the entire string
is used up during the parsing and garbage text at the end is not allowed.
|
static Number |
doParseNumber(String input,
NumberFormat nf)
Parse the given input string using the given format, and make sure the entire string
is used up during the parsing and garbage text at the end is not allowed.
|
static Date |
doParseTime(String input,
DateFormat tf)
parse a time (or date really), but you should use doParseDate for dates as it does some extra stuff
|
String |
formatDate(Date date,
BaseLocalizer.LocalOrGmt tz)
Formats a date-only Date.
|
String |
formatDateTime(Date date)
Formats a date-time Date.
|
Calendar |
getCalendar(BaseLocalizer.LocalOrGmt tz) |
Calendar |
getCalendar(Locale l) |
Calendar |
getCalendar(TimeZone tz) |
NumberFormat |
getCurrencyFormat()
Gets a NumberFormat for currency, using the default settings for the Locale.
|
NumberFormat |
getCurrencyFormat(int scale)
Gets a NumberFormat for currency, using the given precision and scale settings.
|
protected NumberFormat |
getCurrencyFormat(Locale currLocale) |
protected NumberFormat |
getCurrencyFormat(Locale currLocale,
int scale) |
Locale |
getCurrencyLocale() |
DateFormat |
getDateFormat(BaseLocalizer.LocalOrGmt tz)
Get date-only DateFormat for output.
|
DateFormat |
getDateTimeFormat()
Get date-time DateFormat for output.
|
DateFormat |
getGmtTimeFormat()
Get time-only DateFormat for output.
|
DateFormat |
getInputDateFormat(BaseLocalizer.LocalOrGmt tz)
Get date-only DateFormat for input.
|
DateFormat |
getInputDateTimeFormat()
Get date-time DateFormat for input.
|
String |
getLabel(String section,
String name) |
String |
getLabel(String section,
String key,
Object... args)
Convenience function that calls
java.text.MessageFormat.format() on the label
using the Object[] supplied. |
SharedLabelSet |
getLabelSet() |
String |
getLabelThrow(String section,
String name) |
Locale |
getLanguage() |
List<String> |
getList(String section,
String baseName) |
Locale |
getLocale()
Retrieve the locale associated with this localizer.
|
static DateFormat |
getLocaleDateFormat(Locale locale,
TimeZone tz)
Static method to get date-only DateFormat for output.
|
static DateFormat |
getLocaleDateTimeFormat(Locale locale,
TimeZone tz)
Static method to get date-time DateFormat for output.
|
static DateFormat |
getLocaleInputDateFormat(Locale locale,
TimeZone tz)
Static method to get date-only DateFormat for input.
|
static DateFormat |
getLocaleInputDateTimeFormat(Locale locale,
TimeZone tz)
Static method to get date-time DateFormat for input.
|
static DateFormat |
getLocaleTimeFormat(Locale locale,
TimeZone tz)
This form of getLocalDateTimeFormat is used to render times in a specific locale.
|
DateFormat |
getLongDateFormat()
Get date-only DateFormat for output.
|
DateFormat |
getLongDateTimeFormat()
Get date-time DateFormat for output.
|
MessageFormat |
getMessageFormat(String pattern) |
NumberFormat |
getNumberFormat()
Gets a NumberFormat, using the default settings for the Locale.
|
NumberFormat |
getNumberFormat(int scale,
boolean scaleSpecified)
Gets a NumberFormat, using the given precision and scale settings.
|
NumberFormat |
getNumberFormat(int precision,
int scale)
Return the number format for the locale with the given precision and scale
|
NumberFormat |
getPercentFormat()
Gets a NumberFormat for percentage, using the default settings for the Locale.
|
Map<String,Object> |
getSection(String section)
Returns a map containing the contents of an entire label section, or null if the section does not exist.
|
DateFormat |
getTimeFormat()
Get time-only DateFormat for output.
|
TimeZone |
getTimeZone() |
HumanLanguage |
getUserLanguage() |
static boolean |
isLanguageEnglish(Locale locale) |
static boolean |
isLanguageJapanese(Locale locale) |
boolean |
labelExists(String section,
String name) |
Number |
parseCurrency(String s)
Parse the string as currency.
|
Date |
parseDate(String input,
BaseLocalizer.LocalOrGmt tz)
Parses a date-only input string.
|
Date |
parseDateTime(String input)
Parses a date-time input string.
|
Number |
parseNumber(String s)
Parse the string as a number.
|
Number |
parsePercent(String s)
Parse the string as percentage.
|
public static final BaseLocalizer.LocalOrGmt LOCAL
public static final BaseLocalizer.LocalOrGmt GMT
public static final TimeZone GMT_TZ
public static final Date EARLIEST
public static final Date LATEST
public static final Date OLD_EARLIEST
public static final Date OLD_LATEST
protected SharedLabelSet labelSet
protected DateFormat gmtDateFormat
protected DateFormat localDateFormat
protected DateFormat localLongDateFormat
protected DateFormat gmtTimeFormat
protected DateFormat localTimeFormat
protected DateFormat dateTimeFormat
protected DateFormat longDateTimeFormat
protected DateFormat inputGmtDateFormat
protected DateFormat inputLocalDateFormat
protected DateFormat inputDateTimeFormat
protected NumberFormat numberFormat
protected NumberFormat currencyFormat
protected final LruCache<String,MessageFormat> messageFormatCache
public static final String ENGLISH_LANGUAGE
public static final String KOREAN_LANGUAGE
public static final String JAPANESE_LANGUAGE
public static final String CHINESE_LANGUAGE
public BaseLocalizer(Locale locale, Locale currencyLocale, TimeZone timeZone, HumanLanguage language, SharedLabelSet labelSet)
locale - is the user's locale datacurrencyLocale - is org's currency locale ,public SharedLabelSet getLabelSet()
public Calendar getCalendar(BaseLocalizer.LocalOrGmt tz)
public Date parseDate(String input, BaseLocalizer.LocalOrGmt tz) throws ParseException
ParseExceptionpublic Date parseDateTime(String input) throws ParseException
ParseExceptionpublic DateFormat getInputDateFormat(BaseLocalizer.LocalOrGmt tz)
public static DateFormat getLocaleInputDateFormat(Locale locale, TimeZone tz)
public static boolean isLanguageEnglish(Locale locale)
public static boolean isLanguageJapanese(Locale locale)
public DateFormat getInputDateTimeFormat()
public static DateFormat getLocaleInputDateTimeFormat(Locale locale, TimeZone tz)
public static Date doParseDate(String input, DateFormat df) throws ParseException
ParseExceptionpublic static Date doParseTime(String input, DateFormat tf) throws ParseException
ParseExceptionpublic String formatDate(Date date, BaseLocalizer.LocalOrGmt tz)
public DateFormat getDateFormat(BaseLocalizer.LocalOrGmt tz)
public static DateFormat getLocaleDateFormat(Locale locale, TimeZone tz)
public DateFormat getLongDateFormat()
public DateFormat getTimeFormat()
public DateFormat getGmtTimeFormat()
public DateFormat getDateTimeFormat()
public static DateFormat getLocaleDateTimeFormat(Locale locale, TimeZone tz)
public static DateFormat getLocaleTimeFormat(Locale locale, TimeZone tz)
public DateFormat getLongDateTimeFormat()
public Number parseNumber(String s) throws ParseException
s - the string to be parsedParseException - if the string cannot be parsedpublic Number parsePercent(String s) throws ParseException
s - the string to be parsedParseException - if the string cannot be parsedpublic Number parseCurrency(String s) throws ParseException
s - the string to be parsedParseException - if the string cannot be parsedpublic NumberFormat getNumberFormat()
public NumberFormat getNumberFormat(int precision, int scale)
precision - the precision of the number to be displayedscale - the scale to be displayedpublic NumberFormat getNumberFormat(int scale, boolean scaleSpecified)
scale - number of digits to the right of the decimal that will be shownpublic NumberFormat getCurrencyFormat()
protected NumberFormat getCurrencyFormat(Locale currLocale)
public NumberFormat getCurrencyFormat(int scale)
scale - number of digits to the right of the decimal that will be shownprotected NumberFormat getCurrencyFormat(Locale currLocale, int scale)
public NumberFormat getPercentFormat()
public static Number doParseNumber(String input, NumberFormat nf) throws ParseException
ParseExceptionpublic MessageFormat getMessageFormat(String pattern)
public Map<String,Object> getSection(String section)
section - The section to retrievepublic String getLabel(String section, String key, Object... args)
java.text.MessageFormat.format() on the label
using the Object[] supplied.section - same as getLabel(section, key)key - same as getLabel(section, key)args - for java.text.MessageFormat.format()public Locale getLocale()
public TimeZone getTimeZone()
public Locale getLanguage()
public HumanLanguage getUserLanguage()
public Locale getCurrencyLocale()
Copyright (c) 2016-2017, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE.txt file in the repository.