Methods and macros for internationalization
of Helma applications.
Constructs a new instance of jala.I18n
methods
- setMessages(msgObject)
- setLocaleGetter(func)
- setHandler(handler)
- getLocale(localeId)
- translate(key, plural, amount)
- getCatalog(locale)
- formatMessage(message, values)
- gettext(key)
- ngettext(singularKey, pluralKey, amount)
- markgettext(key)
- message_macro(param)
Default i18n class instance.
Methods
Overwrite the default object containing
the messages (ie. a vanilla EcmaScript object).
parameters
Object | msgObject | The object containing the messages |
Set the method for retrieving the locale.
parameters
Function | func | The getter method |
Set (overwrite) the default handler containing
the messages (ie. a vanilla EcmaScript object).
parameters
Object | handler | The handler containing the message object |
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.parameters
localeId |
returns
The locale for the given id |
Tries to "translate" the given message key into a localized
message.
parameters
String | key | The message to translate (required) |
String | plural | The plural form of the message to translate |
Number | amount | A number to determine whether to use the singular or plural form of the message |
returns
The localized message or the appropriate key if no localized message was found |
Helper method to get the message catalog
corresponding to the actual locale.
parameters
locale |
returns
The message catalog. |
Converts the message passed as argument into an instance
of java.text.MessageFormat, and formats it using the
replacement values passed.
parameters
String | message | The message to format |
Array | values | An optional array containing replacement values |
returns
The formatted message or, if the formatting fails, the message passed as argument. |
see
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
String | key | The message to localize |
returns
The translated message |
see
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
String | singularKey | The singular message to localize |
String | pluralKey | The plural form of the message to localize |
Number | 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
A simple proxy method which is used to mark a message string
for the i18n parser as to be translated.
parameters
String | key | The message that should be seen by the i18n parser as to be translated. |
returns
The message in unmodified form |
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.
parameters
param |
returns
The translated message |
see