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
Open
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ org.eclipse.jdt.groovy.core.prefs

# VS Code
.vscode

# Text Files
**/dictionary.properties
18 changes: 18 additions & 0 deletions scripts/get_message_templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

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.

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();
    }

echo "==== Duplicated keys ===="
awk 'NF {print $1}' temp.properties | sort -g | uniq -d -c
echo "==== End ===="
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
sort -u -t= -k1,1 temp.properties > dictionary.properties ; rm temp.properties
chmod u+x dictionary.properties
}

function main() {
getMessageTemplates
echo "INFO : dictionary.properties generated successfully."
}

main
15 changes: 15 additions & 0 deletions scripts/get_report_node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

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?

}

function main() {
echo -e "\033[35;1;4m=== ReportNode calls out of ...Reports.java files ===\033[0m"
getReportNode
echo "==== End ===="

}

main
Loading