Package org.appng.api.support
Class I18n
- java.lang.Object
-
- org.appng.api.support.I18n
-
public class I18n extends Object
Utility class used for formattingString
s,Date
s andNumber
s. Additionally, a message can be retrieved by delegating toRequestSupport.getMessage(String, Object...)
.
Since an instance ofI18n
is being added to eachExpressionEvaluator
returned byRequest.getExpressionEvaluator()
, you can easily use the methods provided byI18n
in your expressions.
Examples
Consider aResourceBundle
containing the following entries:dateFormat = yyyy-MM-dd today = Today: {0}
Reading the format for aFieldDef
usingmessage(String, Object...)
:<field name="validFrom" type="date" format="${i18n.message('dateFormat')}">
leads to<field name="validFrom" type="date" format="yyyy-MM-dd">
Setting the value for aLabel
usingmessage(String, Object...)
andformatDate(Date, String)
<label>${i18n.message('today', i18n.formatDate(current.date, i18n.message('dateFormat')))}</label>
leads to (assuming current.today returns aDate
):<label>Today: 2013-03-08</label>
- Author:
- Matthias Müller
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(String format, Object... args)
Formats the givenString
with the given arguments.String
formatDate(Date date, String format)
Formats the givenDate
using the givenformat
.String
formatNumber(Number number, String format)
Formats the givenNumber
using the givenformat
.String
message(String key)
Returns an internationalized message by delegating toRequestSupport.getMessage(String, Object...)
.String
message(String key, Object... args)
Returns an internationalized message by delegating toRequestSupport.getMessage(String, Object...)
.
-
-
-
Method Detail
-
message
public String message(String key)
Returns an internationalized message by delegating toRequestSupport.getMessage(String, Object...)
. Applies theLocale
provided byRequest.getLocale()
.- Parameters:
key
- the message key- Returns:
- the message
- See Also:
RequestSupport.getMessage(String, Object...)
-
message
public String message(String key, Object... args)
Returns an internationalized message by delegating toRequestSupport.getMessage(String, Object...)
. Applies theLocale
provided byRequest.getLocale()
.- Parameters:
key
- the message keyargs
- the message arguments- Returns:
- the message
- See Also:
RequestSupport.getMessage(String, Object...)
-
format
public String format(String format, Object... args)
Formats the givenString
with the given arguments. Delegates toString.format(java.util.Locale, String, Object...)
using theLocale
provided byRequest.getLocale()
.- Parameters:
format
- theString
to formatargs
- the arguments passed to- Returns:
- a formatted String
- See Also:
String.format(Locale, String, Object...)
-
formatDate
public String formatDate(Date date, String format)
Formats the givenDate
using the givenformat
. Internally, aSimpleDateFormat
is being used. Applies theLocale
provided byRequest.getLocale()
.- Parameters:
date
- theDate
to formatformat
- the the format- Returns:
- the formatted
Number
- See Also:
SimpleDateFormat(String, Locale)
,DateFormat.format(Date)
-
formatNumber
public String formatNumber(Number number, String format)
Formats the givenNumber
using the givenformat
. Internally, aNumberFormat
is being used, which applies theLocale
provided byRequest.getLocale()
.- Parameters:
number
- theNumber
to formatformat
- the the format- Returns:
- the formatted
Number
- See Also:
NumberFormat.getNumberInstance(Locale)
-
-