12.01
The setup
We need to provide different language versions of a site based on the language of the article, or perhaps the domain of the site. This relates to the static text of the design, and not the content itself, wich of course is already translated.
Implementation
To do this, we use the import <library> as <name> in Freemarker.
First we create 2 different libraries, ie. lib/translations-en and lib/translations-no, and assign our variables. We have to have the same variable names in both libraries.
Examples (norwegian):
<#assign home="Hjem">
<#assign here="Du er her">
<#assign by="av">
<#assign lastUpdated="sist oppdatert">
and english:
<#assign home="Home" >
<#assign here="You are here" >
<#assign by="by">
<#assign lastUpdated="last updated">
Then we import one of the libraries into our template, by using the switch directive:
<#switch fullHost>
<#case "http://dev.baltic-recruiting.lt">
<#import "lib/translations-lt" as langlib>
<#break>
<#default>
<#import "lib/translations-no" as langlib>
</#switch>
This does the import by querying the fullHost, but you can also use data.language.
Now we can reference the translated strings by using ${langlib.<variable>}, for example ${langlib.home} to display the home string.
You can see this in effect by visiting www.baltic-recruiting.com and www.baltic-recruiting.lt