In this lesson, we will look at how to provide translations for textual application data. For example, there may be a requirement to maintain the title of a book in different languages.
We will first look at how to declare localized data.
Declaring Localized Data
The localized modifier is used to declare localized data. Use it to identify the entity elements that require translated texts. In the following figure, the title element of the Books entity is marked accordingly:

Behind the Scenes
Based on the preceding definition, various things are automatically generated by the cds compiler. Amongst others, a separate Books.texts entity is generated to hold translated texts. This entity has the following structure:
12345entity Books.texts {
key locale : sap.common.Locale;
key ID : UUID;
title : String(255);
}
The Books.texts entity has the two key fields locale and ID.
The key field locale has the data type sap.common.Locale, which is a common reuse type from the aforementioned @sap/cds/common model. Ultimately, this type is used to define a string with a length of 14. The locale field is intended to store language codes such as en or de.
The second key field ID corresponds to the primary key of the Books entity.
With the Books.texts entity, a translated title for each language code (locale) can be saved for each book, i.e. each ID.
Besides the Books.texts entity, additional views are also created via the generated SQL DDL in order to read the localized texts.
Serving Localized Data
The generic handlers of the service runtimes automatically serve read requests in the user's preferred language with the help of the generated views. In our example, users automatically receive the book title in their preferred language or, if no translation is available for this language, in the fallback language. This is then the title as it is stored in the table belonging to the Books entity.
You can use the URL parameter sap-locale to test different languages. In the following example, German texts are requested:
1GET <your_service_url>/Books?sap-locale=de
Alternatively, you can also use requests with an appropriate Accept-Language header:
12GET <your_service_url>/Books
Accept-Language: de
The URL parameter sap-locale has the highest preference. It overrides the Accept-Language header if this should also be set.
Let's now take a look at how localized data can initially be made available for the application.
Adding Initial Data
Watch the video to see how to add initial data.
In the following section, we will discuss the CodeList aspect and the Country and Currency types from the @sap/cds/common model.