Skip to content

Remove dead code.

Remove dead code. #47

name: Check for New Translatable Strings
on:
push:
branches: [master]
paths:
- 'app/**/*.cpp'
- 'app/**/*.hpp'
- 'app/**/*.h'
workflow_dispatch:
permissions:
contents: read
discussions: write
jobs:
check-strings:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install gettext
run: sudo apt-get update && sudo apt-get install -y gettext
- name: Generate fresh POT file
run: |
find app -name '*.cpp' -o -name '*.hpp' -o -name '*.h' | sort > /tmp/source_files.txt
xgettext \
--files-from=/tmp/source_files.txt \
--keyword=_ \
--keyword=wxPLURAL:1,2 \
--keyword=wxTRANSLATE \
--language=C++ \
--from-code=UTF-8 \
--add-comments=TRANSLATORS \
--add-location=file \
--package-name=paperback \
--output=/tmp/paperback_new.pot
- name: Compare strings
id: compare
run: |
extract_msgids() {
awk '
/^msgid "/ {
in_msgid = 1
msgid = $0
# Remove the "msgid " prefix
sub(/^msgid /, "", msgid)
next
}
in_msgid && /^"/ {
# Continuation of multi-line msgid
msgid = msgid $0
next
}
in_msgid && /^msgstr/ {
# End of msgid, print it (skiping empty headers)
in_msgid = 0
if (msgid != "\"\"") {
print msgid
}
}
' "$1" | sort
}
extract_msgids po/paperback.pot > /tmp/old_strings.txt
extract_msgids /tmp/paperback_new.pot > /tmp/new_strings.txt
comm -13 /tmp/old_strings.txt /tmp/new_strings.txt > /tmp/added.txt
comm -23 /tmp/old_strings.txt /tmp/new_strings.txt > /tmp/removed.txt
ADDED_COUNT=$(wc -l < /tmp/added.txt | tr -d ' ')
REMOVED_COUNT=$(wc -l < /tmp/removed.txt | tr -d ' ')
echo "added_count=$ADDED_COUNT" >> $GITHUB_OUTPUT
echo "removed_count=$REMOVED_COUNT" >> $GITHUB_OUTPUT
if [ "$ADDED_COUNT" -gt 0 ] || [ "$REMOVED_COUNT" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Found $ADDED_COUNT added and $REMOVED_COUNT removed strings"
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No translatable string changes detected"
fi
printf '%s\n' "## Translatable Strings Update" > /tmp/body.md
printf '\n' >> /tmp/body.md
printf '%s\n' "A recent commit has changed the translatable strings in Paperback." >> /tmp/body.md
printf '\n' >> /tmp/body.md
printf '%s\n' "**$ADDED_COUNT** string(s) added, **$REMOVED_COUNT** string(s) removed." >> /tmp/body.md
printf '\n' >> /tmp/body.md
if [ "$ADDED_COUNT" -gt 0 ]; then
printf '%s\n' "### New strings:" >> /tmp/body.md
printf '\n' >> /tmp/body.md
printf '%s\n' '```' >> /tmp/body.md
cat /tmp/added.txt >> /tmp/body.md
printf '%s\n' '```' >> /tmp/body.md
printf '\n' >> /tmp/body.md
fi
if [ "$REMOVED_COUNT" -gt 0 ]; then
printf '%s\n' "### Removed strings:" >> /tmp/body.md
printf '\n' >> /tmp/body.md
printf '%s\n' '```' >> /tmp/body.md
cat /tmp/removed.txt >> /tmp/body.md
printf '%s\n' '```' >> /tmp/body.md
printf '\n' >> /tmp/body.md
fi
printf '%s\n' "---" >> /tmp/body.md
printf '%s\n' "**Translators:** Please update your .po files using msgmerge." >> /tmp/body.md
printf '%s\n' "See the [translation guide](https://paperback.dev/translations) for instructions." >> /tmp/body.md
printf '\n' >> /tmp/body.md
printf '%s\n' "Commit: ${{ github.sha }}" >> /tmp/body.md
DELIMITER="BODY_$(openssl rand -hex 8)"
echo "body<<$DELIMITER" >> $GITHUB_OUTPUT
cat /tmp/body.md >> $GITHUB_OUTPUT
echo "$DELIMITER" >> $GITHUB_OUTPUT
- name: Close previous translation discussions
if: steps.compare.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Searching for previous translation discussions to close..."
DISCUSSIONS=$(gh api graphql -f query='
query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
discussions(first: 50, states: OPEN) {
nodes {
id
title
number
}
}
}
}
' -f owner="${{ github.repository_owner }}" -f name="${{ github.event.repository.name }}")
echo "$DISCUSSIONS" | jq -r '.data.repository.discussions.nodes[] | select(.title | startswith("New translatable strings")) | .id' | while read -r DISC_ID; do
if [ -n "$DISC_ID" ]; then
echo "Closing discussion: $DISC_ID"
gh api graphql -f query='
mutation($id: ID!) {
closeDiscussion(input: {discussionId: $id, reason: OUTDATED}) {
discussion { id }
}
}
' -f id="$DISC_ID" || echo "Warning: Failed to close discussion $DISC_ID"
fi
done
echo "Finished closing previous discussions"
- name: Create Discussion
if: steps.compare.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPO_DATA=$(gh api graphql -f query='
query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
id
discussionCategories(first: 10) {
nodes { id name }
}
}
}
' -f owner="${{ github.repository_owner }}" -f name="${{ github.event.repository.name }}")
REPO_ID=$(echo "$REPO_DATA" | jq -r '.data.repository.id')
CATEGORY_ID=$(echo "$REPO_DATA" | jq -r '.data.repository.discussionCategories.nodes[] | select(.name=="Announcements") | .id')
RESULT=$(gh api graphql -f query='
mutation($repositoryId: ID!, $categoryId: ID!, $title: String!, $body: String!) {
createDiscussion(input: {repositoryId: $repositoryId, categoryId: $categoryId, title: $title, body: $body}) {
discussion { url }
}
}
' \
-f repositoryId="$REPO_ID" \
-f categoryId="$CATEGORY_ID" \
-f title="New translatable strings - $(date +%Y-%m-%d)" \
-f body="${{ steps.compare.outputs.body }}")
echo "Created new discussion:"
echo "$RESULT" | jq -r '.data.createDiscussion.discussion.url'