From 40e9497d4852cd6c0fbab269c97e9f2067de6d88 Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Sat, 11 Nov 2023 14:00:02 +0800 Subject: [PATCH] Discard invalid PO files in pull translations GHA workflow --- .github/workflows/pull-translations.yml | 2 ++ lang/discard_invalid_po.sh | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 lang/discard_invalid_po.sh diff --git a/.github/workflows/pull-translations.yml b/.github/workflows/pull-translations.yml index 397b127c46192..088257f13040b 100644 --- a/.github/workflows/pull-translations.yml +++ b/.github/workflows/pull-translations.yml @@ -39,6 +39,8 @@ jobs: env: TX_TOKEN: ${{ secrets.TX_TOKEN }} run: tx pull --force + - name: "Discard invalid translations" + run: ./lang/discard_invalid_po.sh - name: "Update stats" run: ./lang/update_stats.sh - name: Create Pull Request diff --git a/lang/discard_invalid_po.sh b/lang/discard_invalid_po.sh new file mode 100755 index 0000000000000..05bb5d4ba429c --- /dev/null +++ b/lang/discard_invalid_po.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Sometimes PO files pulled from Transifex are not accepted by GNU gettext, for example +# lang/po/hu.po:430257: 'msgid' and 'msgstr' entries do not both begin with '\n' +# lang/po/hu.po:534682: 'msgid' and 'msgstr' entries do not both end with '\n' +# lang/po/hu.po:534692: 'msgid' and 'msgstr' entries do not both end with '\n' +# +# This script tries to compile each updated PO file, and revert PO files that cannot be compiled by GNU gettext. +# So the invalid PO files won't fail Basic Build CI test and block merging the i18n update pull requests. + +function discard_po() { + echo Discarding $1 + git restore $1 +} + +for i in $(git diff --name-only lang/po/*.po); do + msgfmt -o /dev/null $i || discard_po $i +done +