Internationalisation - AtlasOfLivingAustralia/biocollect GitHub Wiki

Internationalisation or i18n for short is supported by Grails. However, its use is limited to server side i.e. GSP pages, controller methods etc. This wiki article explains how to implement it in JavaScript file and HTML.

Basic requirement

jQuery and KnockoutJS are required. Another dependency is i18n.js file. Use below code in GSP to include it.

<asset:javascript src="i18n.js" asset-defer="true"/>

This file requires the following URL config.

fcConfig = {
 i18nURL: "${createLink(controller: 'home', action: 'i18n')"
} 

NOTE the above action returns i18n file but in JSON format.

Usage in HTML

<div data-bind="i18n: 'g.cancel'"></div>

Where g.cancel is the property name.

or

<div data-bind="i18n: {key: 'record.edit.verificationStatusTypes.help', contentType: 'html', defaultValue: '<b>simple help</b>'}"></div>

Here, the property value has HTML code and therefore requires contentType to be set to html for correct rendering. The default contentType is text.

Usage in JavaScript

$i18nAsync('biocollect.data.map.selector.help.title', 'Your default text here', function (value) { 
   console.log(value);
});
⚠️ **GitHub.com Fallback** ⚠️