getLocale() returns the Locale object of the current context.
When locale_string is specified, it returns the java.util.Locale object. locale_string should be a '_' separated string that contains lanuage, country and variant in that order.
When locale is specified, just returns it.
loc = getLocale()
println("Language: ", loc.language)
println("Country: ", loc.country)
setLocale() changes the Locale of the current context.
When locale_string is specified, it should be a '_' separated string that contains lanuage, country and variant in that order.
getLocalizedResource() gets a localized resource using the specified resourceName and the locale information. The candidates of the localized resource are made in the following rules.
For example, imagin that your system's default locale is fr_FR and you want to localize a resource called "hello.txt".
getLocalizedResource("hello.txt")
If you have "hello_fr_FR.txt", getLocalizedResource() returns the file as a URL object.
If you have "hello_fr.txt" but not "hello_fr_FR.txt", getLocalizedResource() returns "hello_fr.txt" as a URL object.
If neither "hello_fr_FR.txt" nor "hello_fr.txt" are found, getLocalizedResource() returns "hello.txt" as a URL object
Gets the value of key from a resource bundle (bundleName) based on the Locale of the current context. When one or more parameters are specified, it formats a message through MessageFormat::format() method.
formatMessage("pnuts/lang/pnuts", "autoload.failed")
==> ResourceBundle::getBundle("pnuts/lang/pnuts", Locale::getDefault()).getObject("autoload.failed")
formatMessage("pnuts/lang/pnuts", "autoload.failed", "foo.pnut")
==> MessageFormat::format(
ResourceBundle::getBundle("pnuts/lang/pnuts", LC).getObject("autoload.failed"),
["foo.pnut"])
getResourceBundle() return a handle to access the internationalized resource bundle.
b = getResourceBundle("pnuts.jar", "pnuts/lang/pnuts")
println(b.formatMessage("not.defined", "foo"))
Gets a formatted number, currency, and percent number respectively.
imin, imax, fmin, fmax sets the number of digits for integer part or fraction part. When the value is -1 the default value is applied.
- imin
- the minimum integer digits for the NumberFormat
- imax
- the maximum integer digits for the NumberFormat
- fmin
- the minimum fraction digits for the NumberFormat
- fmax
- the maximum fraction digits for the NumberFormat
fmt1 = formatNumber(12345) fmt2 = formatCurrency(12345) fmt3 = formatPercent(0.12, 3)The format string given to formatNumber(number, format) should be a java.text.DecimalFormat patterns.
formatNumber(123.456, "0000")
Gets a formatted date, time, and both respectively.
If style is omitted "DEFAULT" is passed implicitly. style can be one of the followings (case-insensitive):
If two parameters are given to formatDateTime(), the date value is formated using pattern string, which is defined in java.text.SimpleDateFormat.
formatDate(date(), "full") formatTime(date(), "short") formatDateTime(date(), "yyyy/MM/dd HH:mm:ss z")