Page MenuHomeGitPull.it

Create script to check for unescaped apostrophes during build
Open, Needs TriagePublic

Description

We should check for unescaped apostrophes in the translations (especially the French one), with a script before the build process (Android build does not report it).

A basic version could be this:

import sys
import re

def check_file(path):
    found_apo = 0
    with open(path, "r", encoding="utf-8") as f:
        for lineno, line in enumerate(f, start=1):
            # Trova tutti gli apostrofi NON preceduti da un backslash
            for match in re.finditer(r"(?<!\\)'", line):
                col = match.start() + 1
                print(f"[RIGA {lineno}, COL {col}] Unescaped apostrophe found:")
                print("   " + line.rstrip())
                print("   " + " " * (col - 1) + "^")
                print()
                found_apo+=1
    print(f"Found {found_apo} unescaped apostophes")
    return (found_apo >0)

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Uso: python3 check_apostrophes.py /percorso/al/file.xml")
    else:
        found = check_file(sys.argv[1])
        if found:
            sys.exit(1)