More robust PO file check

This commit is contained in:
Guillaume Meunier
2024-12-02 13:42:43 +01:00
parent e42bf36446
commit 73b3a491ef
3 changed files with 53 additions and 9 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install gettext qt6-base-dev qt6-tools-dev qt6-l10n-tools qtchooser
run: sudo apt-get update && sudo apt-get install gettext qt6-base-dev qt6-tools-dev qt6-l10n-tools qtchooser python3-polib
- name: Check that .po files are up to date
run: |
+1 -8
View File
@@ -10,18 +10,11 @@ RC=0
for i in $(find client/locale -name wivrn.po)
do
msgmerge --quiet --no-fuzzy-matching $i $WIVRN_POT --output-file=$i.new
pot_creation_date=$(grep -o "POT-Creation-Date: [-0-9:+ ]*" $i)
sed -i "s/POT-Creation-Date: [-0-9:+ ]*/$pot_creation_date/" $i.new
diff -U 3 -I '#.*' $i $i.new
tools/check_po.py $WIVRN_POT $i
if [ $? != 0 ]
then
RC=1
echo ::warning file=$i::$i is not up to date
fi
done
+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env python
import sys
import polib
import argparse
import pathlib
parser = argparse.ArgumentParser(
prog='check_po.py',
description='Check that all strings are translated in a .po file')
parser.add_argument('ref', type=pathlib.Path)
parser.add_argument('file', type=pathlib.Path)
args = parser.parse_args()
po_ref = polib.pofile(args.ref)
po_file = polib.pofile(args.file)
entries = [i.msgid for i in po_file.translated_entries()]
language = po_file.metadata['Language']
def flagize(str_in):
str_out = ''
for i in str_in:
str_out += chr(ord(i) + ord('🇦') - ord('A'))
return str_out
flags = {
'Spanish': flagize('ES'),
'French': flagize('FR'),
'Italian': flagize('IT'),
'Japanese': flagize('JP')
}
if language in flags:
flag = flags[language]
else:
flag = ''
missing = 0
for i in po_ref:
if not i.obsolete:
if not i.msgid in entries:
missing = missing + 1
print(f"::warning file={args.file}::{flag} Translation for {repr(i.msgid)} is missing")
if missing > 0:
print(f"::warning file={args.file}::{flag} {missing} missing translation(s) in {language}")
sys.exit(1)