From e8aa3f87470197a13981a99ac50459935d056de6 Mon Sep 17 00:00:00 2001 From: crueter Date: Sat, 18 Oct 2025 22:31:02 -0400 Subject: [PATCH] stale translations script Signed-off-by: crueter --- tools/README.md | 8 ++++++-- tools/stale-translations.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100755 tools/stale-translations.sh diff --git a/tools/README.md b/tools/README.md index 14547888a4..061e95bc9c 100644 --- a/tools/README.md +++ b/tools/README.md @@ -20,8 +20,12 @@ Tools for Eden and other subprojects. - `lanczos_gen.c` - `clang-format.sh`: Runs `clang-format` on the entire codebase. * Requires: clang -- `unused-strings.sh`: Finds unused strings in Android `strings.xml` files. - * It's recommended to run this after almost any Android change; this operation is relatively fast. + +## Android +It's recommended to run these scritps after almost any Android change, as they are relatively fast and important both for APK bloat and CI. + +- `unused-strings.sh`: Finds unused strings in `strings.xml` files. +- `stale-translations.sh`: Finds translated strings that aren't present in the source `strings.xml` file. ## Translations diff --git a/tools/stale-translations.sh b/tools/stale-translations.sh new file mode 100755 index 0000000000..791b857a36 --- /dev/null +++ b/tools/stale-translations.sh @@ -0,0 +1,34 @@ +#!/bin/sh -e + +# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +ANDROID=src/android/app/src/main +STRINGS=$ANDROID/res/values/strings.xml + +TMP_DIR=$(mktemp -d) + +SRC="$TMP_DIR"/src +LOCALES="$TMP_DIR"/locales +TRANSLATED="$TMP_DIR"/translated +COMBINED="$TMP_DIR"/combined + +# We start out by getting the list of source strings so we can compare all locale strings to this +grep -e "string name" $STRINGS | grep -v 'translatable="false"' | cut -d'"' -f2 > "$SRC" + +# ... then we determine what locales to check +find $ANDROID/res/values-* -name 'strings.xml' > "$LOCALES" + +while IFS= read -r locale; do + echo "Locale $(echo "$locale" | cut -d"-" -f2- | cut -d"/" -f1)" + grep -e "string name" "$locale" | cut -d'"' -f2 > "$TRANSLATED" + cat "$TRANSLATED" "$SRC" | sort | uniq -u > "$COMBINED" + + # This will also include strings that are present in the source but NOT translated, so we filter those out now: + while IFS= read -r unused; do + { grep -e "string name=\"$unused\"" "$STRINGS" >/dev/null; } || \ + { echo "-- Removing unused translation $unused" && sed "/string name=\"$unused\"/d" "$locale" > "$locale.new" && mv "$locale.new" "$locale"; } + done < "$COMBINED" + + echo "-- done" +done < "$LOCALES" \ No newline at end of file