SAP / open-ux-odata

Enable community collaboration to jointly promote and facilitate best in class framework and tooling capabilities when working with OData services.
Apache License 2.0
51 stars 12 forks source link

BUG - @sap-ux/fe-mockserver-plugin-cds i18n handling #834

Open heimwege opened 3 months ago

heimwege commented 3 months ago

Description

i18n annotations in the data model, e.g.

/srv/i18n/i18n.properties

name=Name

/db/data-model.cds

entity Samples : cuid, managed {
    name     : String(50) @title : '{i18n>name}'; // <-- this one here
    comments : composition of many Comments on comments.sample = $self;
}

are not being resolved in the metadata

<Annotations Target="CapFeTsSampleService.Samples/name">
        <Annotation Term="Common.Label" String="{i18n>name}"/>
</Annotations>

whereas the cds build resolves it to

<Annotations Target="CapFeTsSampleService.Samples/name">
        <Annotation Term="Common.Label" String="Name"/>
</Annotations>

The i18n used in the UI annotations (referring to ./webapp/i18n/i18n.properties) work fine

Expected results

UI displaying Name as table column header (e.g. when property is used as LineItem)

Actual results

UI displays {i18n>name} as table column header (e.g. when property is used as LineItem)

Screenshots

image

image

table title i18n coming from ./webapp/i18n/i18n.properties πŸ‘πŸ» table column headers coming from /srv/i18n/i18n.properties or even directly from CAP (using @sap/cds/common) like ChangedBy πŸ‘ŽπŸ»

Not sure where the path ../i18n/i18n.properties is coming from 🀷🏻

Version/Components/Environment

Add any other context about the problem here OS:

Root Cause Analysis

Problem

{describe the problem}

Fix

{describe the fix}

Why was it missed

{Some explanation why this issue might have been missed during normal development/testing cycle}

How can we avoid this

{if we don’t want to see this type of issues anymore what we should do to prevent}

nlunets commented 3 months ago

That would be nice, but the cds-compiler API doesn't seem to support the i18n, even if we pass them directly... We could replace and parse in the target EDMX but that becomes a bigger work :/

heimwege commented 3 months ago

Oh no. This might be a real blocker for using the plugin because e.g. OPA5 tests might fail if the text is not as expected. I'll open a CAP issue and ask the guys? They must do it somewhere along the cds build as well 🀷🏻

nlunets commented 3 months ago

Let me check for a dirty solution :)

heimwege commented 3 months ago

Ok, then I'll wait for your feedback 🐱

heimwege commented 2 months ago

1.2.1 looks much better πŸ₯³ i18n is shown but there are some superfluous , (just for some not all 🀷🏻)

image

nlunets commented 2 months ago

That might be due to what i copied ;o

heimwege commented 2 months ago

The , is gone in 1.2.2. And I adjusted the i18n keys to ese the identification (samples and Samples looks quite the same πŸ™ˆ). So now we're at image

The cds common stuff works πŸ‘πŸ» but the annotations from db/data-model.cds ({i18n>nameI18n}) and app/samples/ui-annotations.cds ({i18n>samplesI18n}) are using the i18n key instead of the value as fallback because loadI18nMap is being called with dirName pointing to the app folder <someLocalPath>\cap-fe-ts-sample\app\samples. Hence all the i18n paths from loadI18nMap do not point to a file 😒

Maybe project-access or i18n could help to find the i18n file(s)?

Or the location from the csn could be used as starting point image

Or add hard coded /webapp/i18n and /../../srv/i18n. That worked for me as well 🐱

nlunets commented 2 months ago

Dependencies are not really possible or wanted as they tend to create dedicated fs requirement :) Looking at the cds documentation /webapp/i18n would not be considered, maybe /../../srv/i18n because this file is being loaded .... Do you have a sample repo that i can check directly ? would avoid more back and forth :)

heimwege commented 3 weeks ago

Here's the respective branch: https://github.com/heimwege/cap-node-fe-ts-sample/tree/Fe-mockserver-plugin-cds just npm run install:all and npm run ui:mockserver then you see

image

The green marked texts are wrong (from srv/i18n/i18n.properties): samples should be Samples_i18n name should be Name_i18n