The Translation Schema API allows you to manage the schema for translating site content. Define the structure and fields of your app's translatable content to ensure consistency and accuracy across different locales. You only need to do this setup once per entity, providing a foundation for all future translations.
You can create schemas for each entity of your app. For example, if you are developing a food delivery app, you may want to create two schemas, one for a menu and another for orders.
With the Translation Schema API, your app can:
You can also set validations for fields in the schema. For example, in the schema below, the title field has a minLength
of 1, meaning the smallest valid text value for that field must be at least one character long. If validations are defined in the schema, the corresponding content is constrained to those validations. If you add invalid content you'll get a validation error.
It’s important to note the following points before starting to code:
Scope: A schema can have one of two scopes:
Site: A custom schema for a specific site.
Global: A global schema for all sites.
You can update both site and global schemas, as well as change a site schema to global or vice versa. However, if you need to create a site-specific schema based on an existing global one, create a new schema with a site scope and manually copy the specifications from the existing global one.
Schema field: This defines the structure and validation rules for a field within a translation schema. It specifies the type of data (such as text or image) and constraints (such as minimum or maximum length) for each field in the schema. The SchemaField
ensures that any content added conforms to the defined format.
Fields: A list of fields for the translation schema. The fields
property uses a string to map to a SchemaField
(Map<string, SchemaField>
). The string serves as a key, which you'll need to access each field in the schema and when adding translation content.