More robust PO file check
This commit is contained in:
@@ -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: |
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Executable
+51
@@ -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)
|
||||
Reference in New Issue
Block a user