Internationalization

Locale information

getLocale() or
(String locale_string) or
(Locale locale)

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(String locale_string ) or
(Locale locale )

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.

Localized Resource

getLocalizedResource(String rsrcName { , String language {, String country } })

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.

  1. basename + "_" + language + "_" + country + "." + extension
  2. basename + "_" + language + "." + extension
  3. basename + "." + extension

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

Internationalized message

formatMessage(String bundleName, String key {, parameters ...} )

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"])
bundle = getResourceBundle(URL url, String bundleName {, ( Locale | String } locale } )
bundle.formatMessage(String key { , parameters ...} )

getResourceBundle() return a handle to access the internationalized resource bundle.

b = getResourceBundle("pnuts.jar", "pnuts/lang/pnuts")
println(b.formatMessage("not.defined", "foo"))

Locale-sensitive Number Formats

formatNumber (Number number {, int fmin }) or
(Number number, String format ) or
(Number number {, int imin , int imax , int fmin , int fmax } )
formatCurrency (Number number {, int fmin }) or
(Number number {, int imin , int imax , int fmin , int fmax } )
formatPercent (Number number {, int fmin }) or
(Number number {, int imin , int imax , int fmin , int fmax } )

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")
formatDate ( Date aDate {, String style } )
formatTime ( Date aDate {, String style } )
formatDateTime ( Date aDate
{, ( String style , String style | String pattern ) } )

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")