Index: source/tools/i18n/checkTranslationsFontTags.py =================================================================== --- source/tools/i18n/checkTranslationsFontTags.py +++ source/tools/i18n/checkTranslationsFontTags.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2021 Wildfire Games. +# This file is part of 0 A.D. +# +# 0 A.D. is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# 0 A.D. is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with 0 A.D. If not, see . + +import os, re, sys +from tqdm import tqdm +from tqdm import trange + +def checkTranslationsFontTags(inputFilePath, fontPatterns): + with open(file=inputFilePath,mode="r",encoding="utf-8") as file: + data = file.read() + found = False + subErrors = set() + + for fontPattern in fontPatterns: + matches = list(fontPattern.finditer(data)) + if len(matches) > 0: + for match in matches: + if match is not None: + subErrors.add("\t" + match.group(1)) + found = True + + if found == False: + return + + return inputFilePath.replace("../","") + ":\n" + "\n".join(subErrors) + +def main(): + fontPatterns = [ + # Explanation of the monster below. Some translators + # replace programmer's quotes by quotes from their languages which is + # generally fine for text but breaks font tags. They also sometime add spaces + # Anything that's not [font=\"something\"] [/font] is incorrect. + # We also have a broken example: + # "Epibátēs Athēnaîos [font="sans-bold-16"](Athenian Marine)[/font]" + re.compile(r"\n(.*(?!(\[font=\"sans-bold-16\"\]))(?!(\[font=\\\".*\"\]))\[(?:\s+)?font(?:\s+)?=(?:\s+)?(?:[^(\"|\\)]|(?:\\|\")).*(?:[^(\"|\\)]|\")(?:\s+)?\]).*\n", re.IGNORECASE), + re.compile(r"\n(.*(?!(\[\/font]))\[(?:\s+)?\/(?:\s+)?font(?:\s+)?\])", re.IGNORECASE), + ] + + errors = [] + listOfFiles = os.walk("../../../binaries/data/") + flatFileList = [] + for root, _, filenames in listOfFiles: + for filename in filenames: + if ".po" in filename: + flatFileList.append(os.path.join(root,filename)) + + for filename in tqdm(flatFileList): + try: + error = checkTranslationsFontTags(filename, fontPatterns) + if error is not None: + errors.append(error) + except: + print("Error parsing: " + filename) + + if len(errors): + print("Found errors in the following files: \n" + "\n".join(errors)) + +if __name__ == "__main__": + main()