File tree Expand file tree Collapse file tree 2 files changed +25
-96
lines changed
Expand file tree Collapse file tree 2 files changed +25
-96
lines changed Original file line number Diff line number Diff line change @@ -1334,38 +1334,6 @@ exports[`Tests for Data Product definition Check interop CSN content 1`] = `
13341334 " genre_ID" : {
13351335 " type" : " cds.Integer" ,
13361336 },
1337- " localized" : {
1338- " on" : [
1339- {
1340- " ref" : [
1341- " localized" ,
1342- " ID" ,
1343- ],
1344- },
1345- " =" ,
1346- {
1347- " ref" : [
1348- " ID" ,
1349- ],
1350- },
1351- " and" ,
1352- {
1353- " ref" : [
1354- " localized" ,
1355- " locale" ,
1356- ],
1357- },
1358- " =" ,
1359- {
1360- " ref" : [
1361- " $user" ,
1362- " locale" ,
1363- ],
1364- },
1365- ],
1366- " target" : " sap.capdpprod.DPBooks.v1.Books.texts" ,
1367- " type" : " cds.Association" ,
1368- },
13691337 " modifiedAt" : {
13701338 " @EndUserText.label" : " {i18n>ChangedAt}" ,
13711339 " @UI.ExcludeFromNavigationContext" : true ,
@@ -1483,38 +1451,6 @@ exports[`Tests for Data Product definition Check interop CSN content 1`] = `
14831451 " length" : 1000 ,
14841452 " type" : " cds.String" ,
14851453 },
1486- " localized" : {
1487- " on" : [
1488- {
1489- " ref" : [
1490- " localized" ,
1491- " code" ,
1492- ],
1493- },
1494- " =" ,
1495- {
1496- " ref" : [
1497- " code" ,
1498- ],
1499- },
1500- " and" ,
1501- {
1502- " ref" : [
1503- " localized" ,
1504- " locale" ,
1505- ],
1506- },
1507- " =" ,
1508- {
1509- " ref" : [
1510- " $user" ,
1511- " locale" ,
1512- ],
1513- },
1514- ],
1515- " target" : " sap.capdpprod.DPBooks.v1.Currencies.texts" ,
1516- " type" : " cds.Association" ,
1517- },
15181454 " minorUnit" : {
15191455 " @EndUserText.label" : " {i18n>CurrencyMinorUnit}" ,
15201456 " type" : " cds.Int16" ,
@@ -1628,38 +1564,6 @@ exports[`Tests for Data Product definition Check interop CSN content 1`] = `
16281564 " length" : 1000 ,
16291565 " type" : " cds.String" ,
16301566 },
1631- " localized" : {
1632- " on" : [
1633- {
1634- " ref" : [
1635- " localized" ,
1636- " ID" ,
1637- ],
1638- },
1639- " =" ,
1640- {
1641- " ref" : [
1642- " ID" ,
1643- ],
1644- },
1645- " and" ,
1646- {
1647- " ref" : [
1648- " localized" ,
1649- " locale" ,
1650- ],
1651- },
1652- " =" ,
1653- {
1654- " ref" : [
1655- " $user" ,
1656- " locale" ,
1657- ],
1658- },
1659- ],
1660- " target" : " sap.capdpprod.DPBooks.v1.Genres.texts" ,
1661- " type" : " cds.Association" ,
1662- },
16631567 " name" : {
16641568 " @EndUserText.label" : " {i18n>Name}" ,
16651569 " length" : 255 ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const localize = require("@sap/cds/lib/i18n/localize");
44function interopCSN ( csn ) {
55 if ( typeof csn != "object" || csn === null ) return csn ; // handle non-object inputs early
66 add_i18n_texts ( csn ) ;
7+ remove_localized_assoc ( csn ) ;
78 map_annotations ( csn ) ;
89 add_meta_info ( csn ) ;
910 return csn ;
@@ -61,6 +62,30 @@ function add_i18n_texts(csn) {
6162 }
6263}
6364
65+ //
66+ // remove association "localized" for localized texts
67+ //
68+ // The "localized" association for localized elements contains a reference to $user.locale
69+ // and is specific to the CAP. It needs to be removed from the interop CSN.
70+ //
71+ function remove_localized_assoc ( csn ) {
72+ // how to detect "localized" association?
73+ // - name is "localized"
74+ // - type is "cds.Association"
75+ // - target name is source name + ".texts"
76+ // - there is an ON condition
77+ for ( let n1 in csn . definitions ) {
78+ let def = csn . definitions [ n1 ] ;
79+ if ( def . kind === "entity" )
80+ for ( let n2 in def . elements ) {
81+ let el = def . elements [ n2 ] ;
82+ if ( n2 === "localized" && el . type === "cds.Association" && el . target === `${ n1 } .texts` && el . on ) {
83+ delete def . elements [ n2 ] ;
84+ }
85+ }
86+ }
87+ }
88+
6489//
6590// annotation mapping/replacement
6691//
You can’t perform that action at this time.
0 commit comments