1
1
const cds = require ( "@sap/cds/lib" ) ;
2
2
const LOG = cds . log ( "change-log" ) ;
3
3
const { getNameFromPathVal, getDBEntity } = require ( "./entity-helper" ) ;
4
- const OBJECT_TYPE_I18N_LABEL_KEY = "@Common.Label"
5
- const OBJECT_TYPE_I18N_TITLE_KEY = "@title"
6
4
7
5
const MODIF_I18N_MAP = {
8
6
create : "{i18n>ChangeLog.modification.create}" ,
@@ -43,7 +41,7 @@ const _localizeDefaultObjectID = function (change, locale) {
43
41
const parentEntityName = getNameFromPathVal ( parentNodePathVal ) ;
44
42
const dbEntity = getDBEntity ( parentEntityName ) ;
45
43
try {
46
- const labelI18nKey = dbEntity [ OBJECT_TYPE_I18N_LABEL_KEY ] ;
44
+ const labelI18nKey = dbEntity [ '@Common.Label' ] || dbEntity [ '@title' ] ;
47
45
const labelI18nValue = labelI18nKey ? _getLocalization ( locale , labelI18nKey ) : null ;
48
46
change . parentObjectID = labelI18nValue ? labelI18nValue : dbEntity . name ;
49
47
} catch ( e ) {
@@ -56,7 +54,7 @@ const _localizeDefaultObjectID = function (change, locale) {
56
54
const _localizeEntityType = function ( change , locale ) {
57
55
if ( change . entity ) {
58
56
try {
59
- const labelI18nKey = _getLabelI18nKeyOnEntity ( change . entity ) ;
57
+ const labelI18nKey = _getLabelI18nKeyOnEntity ( change . serviceEntity ) ;
60
58
const labelI18nValue = labelI18nKey ? _getLocalization ( locale , labelI18nKey ) : null ;
61
59
62
60
change . entity = labelI18nValue ? labelI18nValue : change . entity ;
@@ -83,12 +81,11 @@ const _localizeAttribute = function (change, locale) {
83
81
try {
84
82
const serviceEntity = cds . model . definitions [ change . serviceEntity ] ;
85
83
let labelI18nKey = _getLabelI18nKeyOnEntity ( change . serviceEntity , change . attribute ) ;
86
- const element = serviceEntity . elements [ change . attribute ] ;
87
- if ( element . isAssociation && ! labelI18nKey ) {
88
- labelI18nKey = _getLabelI18nKeyOnEntity ( element . target ) ;
84
+ if ( ! labelI18nKey ) {
85
+ const element = serviceEntity . elements [ change . attribute ] ;
86
+ if ( element . isAssociation ) labelI18nKey = _getLabelI18nKeyOnEntity ( element . target ) ;
89
87
}
90
88
const labelI18nValue = labelI18nKey ? _getLocalization ( locale , labelI18nKey ) : null ;
91
-
92
89
change . attribute = labelI18nValue ? labelI18nValue : change . attribute ;
93
90
} catch ( e ) {
94
91
LOG . error ( "Failed to localize change attribute" , e ) ;
@@ -98,14 +95,10 @@ const _localizeAttribute = function (change, locale) {
98
95
} ;
99
96
100
97
const _getLabelI18nKeyOnEntity = function ( entityName , /** optinal */ attribute ) {
101
- const entity = cds . model . definitions [ entityName ] ;
102
- if ( ! entity ) return "" ;
103
- if ( attribute ) {
104
- const element = entity . elements [ attribute ] ? entity . elements [ attribute ] : { } ;
105
- return element [ OBJECT_TYPE_I18N_LABEL_KEY ] ;
106
- }
107
- const entityLabel = entity [ OBJECT_TYPE_I18N_LABEL_KEY ] ? entity [ OBJECT_TYPE_I18N_LABEL_KEY ] : entity [ OBJECT_TYPE_I18N_TITLE_KEY ] ;
108
- return entityLabel ;
98
+ let def = cds . model . definitions [ entityName ] ;
99
+ if ( attribute ) def = def ?. elements [ attribute ]
100
+ if ( ! def ) return "" ;
101
+ return def [ '@Common.Label' ] || def [ '@title' ] ;
109
102
} ;
110
103
111
104
const localizeLogFields = function ( data , locale ) {
0 commit comments