Internationalization

locale()

LC = locale()
LC = locale(Locale locale) or (String localeName)
LC = locale(String language , String country {, String variant })

locale() creates a pnuts.util.LocaleAdapter object.

LC = locale()
LC_IT = locale("ITALY")
LC_JA = locale(Locale::JA)
LC_CF = locale("fr", "CA")

To get a Locale object from a LocaleAdatper object, call getLocale() of a LocaleAdatper object.

LC = locale()
LC . getLocale()

Accessing Resource Bundles

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

Gets the value of key from a resource bundle (bundleName) based on a LocaleAdapter (LC). When one or more parameters are specified, it formats a message through MessageFormat::format() method.

LC = locale()

LC.pnuts("autoload.failed")

   ==> ResourceBundle::getBundle("pnuts", LC).getObject("autoload.failed")

LC.pnuts("autoload.failed", "foo.pnut")

   ==> MessageFormat::format(
           ResourceBundle::getBundle("pnuts", LC).getObject("autoload.failed"),
          ["foo.pnut"])

Locale-sensitive Formats

LC . number (Number number {, int fmin }) or
(Number number {, int imin , int imax , int fmin , int fmax } )
LC . currency (Number number {, int fmin }) or
(Number number {, int imin , int imax , int fmin , int fmax } )
LC . percent (Number number {, int fmin }) or
(Number number {, int imin , int imax , int fmin , int fmax } )
number
Gets a formatted number
currency
Gets a formatted currency
percent
Gets a formatted percent number

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
LC = locale()
fmt1 = LC.number(12345)
fmt2 = LC.currency(12345)
fmt3 = LC.percent(0.12, 3)
LC . date ( { Date aDate } {, String style } )
LC . time ( { Date aDate } {, String style } )
LC . datetime ( { Date aDate } {, String style {, String style }} )
date
Gets a formatted date
time
Gets a formatted time
datetime
Gets a formatted date and time

If aDate is omitted "new Date()" is passed implicitly.

If style is omitted DateFormat::DEFAULT is passed implicitly. style can be one of the followings:

LC = locale()
fmt4 = LC.date(date(), "full")
fmt5 = LC.time(date(), "short")

Back