The cms is multi-language capable. Available languages can be defined for the front- and the backend individually.

Configuration can be adjusted directly for each site/domain within multi-site support. To include languages you should use the following steps:

Configuration



cms.sites = [
{
name: site1.ch
key: site1
hosts: ["localhost:9000", "site1.ch:9000", www.site1.ch]
langs: {
# There should be only lang tags
# Language support separated for the both sides - frontend & backend
frontend: [de, en]
backend: [en]
}
logoPath: "uploads/site1.png"
}
...
]

Retrieving the languages

To retrieve the list of front- and backend languages:

// Get the front- or backend languages
    CMS.getConfig().frontendLanguages();
    CMS.getConfig().backendLanguages();

    // Get the currently selected language
    Language.getCurrentLanguage();


Switching the visitor's language

  • Via GET: Add ?lang=<lang-code> to the URL
  • In code (forcefully, should be used for tests only): Language.forceCurrentLanguage(<language code>);

Language selection example

@for(lang <-CMS.getConfig.backendLanguages) {
    <li>
    @if(Language.getCurrentLanguage.equals(lang)){<strong>}
    <a href="@CMS.getConfig.backendPath()?lang=@lang">@lang.toUpperCase</a>
    @if(Language.getCurrentLanguage.equals(lang)){</strong>}
    </li>
    }


Hint: If you have dynamic urls that can have GET params, use @Template.addGetParm() to easily add the param to the url.