Skip to content

Internationalisation

temi edited this page Oct 19, 2020 · 3 revisions

Internationalisation

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

KnockoutJS is required. It also requires i18n.js file. It can be intialised by the following code.

i18nInitilisation("https://biocollect.ala.org.au/home/i18n");

Where URL is controller method that gets i18n file content.

NOTE This is already included in layout page. You can skip this step.

Usage in HTML

<strong data-bind="text: $i18n('biocollect.data.map.selector.help.title', 'Your default text here')"></strong>

Where biocollect.data.map.selector.help.title is the property name.

If your i18n code has HTML, then use KnockoutJS's html binding.

<strong data-bind="html: $i18n('biocollect.data.map.selector.help.title', 'Your default text here')"></strong>

NOTE It is assumed that the above HTML is in a section activated by KnockoutJS.

Usage in JavaScript

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