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.

Localized content type schema
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:

  1. Add or edit one file per language supported:

    src/main/resources/i18n/phrases_<language-code>.properties

    Example files to support English and Norwegian
    src/main/resources/cms/i18n/phrases.properties
    src/main/resources/cms/i18n/phrases_en.properties
    src/main/resources/cms/i18n/phrases_no.properties
  2. 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.properties
    person.title=Person
    person.name.label=Name
    person.age.label=Age
    person.photo.label=Photo
    person.photo.help-text=Passport photo
    phrases_no.properties
    person.title=Person
    person.name.label=Navn
    person.age.label=Alder
    person.photo.label=Bilde
    person.photo.help-text=Passbilde
  3. fallback file phrases.properties file

    If this does not exist, the system will use the text value 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 the text value from the schema. This allows you to provide default translations without having to add the text value in the schema itself.


Contents

Contents