Skip to content
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
49 changes: 49 additions & 0 deletions .github/workflows/translation-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Translation Coverage Report

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- "**/*.ts" # Trigger only if .ts files are modified

jobs:
translation-report:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
# 1. Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4

# 2. Make the script executable
- name: Make script executable
run: chmod +x ./translate.sh

# 3. Run the translation report script
- name: Run translation report
id: run_report
run: |
echo "Generating translation report..."
OUTPUT=$(./translate.sh stats)
echo "report<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

# 4. Post the report as a PR comment
- name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: translation-report
message: |
### 📝 Translation Coverage Report
The following report was generated for the modified `.ts` files:

<details>

${{ steps.run_report.outputs.report }}

</details>

:white_check_mark: This comment updates automatically if you push new commits.
100 changes: 95 additions & 5 deletions translate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,62 @@ set -euo pipefail
# ./translate.sh update
# ./translate.sh release [qmlui|ui]
# ./translate.sh create <ll_CC> [qmlui|ui]
# ./translate.sh stats

ACTION="${1:-}"

which_qt() {
local base="$1"
command -v "$base" 2>/dev/null || command -v "${base}-qt6" 2>/dev/null || command -v "${base}-qt5" 2>/dev/null || true
}
LRELEASE="$(which_qt lrelease)"
LUPDATE="$(which_qt lupdate)"
: "${LRELEASE:?lrelease not found}"
: "${LUPDATE:?lupdate not found}"

ACTION="${1:-}"
if [[ "$ACTION" != "stats" ]]; then
LRELEASE="$(which_qt lrelease)"
LUPDATE="$(which_qt lupdate)"
: "${LRELEASE:?lrelease not found}"
: "${LUPDATE:?lupdate not found}"
fi

UI_LANGS="de_DE es_ES fr_FR it_IT nl_NL cz_CZ pt_BR ca_ES ja_JP"
QMLUI_LANGS="de_DE es_ES fr_FR it_IT nl_NL ru_RU ca_ES ja_JP uk_UA pl_PL"

STATS_LANGS="de_DE es_ES fr_FR it_IT nl_NL cz_CZ pt_BR ca_ES ja_JP ru_RU uk_UA pl_PL" # merge of both above for stats
EMOJI_FLAGS="🇩🇪 🇪🇸 🇫🇷 🇮🇹 🇳🇱 🇨🇿 🇧🇷 🇪🇸 🇯🇵 🇷🇺 🇺🇦 🇵🇱"

# [path|category_name]
TS_FILES=(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't like this part. It's not dynamic. If we add new ts files I need to remember about this.
The script already finds all the ts files depending on the build.
Can labels be like the folder name? like "fixtureeditor", "plugins/midi" and so on?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, we can, but the result in the table will be very ugly. Maybe we can mix the two? We search for all .ts files, and if we know the path (TS_FILES), we get the friendly name, otherwise, we just put the path

"./fixtureeditor/fixtureeditor_xx_YY.ts|Fixture Editor"
"./launcher/launcher_xx_YY.ts|Launcher"
"./plugins/artnet/src/ArtNet_xx_YY.ts|ArtNet Plugin"
"./plugins/dmx4linux/DMX4Linux_xx_YY.ts|DMX4Linux Plugin"
"./plugins/dmxusb/src/DMX_USB_xx_YY.ts|DMX-USB Plugin"
"./plugins/E1.31/E131_xx_YY.ts|E1.31 Plugin"
"./plugins/enttecwing/src/ENTTEC_Wing_xx_YY.ts|ENTTEC Wing Plugin"
"./plugins/gpio/GPIO_xx_YY.ts|GPIO Plugin"
"./plugins/hid/HID_xx_YY.ts|HID Plugin"
"./plugins/loopback/src/loopback_xx_YY.ts|Loopback Plugin"
"./plugins/midi/src/MIDI_xx_YY.ts|MIDI Plugin"
"./plugins/ola/OLA_xx_YY.ts|OLA Plugin"
"./plugins/os2l/OS2L_xx_YY.ts|OS2L Plugin"
"./plugins/osc/OSC_xx_YY.ts|OSC Plugin"
"./plugins/peperoni/Peperoni_xx_YY.ts|Peperoni Plugin"
"./plugins/spi/SPI_xx_YY.ts|SPI Plugin"
"./plugins/uart/UART_xx_YY.ts|UART Plugin"
"./plugins/udmx/src/uDMX_xx_YY.ts|uDMX Plugin"
"./plugins/velleman/src/Velleman_xx_YY.ts|Velleman Plugin"
"./qmlui/qlcplus_xx_YY.ts|QML UI"
"./ui/src/qlcplus_xx_YY.ts|UI"
"./webaccess/src/webaccess_xx_YY.ts|Web Access"
)

die() { echo "Error: $*" >&2; exit 1; }
usage() {
cat <<EOF
Usage:
$0 update
$0 release [qmlui|ui]
$0 create <ll_CC> [qmlui|ui]
$0 stats
EOF
}

Expand All @@ -47,6 +82,26 @@ find_ts_for_lang() {
fi
}

compute_translation_percentage() {
# read .ts file and count total and translated strings
# simply count <message> and <translation> tags
# and translation with type="unfinished" attribute
# args: ts_file_path
local ts_file_path="$1"
local total translated percent

total=$(awk '/<message/ {c++} END {print c+0}' "$ts_file_path")
translated=$(awk '/<translation/ && $0 !~ /type="unfinished"/ {c++} END {print c+0}' "$ts_file_path")

if [[ "$total" -eq 0 ]]; then
echo 0
return
fi

percent=$(( translated * 100 / total ))
echo "$percent"
}

case "$ACTION" in
update)
echo "Scanning for translation folders and updating .ts files..."
Expand Down Expand Up @@ -153,6 +208,41 @@ case "$ACTION" in
rm -f "$refs_tmp" "$pairs_tmp"
;;

stats)
header="| Projects |"
separator="|----------|"

for flag in $EMOJI_FLAGS; do
header+=" ${flag} |"
separator+="-------|"
done
echo "$header"
echo "$separator"

# parse each ts file
for entry in "${TS_FILES[@]}"; do
IFS='|' read -r ts_file category <<<"$entry"
row="| ${category} |"
for lang in $STATS_LANGS; do
ts_file_path="${ts_file//xx_YY/$lang}"
if [[ -f "$ts_file_path" ]]; then
percent="$(compute_translation_percentage "$ts_file_path")"
if [[ "$percent" -ge 100 ]]; then
row+=" ✅ |"
elif [[ "$percent" -eq 0 ]]; then
row+=" ❌ |"
else
printf -v cell " %3d%% |" "$percent"
row+="$cell"
fi
else
row+=" ❌ |"
fi
done
echo "$row"
done
;;

""|-h|--help)
usage
;;
Expand Down
Loading