Kauri Documentation
 PreviousHomeNext 
11.5 Server APIBook Index12 Security

11.6 Client API

Since web pages are often constructed dynamically by downloaded Javascript code, features such as translation and number formatting need to be available client-side as well.

i18n REST-service

The kauri-i18n-impl bundle exposes an 'i18n' REST-service. The main purpose of this REST-service is to make resolved resource bundles available.

Getting a bundle

Motivation: due to locale fallback (e.g. from nl-BE to nl to en), looking up a key from a resource bundle might require reading multiple resources, which might or might not exist, and it would not be efficient to access all those resources from the browser. Therefore, the i18n REST-service provides a 'resolved' resource bundle, which is a merged view of the resource bundle and its fallback bundles.

Getting a bundle is done through this resource:

/bundles/{bundle}/{locale}

for example:

/bundles/org.myproject.mybundle/fr_CH

The locale can also be specified in full lower case, and using dash as separator, e.g. fr-ch

The resource bundle is returned as a JSON object, allowing easy use from Javascript.

[TODO: if values include mixed content, are these part of the json?]

Getting lists of locales and timezones

To help build GUIs to let users select their locale and timezone, the following resources are also available:

/info/locales/{locale}
/info/locales
/info/countries/{locale}
/info/countries
/info/languages/{locale}
/info/languages
/info/timezones/{locale}
/info/timezones

The optional {locale} specifies the locale in which the list should be returned. These resources are used by the locale settings page, which can be seen in action in the kauri-i18n-sample.

Javascript API

Building a message an displaying the text:

var kf = $.org.kauriproject.forms;
var msg = kf.Messsage.build(key, args[, type, source])
alert(msg.getText())

Setting a message bundle:

The example below does not work because kf.locale.loadMessages(path) is not implemented in Kauri 0.4 - See http://dev.outerthought.org/trac/outerthought_kauri/ticket/167
In Kauir 0.4 you should use kf.locale.setMessages(messages);

var kf = $.org.kauriproject.forms;
kf.locale.loadMessages("/bundles/org.myproject.mybundle/fr_CH");

Integration with Kauri forms

Validators and parsers (see  forms API)  have various methods that take messages and arguments - those are used to build messages as described above.

 PreviousHomeNext 
11.5 Server API12 Security