Jala 1.3

## Class jala.I18n

    Object
       |
       +--jala.I18n

class jala.I18n

This class provides various functions and macros for internationalization of Helma applications.
Defined in I18n.js

Constructor Summary
`jala.I18n ()` Constructs a new instance of jala.I18n

Method Summary
`String` | `formatMessage(<String> message, <Array> values)` Converts the message passed as argument into an instance of java.text.MessageFormat, and formats it using the replacement values passed.
`Object` | `getCatalog(locale)` Helper method to get the message catalog corresponding to the actual locale.
`java.util.Locale` | `getLocale(localeId)` Returns the locale for the given id, which is expected to follow the form `language[_COUNTRY][_variant]`, where `language` is a valid ISO Language Code (eg.
`Function` | `getLocaleGetter()` Get the method for retrieving the locale.
`Object` | `getMessages()` Get the message object.
`String` | `gettext(<String> key )` Returns a localized message for the message key passed as argument.
`String` | `markgettext(<String> key)` A simple proxy method which is used to mark a message string for the i18n parser as to be translated.
`String` | `message_macro(param)` Returns a translated message.
`String` | `ngettext(<String> singularKey, <String> pluralKey, <Number> amount )` Returns a localized message for the message key passed as argument.
`void` | `setHandler(<Object> handler)` Set (overwrite) the default handler containing the messages (ie.
`void` | `setLocaleGetter(<Function> func)` Set the method for retrieving the locale.
`void` | `setMessages(<Object> msgObject)` Overwrite the default object containing the messages (ie.
`String` | `translate(singularKey, pluralKey, <Number> amount)` Tries to "translate" the given message key into a localized message.

Constructor Detail

### jala.I18n

    jala.I18n()

Constructs a new instance of jala.I18n

Method Detail

### formatMessage

    String formatMessage(<String> message, <Array> values)

Converts the message passed as argument into an instance of java.text.MessageFormat, and formats it using the replacement values passed.

Parameters:

`message` - The message to format

`values` - An optional array containing replacement values

Returns:

The formatted message or, if the formatting fails, the message passed as argument.

See:

- http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html

### getCatalog

    Object getCatalog(locale)

Helper method to get the message catalog corresponding to the actual locale.

Returns:

The message catalog.

### getLocale

    java.util.Locale getLocale(localeId)

Returns the locale for the given id, which is expected to follow the form `language[_COUNTRY][_variant]`, where `language` is a valid ISO Language Code (eg. "de"), `COUNTRY` a valid ISO Country Code (eg. "AT"), and variant an identifier for the variant to use.

Returns:

The locale for the given id

### getLocaleGetter

    Function getLocaleGetter()

Get the method for retrieving the locale.

Returns:

The getter method

### getMessages

    Object getMessages()

Get the message object.

Returns:

The object containing the messages

### gettext

    String gettext(<String> key )

Returns a localized message for the message key passed as argument. If no localization is found, the message key is returned. Any additional arguments passed to this function will be used as replacement values during message rendering. To reference these values the message can contain placeholders following "{number}" notation, where `number` must match the number of the additional argument (starting with zero).

Parameters:

`key` - The message to localize

Returns:

The translated message

See:

- translate()
- formatMessage()

### markgettext

    String markgettext(<String> key)

A simple proxy method which is used to mark a message string for the i18n parser as to be translated.

Parameters:

`key` - The message that should be seen by the i18n parser as to be translated.

Returns:

The message in unmodified form

### message_macro

    String message_macro(param)

Returns a translated message. The following macro attributes are accepted:

- text: The message to translate (required)
- plural: The plural form of the message
- values: A list of replacement values. Use a comma to separate more than one value. Each value is either interpreted as a global property (if it doesn't containg a dot) or as a property name of the given macro handler object (eg. "user.name"). If the value of the property is a HopObject or an Array this macro uses the size() resp. length of the object, otherwise the string representation of the object will be used.

Returns:

The translated message

See:

- gettext()
- ngettext()

### ngettext

    String ngettext(<String> singularKey, <String> pluralKey, <Number> amount )

Returns a localized message for the message key passed as argument. In contrast to gettext() this method can handle plural forms based on the amount passed as argument. If no localization is found, the appropriate message key is returned. Any additional arguments passed to this function will be used as replacement values during message rendering. To reference these values the message can contain placeholders following "{number}" notation, where `number` must match the number of the additional argument (starting with zero).

Parameters:

`singularKey` - The singular message to localize

`pluralKey` - The plural form of the message to localize

`amount` - The amount which is used to determine whether the singular or plural form of the message should be returned.

Returns:

The translated message

See:

- translate()
- formatMessage()

### setHandler

    void setHandler(<Object> handler)

Set (overwrite) the default handler containing the messages (ie. a vanilla EcmaScript object).

Parameters:

`handler` - The handler containing the message object

Deprecated Use setMessages() instead

### setLocaleGetter

    void setLocaleGetter(<Function> func)

Set the method for retrieving the locale.

Parameters:

`func` - The getter method

### setMessages

    void setMessages(<Object> msgObject)

Overwrite the default object containing the messages (ie. a vanilla EcmaScript object).

Parameters:

`msgObject` - The object containing the messages

### translate

    String translate(singularKey, pluralKey, <Number> amount)

Tries to "translate" the given message key into a localized message.

Parameters:

`amount` - A number to determine whether to use the singular or plural form of the message

`key` - The message to translate (required)

`plural` - The plural form of the message to translate

Returns:

The localized message or the appropriate key if no localized message was found

Jala 1.3

Documentation generated by JSDoc on Tue Jan 8 15:45:31 2008