2025 May 03 11:44 AM - edited 2025 May 03 11:59 AM
When using CAP with NodeJS runtime, you may have been in contact with the "bookshop sample" over the years. This is also generated as complete sample application in your project folder, when you run
cds add sample
on the command line.
You may have noticed, that in the UI on the object (detail) page for a book, in the "Translations" section it is currently not possible to add another localization line with a locale, title and description for further languages. There is no data available as value help and whatever you enter as locale in the draft is not accepted:
If you leave it empty, you can save the draft, but then you have no locale for your new entry and also this can not be edited afterwards:
To be honest, I was a bit surprised, that this sample, which SAP uses in many tutorials / learning courses and included in the CDS tooling to be generated as sample, shows such a basic deficiency.
The reasons seems to be, that this sample was developed earlier for OData V2 and not migrated cleanly over time to OData V4. The main problem in the file app/admin-books/fiori-service.cds is the following line, which is not valid anymore in OData V4:
locale @(ValueList.entity: 'Languages', Common.ValueListWithFixedValues)
The fixes seem to be relatively simple. In the file app/admin-books/fiori-service.cds you add in the header:
using {sap} from '@sap/cds/common';
using from '@sap/cds-common-content';
The locale annotation block has to be replaced.
Old:
// Add Value Help for Locales
annotate AdminService.Books.texts {
locale @(rvice.c
ValueList.entity: 'Languages',
Common.ValueListWithFixedValues, //show as drop down, not a dialog
)
};o OData
New: ValueL
// Add Value Help for Locales
annotate AdminService.Books.texts with {
locale @(
Common.FieldControl : #Mandatory,
Common.ValueListWithFixedValues,
Common.ValueList : {
$Type : 'Common.ValueListType',
CollectionPath: 'Languages',
Parameters : [
{ $Type : 'Common.ValueListParameterInOut',
LocalDataProperty: locale,
ValueListProperty: 'code' },
{ $Type : 'Common.ValueListParameterDisplayOnly',
ValueListProperty: 'descr' }
]
}
);
};
In package.json in the dependencies, you will have to add "@sap/cds-common-content": "^2.1.0", like:
"dependencies": {
"@sap/cds": "^8",
"@sap/cds-common-content": "^2.1.0",
"express": "^4"
},
This can be done on the command line with:
npm add @sap/cds-common-content --save
This will show all language / country codes currently defined in the cds-common package as value help for the locale field:
If you select 'es' and add some text, after saving the draft, you will see:
If you do not want to see all predefined languages / country codes and want to override it with a selection of your choice, you can add a table as CSV in the db/data folder under the name db/data/sap.common-Languages.csv for example with this content:
code;descr
de;Deutsch
en;English
fr;Français
es;Español
it;Italiano
Hoping this helps - and hoping SAP will fix their sample code generated by the cds tool as well.
(Sorry for some strange characters and formattings in this post, but it could not be fixed using the buggy WYSIWYG editor)
Request clarification before answering.
User | Count |
---|---|
24 | |
22 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.