Specifying internationalization settings

October 8, 2024

Jahia supports enabling multiple languages for sites. For more information, see Managing languages for your site. As a developer, you define which fields are internationalized fields for content editors. This topics shows how to mark a field as internationalized and provides a description of the content model.

Internationalized fields

An internationalized field has a different value for each language. You can mark a field as internationalized by adding the internationalized keyword or i18n in the CND file. Any field type can be marked as internationalized. In this example, body and image fields are internationalized. The text and associated image differs for every language.

[jnt:mainContent] > jnt:content, mix:title, jmix:structuredContent, jmix:editorialContent
- body (string, richtext) i18n
- image (weakreference, picker[type='image']) i18n
- align (string,choicelist[resourceBundle]) = left indexed=no < left,right,default

Non internationalized fields are marked with Shared by all languages indicating that they have the same value in all languages. If Shared by all languages is absent, then the field is internationalized. 

international-field.png

Note: The align field is not internationalized, but the displayed label differs depending on the selected language. The value itself is shared between all languages, but the resourceBundle keyword indicate if the value is a resource bundle key.

Content model

Internationalized fields are stored in a special subnode of the content. The subnode is named j:translation_lang and has the jnt:translation type. This type is unstructured and stores all internationalized properties of its parent.

i18n-content-model.png

Using localized and unlocalized sessions

Translation nodes are usually hidden from the user. As long as the session is opened with a locale (localized session), internationalized properties are transparently returned by getProperty() methods and other APIs. Translation nodes display when using a non-localized session. A localized session can be opened using the following method from JCRSessionFactory:

public JCRSessionWrapper getCurrentUserSession(String workspace, Locale locale) throws RepositoryException;

You can use any other methods from JCRSessionFactory and JCRTemplate that take the locale as a parameter to retrieve a localized session.

All the sessions that are used for rendering, for example the ones used in JSP views, are localized.

Publishing translated nodes

The lifecycle of the translation nodes is separate from their parent node. They can be published independently.