on 03-14-2019 2:29 PM
Reading the blog https://blogs.sap.com/2018/08/24/top-5-time-saving-benefits-of-the-application-programming-model-for..., in first Item. I had a question about localized strings. I had expected a second table with the product descriptions and language as one of the keys, or something in the table to identify the text language.
for exemple:
entity ProductTypes {
key code : Integer;
name : localized String(40) @title:'{i18n>Name}';
}
I need to create a CSV file to import ProductTypes in different languages, how can I do that, since I don't have a field to choose the locale ou language?
Regards
Hi
This is a good question; I've done a little digging as I think the docu on the public facing site is a little behind. The 'localized' modifier is indeed valid and the right thing to add, but the feature itself is still in beta. In order to use the feature, make sure you have a .cdsrc.json file in the root of your project (initialising a new project with 'cds init' will give you one of these files anyway) and add the following to it:
"features": {
"localized": true
},
"cdsc": {
"betaMode": true
}
When you then compile explicitly, or implicitly (via 'cds deploy'), you will get not only the table definition:
CREATE TABLE ProductTypes (
code INTEGER,
name NVARCHAR(40),
PRIMARY KEY(code)
);
but also a locale-specific "texts" table too:
CREATE TABLE ProductTypes_texts (
locale NVARCHAR(5),
code INTEGER,
name NVARCHAR(40),
PRIMARY KEY(locale, code)
);
In addition, for SQLite based persistence layers, you get some views that are locale-specific.
dj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
With the newest CDS version, the localized feature works without extra cdsrc.json settings.
It also works for HANA DB, and both Data versions.
Assuming that you have exposed the ProductTypes in your service, if you select from it, the name will be the localized name (if your have a translation in ProductTypes_texts).
Under the hood, the service runtime will first check whether there is a definition for `localized.<yourService>.ProductTypes` which is an automatically created view which select from ProductTypes_texts (and ProductTypes if there is no translation).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, following your advice I had define a service like that
service TestService {
entity ProductTypes as projection on db.ProductTypes;
}
where db.ProductTypes is the localized entity.
When I test with postman the EntitySet I got this response:
{
"error": {
"code": "Operation is not supported.",
"message": "Operation is not supported."
}
}
What's wrong with that?
Any idea?
Gianni
In your text table, I see 'de_DE' as LOCALE - you should use just 'de'.
For details, see https://cap.cloud.sap/docs/guides/i18n#user-locale.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
I have a CAP Node.JS service with an entity ValueHelps which is localized. Also, data is available in the database and req.user.locale is set to 'de' if I add sap-language as URL parameter. Nevertheless, always the default language is shown.
http://localhost:4004/import/ValueHelps('42458')?sap-language=de
{
"@odata.context": "$metadata#ValueHelps/$entity",
"ID": "42458",
"name": "Organizational Management",
"description": null,
}
help-service.cds
using{ de.org as my }from'../db/src/schema';
service HelpService @readonly{
entity ValueHelps as projection on my.ValueHelps;...}
help-service.js
const cds = require('@sap/cds')module.exports = async function(){
this.on('READ',(req,res,next)=>{
console.log(req.user.locale)})...}
schema.cds
entity ValueHelps : managed {keyID:String;
externalID :String;type:String;name: localized String;description: localized String;status:String;}
entity Users : managed {keyID:String;locale:String;}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.