Schema localization
Contents
Labels and texts in schemas can be displayed in the users preferred language (based on browser settings).
Introduction
Any localizable field can be either a simple string, or an object with text and i18n properties. The i18n key must match an entry in your application’s src/main/resources/i18n/phrases.properties file.
| Schema localization uses the same properties file format as the rest of XP. Please consult the localization docs for more details. |
Localization is optional. When a field is a simple string, no localization is applied. When an i18n key is specified but no matching translation is found, the text value is used as fallback.
Example
Below is an example of a content type where localization has been enabled.
kind: "ContentType"
title:
text: "Person"
i18n: "person.title"
superType: "base:structured"
form:
- type: "TextLine"
name: "name"
label:
text: "Name"
i18n: "person.name.label"
occurrences:
min: 1
max: 1
- type: "TextLine"
name: "age"
label:
text: "Age"
i18n: "person.age.label"
occurrences:
min: 1
max: 1
- type: "ImageSelector"
name: "photo"
label:
text: "Photo"
i18n: "person.photo.label"
help-text:
text: "Passport photo"
i18n: "person.photo.help-text"
occurrences:
min: 0
max: 1
Supported Fields
In general, the following schema elements support localization via the text/i18n object pattern:
-
title
-
label
-
help-text
-
description
Other elements may also support localization, simply try adding the attribute to see if it works.
Translation files
The translated texts for each of the i18n keys should be placed in a corresponding phrases.properties and deployed via your Enonic application.
Steps to add the translations for a schema:
-
Add or edit one file per language supported:
src/main/resources/i18n/phrases_<language-code>.propertiesExample files to support English and Norwegiansrc/main/resources/cms/i18n/phrases.properties src/main/resources/cms/i18n/phrases_en.properties src/main/resources/cms/i18n/phrases_no.properties -
Add the i18n keys from the schema in each of the phrases.properties files.
Each line should have the key, an equals
=sign, and the text in the specific language.phrases_en.propertiesperson.title=Person person.name.label=Name person.age.label=Age person.photo.label=Photo person.photo.help-text=Passport photophrases_no.propertiesperson.title=Person person.name.label=Navn person.age.label=Alder person.photo.label=Bilde person.photo.help-text=Passbilde -
fallback file
phrases.propertiesfileIf this does not exist, the system will use the
textvalue from the schema as fallback for any missing translations. If it does exist, it will be used as fallback for any missing translations instead of thetextvalue from the schema. This allows you to provide default translations without having to add thetextvalue in the schema itself.