Files
upstream-zulip/tools/i18n/sync-translations
upstream-mirror 64898b2c79
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
2026-09-15 15:05:30 +05:00

110 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# See https://zulip.readthedocs.io/en/latest/translating/internationalization.html
# for background on this subsystem.
set -e
set -x
# Check we're on `main` or `\d+\.x`
branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" == "main" ]; then
suffix=""
elif [[ "$branch" =~ ^[0-9]+\.x$ ]]; then
suffix="-${branch/./-}"
else
echo "Unexpected branch name: $branch"
exit 1
fi
git fetch upstream
local_branch="update-translations-$branch"
if git rev-parse --verify --quiet "origin/$local_branch" >/dev/null; then
echo "Remote branch origin/$local_branch already exists -- delete it before continuing"
exit 1
fi
git checkout -b "$local_branch" "upstream/$branch"
# Clear out local any `.mo` files, which cause locale/*/LC_MESSAGES/
# directories to not be empty when their .po files vanish, so git
# doesn't remove the directory.
rm locale/*/LC_MESSAGES/*.mo || true
wlc lock "zulip/frontend$suffix"
wlc lock "zulip/django$suffix"
trap 'wlc unlock "zulip/frontend$suffix" && wlc unlock "zulip/django$suffix"' EXIT
wlc commit "zulip/frontend$suffix"
wlc commit "zulip/django$suffix"
git fetch "https://hosted.weblate.org/git/zulip/django$suffix/"
if [ "$(git rev-list FETCH_HEAD "^upstream/$branch")" == "" ]; then
echo "No changes from Weblate to commit!"
else
git cherry-pick FETCH_HEAD "^upstream/$branch"
git clean -dxf locale/
# Check that everything is normalized into NFC; if it isn't, we
# need to fix it in Weblate, or Weblate will fail to rebase the
# changes out after we push.
files="$(find locale -type f -name '*.json' -o -name '*.po')"
mapfile -t files <<<"$files"
for file in "${files[@]}"; do
uconv -x any-nfc "$file" | sponge -- "$file"
done
git add locale/
if ! git diff-index --quiet --cached HEAD locale/; then
echo "Non-NFC translations exist! Fix them in Weblate first."
git diff --cached
exit 1
fi
# Update locale/*/legacy_stream_translations.json
./tools/i18n/update-for-legacy-translations
# Trim out any now-empty locale directories
find locale/ -type d -empty -delete
git add locale/
# Double-check that they all compile
./manage.py compilemessages --ignore='*'
git commit --amend -m 'i18n: Sync translations from Weblate.'
fi
./manage.py makemessages --all
git add locale/
if git diff-index --quiet --cached HEAD locale/; then
echo "No changes to PO files to commit!"
else
git commit -m 'i18n: Updated .po files for new strings.'
fi
if [ "$(git rev-list HEAD "^upstream/$branch")" == "" ]; then
echo "No commits to push, aborting!"
git checkout "$branch"
git branch -D "$local_branch"
else
git push origin "HEAD:$local_branch"
gh_username="$(gh api user --jq '.login')"
gh pr create --title "Updated translations for $branch from Weblate." --body "" --base "$branch" --head "$gh_username:$local_branch"
gh pr merge --rebase --auto "$gh_username:$local_branch"
commit=$(git rev-parse HEAD)
git checkout "$branch"
git branch -D "$local_branch"
echo "Waiting for PR to merge..."
while [ "$(gh pr list --search "$commit" --state all --json state --jq .[0].state)" != "MERGED" ]; do
sleep 30
done
git push origin --delete "$local_branch"
fi