ALA Internationalization (i18n) - AtlasOfLivingAustralia/documentation GitHub Wiki

Grails uses the standard Java way of providing internationalisation - using messages.properties and the g:message taglib for use in GSP pages. Language detection can be triggered by the browser providing a locale value or by providing an additional request parameter called lang. E.g. add ?lang=es to a request URL.

The client webapp (e.g. generic-hub) inherits some internationalisation properties from the biocache-hubs plugin, which in turn, inherits further properties from biocache-service (via a webservice call. Custom i18n properties can be added/overrided by including the appropriate messages file.

Warning : There are differences between the English sentence structuration and the French one (same as Spanish) To prevent this problem, you have to make modifications directly on the code and create new terms in messages.properties

i18n properties files

Grails i18n files are found in:

/grails-app/i18n

and follow the Java naming convention of messages_xx_XX.properties. The ALA is keen to get contributions for non-English translations via crowdin.

These properties files are now packaged as mentioned in ala-i18n so you can easily install in your node these up-to-date translations and also some local customizations.

UI lang selection via html/js

ALA uses jquery-i18n-properties plugin to translate charts, etc.

You can use this plugin also to translate some parts of your branding via customization of your header.html and footer.html to create your lang selector menu or lang buttons. For that use the lang parameter in UI elements urls that we mentioned previously, locale browser detection.

Currently the ALA modules only store the lang url parameter selection for the session (30 minutes), so while we don't use other strategy to remember the user lang selection like grails CookieLocaleResolver or storing it in userdetails, you can try some workaround as Spain did here.

For the rest of header/footer strings to internationalize here a sample of usage.

UI lang selection via Grails

Here you have the instructions to do the correctly configuration of lang-selector plugin in your module. Now, we are going to suppose that you want to install and configure this plugin in generic-hub.

  1. You have to include in the section of plugins of BuildConfig.grrovy this code:

    runtime ":lang-selector:0.3"

  2. After this, you can add the tag to your gsp. For example, you can include it in the header sections of /grails-app/views/laouts/generic.gsp to see the lang selector in all views of your generic-hub module.

  3. Optionally you can add this property to the /grails-app/conf/Config.groovy to tell the plugin which flag display for the language:

    com.mfelix.grails.plugins.langSelector.lang.flags = ["es":"es", "en":"gb", "fr":"fr", "da":"dk", "de":"de", "it":"it", "ja":"jp", "nl":"nl", "ru":"ru", "th":"th", "zh":"cn", "pt":"pt", "ca":"catalonia"]

Also, you can do this in the collectory module.

Now we are going to suppose that you don't want to have a flags, maybe for more accesibility or for other reasons. In this case, you have to modify the code of this plugin. To do that you have to download the plugin, calling it locally in the /grails-app/BuildConfig.groovy, and you have to modify /lang-selector-0.3/grails-app/views/langSelector/_selector.gsp:

BuildConfig.groovy:

grails.plugin.location.'lang-selector' = "plugins/lang-selector-0.3"

_selector.gsp:

<div id="lang_selector">
<span style="color:white"><g:message code="1" default="|"/></span>
<g:each in="${flags.keySet().sort() }" var="lang">
	<a href="${ uri + lang }" title="${message(code:'tittle.lang_link')}">
		<span class="lang_flag ${ lang==selected.toString()? selected_class : not_selected_class }" style="margin-left: 14px;">
		<g:if test="${flags[lang] == 'catalonia'}">
		        <g:message code="1" default="Català"/>
		</g:if>
		<g:if test="${flags[lang] == 'gb'}">
		        <g:message code="1" default="English"/>
		</g:if>

		<g:if test="${flags[lang] == 'es'}">
		        <g:message code="1" default="Español"/>
		</g:if>
		<%--<img alt="" src="${resource(plugin:'langSelector',dir:'images/flags/png',file:flags[lang]+'.png') }" border="0">--%>
		</span>
	</a>
	<span style="color:white"><g:message code="1" default="|"/></span>
</g:each>

More information

See this list of known issues in LA Internationalization.

⚠️ **GitHub.com Fallback** ⚠️