Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Script for ReportNodes internationalization #121

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

nao1345678
Copy link

@nao1345678 nao1345678 commented Feb 4, 2025

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

Allows to get any ReportNodes that aren't written in the right files and generate a file with the keys of messageTemplate and the corresponding message.

What kind of change does this PR introduce?

It will allow code cleanup and message templates translation.

Does this PR introduce a new Powsybl Action implying to be implemented in simulators or pypowsybl?

  • Yes
  • No

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

@olperr1 olperr1 changed the title Script for ReportNodes internationalization [WIP] Script for ReportNodes internationalization Feb 5, 2025
Naledi EL CHEIKH added 4 commits February 10, 2025 14:29
scripts/get_message_templates.sh Outdated Show resolved Hide resolved
scripts/get_report_node.sh Outdated Show resolved Hide resolved
scripts/get_message_templates.sh Outdated Show resolved Hide resolved
scripts/get_message_templates.sh Outdated Show resolved Hide resolved
scripts/get_message_templates.sh Outdated Show resolved Hide resolved
@olperr1
Copy link
Member

olperr1 commented Feb 11, 2025

Could you also add the "u+x" permission on your scripts?

scripts/get_message_templates.sh Outdated Show resolved Hide resolved
Naledi EL CHEIKH added 2 commits February 12, 2025 14:08
Signed-off-by: Naledi EL CHEIKH <[email protected]>
Signed-off-by: Naledi EL CHEIKH <[email protected]>
.gitignore Outdated Show resolved Hide resolved
function getMessageTemplates() {
grep -R "\\.withMessageTemplate" --exclude="*Test*" --exclude="*.class" "$path" | awk -F'"' '{sub(/[ \t]+$/, "", $2); sub(/[ \t]+$/, "", $3); print $2, $3, $4}' | sort -g | uniq -u | sed "s/,/=/g" > dictionary.properties
echo "==== Duplicated lines ===="
grep -R "\\.withMessageTemplate" --exclude="*Test*" --exclude="*.class" "$path" | awk -F'"' '{sub(/[ \t]+$/, "", $2); sub(/[ \t]+$/, "", $3); print $2, $3, $4}' | sort -g | uniq -d -c | sed "s/,/=/g"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to look for the duplicated keys.
If the same key is used several times, there's a huge probability that the associated template will be different.

For instance, in the file you accidentally pushed, validationWarning was used 2 times with different templates.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I look for the keys, should I only print them in the console ? Or should I print the whole line including the duplicated key ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can either:

  • just print the key
  • print the whole line, with the path.

scripts/get_message_templates.sh Outdated Show resolved Hide resolved
scripts/get_message_templates.sh Show resolved Hide resolved
scripts/get_message_templates.sh Outdated Show resolved Hide resolved

path="$1"
function getMessageTemplates() {
grep -R "\\.withMessageTemplate" --exclude="*Test*" --include="*.java" "$path" | awk -F'"' '{sub(/[ \t]+$/, "", $2); sub(/[ \t]+$/, "", $3); print $2, $3, $4}' | sort -g | sed 's/,/=/' > temp.properties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "exclude" and "include" should be switched in order to really exclude the test java files.


path="$1"
function getReportNode() {
grep --color='auto' -R "\\.withMessageTemplate" --exclude="*Test*" --exclude="*Reports.java" "$path"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the --include="*.java" option in this script?


path="$1"
function getMessageTemplates() {
grep -R "\\.withMessageTemplate" --exclude="*Test*" --include="*.java" "$path" | awk -F'"' '{sub(/[ \t]+$/, "", $2); sub(/[ \t]+$/, "", $3); print $2, $3, $4}' | sort -g | sed 's/,/=/' > temp.properties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have missed it, but in the resulting dictionary, some keys have no message.
In fact, in the source code, the message can be on another line. For instance, in powsybl-core we have:

    protected void reportOnInconclusiveDryRun(ReportNode reportNode, String cause) {
        reportNode.newReportNode()
            .withMessageTemplate("networkModificationDryRun-failure",
                "Dry-run failed for ${networkModification}. The issue is: ${dryRunError}")
            .withUntypedValue("dryRunError", cause)
            .withUntypedValue("networkModification", getName())
            .add();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants