Skip to content

Commit

Permalink
VPN-6763: Do not include shared translations when importing addon-spe…
Browse files Browse the repository at this point in the history
…cific ts files (#10091)

* first draft

* fix branch name

* use flag for generate_ts

* better shared strings

* move into existing loop

* Add for first round
  • Loading branch information
mcleinman authored Dec 5, 2024
1 parent 96cb761 commit 82062dd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 58 additions & 2 deletions scripts/utils/generate_ts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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... "
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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..."
Expand Down

0 comments on commit 82062dd

Please sign in to comment.