pre-receive-check-translations: match lang codes containing country
Currently re.match('\+[a-z]', l)
will match only language codes like fr, pt, etc. When trying to match against 'pt_BR', this will match only 'pt'. This incorrect match will later cause git.show to fail because 'pt.po' is not part of the commit.
Making it re.match('\+[a-z](_[A-Z]+)?', l)
will correctly match pt_BR, zh_TW, etc.
Steps to reproduce:
# Get Loupe
git clone https://gitlab.gnome.org/GNOME/Loupe
cd Loupe/po
# Download a translation (or use it attached below in the MR):
wget -O zh_TW.po https://l10n.gnome.org/media/upload/loupe-main-po-zh_TW-993280_euiJ76i.merged.po
# Enable the lang code in LINGUAS
echo zh_TW >> LINGUAS
# Commit new translation
git add zh_TW.po LINGUAS
git commit -m 'Add Chinese (Simplified) translation'
# Enable
python -m venv venv
source venv/bin/activate
pip install polib
# Make both 'pre-receive-check-translation' and 'git.py' available to run
# Replace my scenario's 77441fe and c4ee7f8 hash with the parent and new commit hashes, respectively
$ python pre-receive-check-translation 77441fe c4ee7f8 refs/heads/main
# By editing to print CalledProcessError expection, this is the output:
error found: Command 'git show c4ee7f8:po/zh.po' returned non-zero exit status 128
GL-HOOK-ERR translations user cannot modify 'po/LINGUAS'
# er.. filename is zh_TW.po actually
Sample PO: zh_TW.po
Fixes damned-lies#462 (closed)
Edited by Rafael Fontenelle