ui5-language-assistant icon indicating copy to clipboard operation
ui5-language-assistant copied to clipboard

feat: add XML validation and quickfix for hardcoded UI text

Open fausto-m opened this issue 3 years ago • 14 comments

This is a validator that warns the user of hardcoded UI texts in XML views/fragments that could be externalized to a resource bundle. Includes a quick fix for the warning, where externalized strings from the project's i18n.properties file (if existent) may be suggested as replacements.

fausto-m avatar Sep 06 '22 07:09 fausto-m

This pull request introduces 1 alert when merging 5c5968d2d770cf618a1ce177cfe45f593fb18eb9 into 9d0c89c2d912b2c929fb3c3e7c1ac84d49ee73c1 - view on LGTM.com

new alerts:

  • 1 for Polynomial regular expression used on uncontrolled data

lgtm-com[bot] avatar Sep 06 '22 07:09 lgtm-com[bot]

@fausto-m the build matrix fails, can you please fix so I can start the review process.

@petermuessig WDYT of this feature?

bd82 avatar Sep 29 '22 12:09 bd82

This pull request introduces 1 alert when merging 930cd5f9864999f6a4017fa3f75931c5e17deac7 into 9d0c89c2d912b2c929fb3c3e7c1ac84d49ee73c1 - view on LGTM.com

new alerts:

  • 1 for Polynomial regular expression used on uncontrolled data

lgtm-com[bot] avatar Sep 29 '22 13:09 lgtm-com[bot]

This pull request introduces 1 alert when merging 70539f88d559186798e36d3e8d97600163335c98 into 9d0c89c2d912b2c929fb3c3e7c1ac84d49ee73c1 - view on LGTM.com

new alerts:

  • 1 for Polynomial regular expression used on uncontrolled data

lgtm-com[bot] avatar Sep 29 '22 14:09 lgtm-com[bot]

This pull request introduces 1 alert when merging 44709f1581d46ca5038b90aa9ef697c5d9d7f5fe into 9d0c89c2d912b2c929fb3c3e7c1ac84d49ee73c1 - view on LGTM.com

new alerts:

  • 1 for Polynomial regular expression used on uncontrolled data

lgtm-com[bot] avatar Sep 29 '22 14:09 lgtm-com[bot]

This pull request introduces 1 alert when merging a069a2b4c24977ab7f19166c396b5ef37c70e7b8 into 9d0c89c2d912b2c929fb3c3e7c1ac84d49ee73c1 - view on LGTM.com

new alerts:

  • 1 for Polynomial regular expression used on uncontrolled data

lgtm-com[bot] avatar Sep 30 '22 15:09 lgtm-com[bot]

This pull request introduces 1 alert when merging f1335dcb7a595f5c466cf57ad4dc70faaee59872 into 90807cda6a2bb6925340057865043f97df705586 - view on LGTM.com

new alerts:

  • 1 for Polynomial regular expression used on uncontrolled data

lgtm-com[bot] avatar Oct 03 '22 06:10 lgtm-com[bot]

Hi @bd82, the build matrix issues have been solved now. Node16 failed due to something unrelated to my changes (timeout error from other test). Is there a way to rerun the test without additional commits? I've tried from CircleCI, but the option is disabled for me.

fausto-m avatar Oct 03 '22 06:10 fausto-m

Hi @fausto-m,

I checked out this code and the validation is working fine. However I couldn't get the quick fix to work. Can you explain in a bit more detail how that works? Maybe we should add that to the readme.

I wonder if we should have a setting as well to enable or disable this validation, some projects are just in one language and it might seem as a nuisance for them to get these squiggly lines

uxkjaer avatar Oct 26 '22 11:10 uxkjaer

Hi @uxkjaer,

Thanks for your feedback. You're right, opt-in is probably better for this feature. I'll work on that.

Regarding the quick fix part, you're supposed to get them if the (UI) text in a control property matches a value present in the project's resource bundle file. There's a script that locates the nearest i18n.properties file (nearest in relation to the XML view/fragment being displayed) and uses it for fetching suggestions. If needed, I can add more info to the readme file. Here's what it looks like:

Quick_Fix_for_i18n_l

fausto-m avatar Nov 16 '22 14:11 fausto-m

Hi, I have a few more points to add regarding this feature.

Similar feature is implemented for annotation files in SAP Fiori Tools - XML Annotation Language Server and I think it would make sense to keep the behaviour as similar as possible across the extensions, since users could be using both in the same project.

  1. Properly resolving i18n model to its resource file - manifest.json contains information about the model names and where the resources are located at. Users can change the name of the i18n model or the path to the resource bundle and in that case current implementation may generate a code that actually doesn't work in runtime. Here is a sample fragment of manifest.json with the definition. This #523 PR might help with getting such information from the context.
"sap.ui5": {
        "models": {
            "i18n": {
                "type": "sap.ui.model.resource.ResourceModel",
                "settings": {
                    "bundleName": "sap.fe.cap.travel.i18n.i18n"
                }
            }
      }
}
  1. Current use case seems rather narrow, because it requires the translated text to exist which probably isn't the case most of the time. I would expect that a more common scenario would be one where you generate a new text (in i18n.properties file) for values that are not yet translated as well and save the user time for having to define one.
  2. I'm concerned that maintaining ui5-user-facing-attributes.ts could prove troublesome, because we need to track the changes done to control libraries. It would be good if we could get information which properties should be translated from the ui5 metadata, but it looks like currently it is missing.

voicis avatar Nov 29 '22 16:11 voicis

CLA assistant check
All committers have signed the CLA.

cla-assistant[bot] avatar Oct 18 '23 14:10 cla-assistant[bot]

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

cla-assistant[bot] avatar Oct 18 '23 14:10 cla-assistant[bot]

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

cla-assistant[bot] avatar Oct 18 '23 14:10 cla-assistant[bot]