diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 7e7e421fe4..bf99b0d266 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -33,7 +33,7 @@ jobs: - name: Generate updated .ts files and check for l10n errors run: | - ./scripts/utils/generate_ts.sh + ./scripts/utils/generate_ts.sh -a python .github/l10n/check_l10n_issues.py - name: Check for QRC errors diff --git a/.github/workflows/translations.yaml b/.github/workflows/translations.yaml index 114d9f3093..da30342c3e 100644 --- a/.github/workflows/translations.yaml +++ b/.github/workflows/translations.yaml @@ -40,7 +40,7 @@ jobs: - name: Generating translations run: | - ./scripts/utils/generate_ts.sh + ./scripts/utils/generate_ts.sh -a - name: Uploading uses: actions/upload-artifact@v4 diff --git a/scripts/utils/generate_ts.sh b/scripts/utils/generate_ts.sh index f96e2bd899..76d63600e6 100755 --- a/scripts/utils/generate_ts.sh +++ b/scripts/utils/generate_ts.sh @@ -9,11 +9,26 @@ print N "This script generates 'ts' files for the Mozilla VPN app." print N "" +# When the `-a`/`--all` flag is present, .ts files are created +# for every addon. +# Without an argument of `-a` or `--all`, .ts files will NOT +# be created for addons that use the shared strings file. +KEEP_ALL_TS_FILES=0 +# Parse Script arguments +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + (-a | --all) + KEEP_ALL_TS_FILES=1 + shift + ;; + esac +done + cd $(dirname $0)/../.. || die printn Y "Branch name: " -BRANCHNAME="$(git symbolic-ref HEAD 2>/dev/null)" -BRANCHNAME=${BRANCHNAME##refs/heads/} +BRANCHNAME="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" print G "$BRANCHNAME" printn Y "Caching the dep scripts... " @@ -71,6 +86,28 @@ cmake --build build-addons/ mkdir -p addon_ts || die cp build-addons/*.ts addon_ts +# When creating translation files for l10n repo, remove any addon-specific files that use +# shared strings, as they are translated via `strings.yaml`, which is set up for translation in +# `build.py` (which like the addon ts files, is created above when addon's cmake calls `build.py`)" +if [ $KEEP_ALL_TS_FILES == 0 ]; then + print Y "Checking for .ts files using shared strings" + for ts_file in ./addon_ts/* + do + # Use the addon name from the .ts file to build a path to the manifest + manifest_file="./addons/$(basename $ts_file .ts)/manifest.json" + if [[ -f $manifest_file ]]; then + uses_shared_strings=$(jq '.message.usesSharedStrings // false' < $manifest_file) + if [[ "$uses_shared_strings" == "true" ]]; then + print G "Deleting file because the addon uses shared strings: $ts_file" + rm $ts_file + fi + else + die "Manifest file not found: $manifest_file" + fi + done +fi + +# Now that we have the base files set, make sure to include strings from all release branches for branch in $(git branch -r | grep origin/releases); do echo "Checking out to branch $branch" git checkout $branch || die @@ -98,8 +135,27 @@ for branch in $(git branch -r | grep origin/releases); do cmake --build build-addons-$branch/ ts_files="build-addons-$branch/*.ts" + print Y "Finalizing addon strings from $branch..." for f in $ts_files do + # When creating translation files for l10n repo, remove any addon-specific files that use + # shared strings, as they are translated via `strings.yaml`, which is set up for translation in + # `build.py` (which like the addon ts files, is created above when addon's cmake calls `build.py`)" + if [ $KEEP_ALL_TS_FILES == 0 ]; then + # Use the addon name from the .ts file to build a path to the manifest + manifest_file="./addons/$(basename $f .ts)/manifest.json" + if [[ -f $manifest_file ]]; then + uses_shared_strings=$(jq '.message.usesSharedStrings // false' < $manifest_file) + if [[ "$uses_shared_strings" == "true" ]]; then + print G "Deleting file because the addon uses shared strings: $f" + rm $f + continue + fi + else + die "Manifest file not found: $manifest_file" + fi + fi + ts_name=$(basename "$f") if [ -f "addon_ts/${ts_name}" ]; then print Y "File ${ts_name} exists, updating with branch strings..."