com.apamax
Event L10N


Event wrapper for doing translation / localization of EPL applications.

It's recommended that you import it into each monitor or event you use it in with:


L10N l10n;
action _(string message) returns string { return l10n.gettext(message); }
action _N(string singular, string plural, integer n) returns string { return l10n.ngettext(singular, plural, n); }
Use the convenience functions whenever you want a translated string, eg:


send Reply(l10n.printf(_("Unfortunately this didn't work for %1$s because of %1$s"), input, error)) to "output";
The L10N instance must be initialized to define the text domain and the location of the translations before use.

The locale to translate to is selected from the LANGUAGE environment variable.
Action summary
 stringgettext(string msgid)

Return the localized string in the appropriate language, or msgid unchanged if a translation cannot be found.
 voidinit(string textdomain)

Initialize this L10N instance for a particular textdomain using the default location for translations.
 voidinitFromPath(string textdomain, string translationsdir)

Initialize this L10N instance for a particular textdomain, reading the location of translations from an explicit path
 voidinitFromProperty(string textdomain, string translationsdirprop)

Initialize this L10N instance for a particular textdomain, reading the location of translations from a correlator property variable.
 stringngettext(string singular, string plural, integer n)

Return the localized string in the localized language with singular/plural selected based on a runtime parameter. If no translation is found the appropriate input parameter is returned.
 stringprintf(string format, sequence<any> args)

Use a printf-style format string to render the sequence of arguments.
 
Action detail

gettext

string gettext(string msgid)
Return the localized string in the appropriate language, or msgid unchanged if a translation cannot be found.

Normally this will be aliased to _ by a convenience function.
Parameters:
msgid - The string to translate in the input language (usually English).
Returns:
The translated string, or the input string if a translation is not found.

init

void init(string textdomain)
Initialize this L10N instance for a particular textdomain using the default location for translations.

The default translation location is APAMA_WORK/translations/textdomain/
Parameters:
textdomain - A unique string to locate the translations for this project

initFromPath

void initFromPath(string textdomain, string translationsdir)
Initialize this L10N instance for a particular textdomain, reading the location of translations from an explicit path
Parameters:
textdomain - A unique string to locate the translations for this project.
translationsdir - The path to the translations.

initFromProperty

void initFromProperty(string textdomain, string translationsdirprop)
Initialize this L10N instance for a particular textdomain, reading the location of translations from a correlator property variable.

Property values can be specified from a .properties file or with -D on the correlator command line.
Parameters:
textdomain - A unique string to locate the translations for this project.
translationsdirprop - The name of a correlator configuration property which contains a path to the translations.

ngettext

string ngettext(string singular, string plural, integer n)
Return the localized string in the localized language with singular/plural selected based on a runtime parameter. If no translation is found the appropriate input parameter is returned.

Normally this will be aliased to _N by a convenience function.
Parameters:
singular - The string to translate in the input language for n=1.
plural - The string to translate in the input language for n!1.
n - The number to use to determine if we should use the singular or plural translation.
Returns:
The translated string, or the input string if a translation is not found.

printf

string printf(string format, sequence<any> args)
Use a printf-style format string to render the sequence of arguments.

Often used in combination with the gettext and ngettext functions to insert parameters which might be in different locations in different translations. For example:


log l10n.printf(_N("Succesfully processed one %1$s", "Succesfully processed %2$d %1$ss", count), [type, count]) at INFO;
Notes:
Parameters:
format - A printf-style format string.
args - A sequence of all the arguments to format into the format string
Returns:
The string with the result substituted in