Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.cds
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ annotate ChangeView with @(UI: {
RequestAtLeast: [
parentKey,
serviceEntity,
serviceEntityPath
serviceEntityPath,
valueDataType
],
SortOrder : [{
Property : createdAt,
Expand Down
30 changes: 30 additions & 0 deletions lib/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,43 @@ const _getLabelI18nKeyOnEntity = function (entityName, /** optinal */ attribute)
return def['@Common.Label'] || def['@title'] || def['@UI.HeaderInfo.TypeName'];
};

const _localizeDates = (change, locale) => {
if (change.valueDataType === 'cds.Date') {
const defaultLocale = 'en';
const normalizedLocale = locale ? locale.replaceAll('_', '-') : defaultLocale;

const formatOptions = {
'de': { day: '2-digit', month: '2-digit', year: 'numeric' }, // 15.07.2025
'en': { day: 'numeric', month: 'short', year: 'numeric' }, // Jul 15, 2025
'es': { day: '2-digit', month: 'short', year: 'numeric' }, // 15 jul 2025
'fr': { day: '2-digit', month: 'short', year: 'numeric' }, // 15 juil. 2025
'it': { day: '2-digit', month: 'short', year: 'numeric' }, // 15 lug 2025
'ja': { year: 'numeric', month: '2-digit', day: '2-digit' }, // 2025/07/15
'pl': { day: '2-digit', month: 'short', year: 'numeric' }, // 15 lip 2025
'pt': { day: '2-digit', month: 'short', year: 'numeric' }, // 15 de jul. de 2025
'ru': { day: '2-digit', month: 'short', year: 'numeric' }, // 15 июл. 2025 г.
'zh-CN': { year: 'numeric', month: 'long', day: 'numeric' } // 2025年7月15日
};

const options = formatOptions[normalizedLocale] || formatOptions[defaultLocale];

if (change.valueChangedFrom) {
change.valueChangedFrom = new Date(change.valueChangedFrom).toLocaleDateString(normalizedLocale, options);
}
if (change.valueChangedTo) {
change.valueChangedTo = new Date(change.valueChangedTo).toLocaleDateString(normalizedLocale, options);
}
}
};

const localizeLogFields = function (data, locale) {
if (!locale) return
for (const change of data) {
_localizeModification(change, locale);
_localizeAttribute(change, locale);
_localizeEntityType(change, locale);
_localizeDefaultObjectID(change, locale);
_localizeDates(change, locale);
}
};
module.exports = {
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/fiori-draft-enabled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ describe("change log integration test", () => {
expect(registryChange.objectID).to.equal("San Francisco-2");
expect(registryChange.entity).to.equal("Book Store Registry");
expect(registryChange.valueChangedFrom).to.equal("");
expect(registryChange.valueChangedTo).to.equal("2022-01-01");
expect(registryChange.valueChangedTo).to.equal("Jan 1, 2022");
expect(registryChange.parentKey).to.equal("01234567-89ab-cdef-0123-456789abcdef");
expect(registryChange.parentObjectID).to.equal("Murder on the Orient Express");
});
Expand Down Expand Up @@ -1540,8 +1540,8 @@ describe("change log integration test", () => {
const registryChange = registryChanges[0];
expect(registryChange.attribute).to.equal("Valid On");
expect(registryChange.modification).to.equal("Update");
expect(registryChange.valueChangedFrom).to.equal("2022-10-15");
expect(registryChange.valueChangedTo).to.equal("2022-01-01");
expect(registryChange.valueChangedFrom).to.equal("Oct 15, 2022");
expect(registryChange.valueChangedTo).to.equal("Jan 1, 2022");
expect(registryChange.parentKey).to.equal("5ab2a87b-3a56-4d97-a697-7af72334a384");
expect(registryChange.parentObjectID).to.equal("The Strand");
});
Expand All @@ -1566,8 +1566,8 @@ describe("change log integration test", () => {
const registryChange = registryChanges[0];
expect(registryChange.attribute).to.equal("Valid On");
expect(registryChange.modification).to.equal("Update");
expect(registryChange.valueChangedFrom).to.equal("2018-09-01");
expect(registryChange.valueChangedTo).to.equal("2022-01-01");
expect(registryChange.valueChangedFrom).to.equal("Sep 1, 2018");
expect(registryChange.valueChangedTo).to.equal("Jan 1, 2022");
expect(registryChange.parentKey).to.equal("8aaed432-8336-4b0d-be7e-3ef1ce7f13ea");
expect(registryChange.parentObjectID).to.equal("City Lights Books");
});
Expand All @@ -1588,7 +1588,7 @@ describe("change log integration test", () => {
const registryChange = registryChanges[0];
expect(registryChange.attribute).to.equal("Valid On");
expect(registryChange.modification).to.equal("Delete");
expect(registryChange.valueChangedFrom).to.equal("2018-09-01");
expect(registryChange.valueChangedFrom).to.equal("Sep 1, 2018");
expect(registryChange.valueChangedTo).to.equal("");
expect(registryChange.parentKey).to.equal("8aaed432-8336-4b0d-be7e-3ef1ce7f13ea");
expect(registryChange.parentObjectID).to.equal("City Lights Books");
Expand Down
Loading