From 701204fb228c3f1629a249a6d2af4cd1a19cf368 Mon Sep 17 00:00:00 2001
From: piterson05 <75865556+piterson05@users.noreply.github.com>
Date: Thu, 14 Sep 2023 01:18:36 +0200
Subject: [PATCH] changed few errors into warnings
---
specialitems.xml | 6 +++---
validator.py | 21 +++++++++++++++++----
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/specialitems.xml b/specialitems.xml
index 5f95133..5c031c2 100644
--- a/specialitems.xml
+++ b/specialitems.xml
@@ -308,7 +308,7 @@
~r~No puedes usar ~s~un ~b~{0} ~s~cuando estás dentro de un vehículo.
Sen ~r~kullanamazsın ~b~{0} ~s~bir aracın içindeyken.
~r~Nie możesz użyć ~s~a ~b~{0} ~s~w środku pojazdu.
- você não pode usar ~s~a ~b~{0} ~s~ quando estiver dentro de um veículo.
+ você não pode usar ~s~a ~b~{0} ~s~quando estiver dentro de um veículo.
@@ -440,7 +440,7 @@
Znalazłeś 20 kolejnych ~o~dyń~s~! Sprawdź swój ekwipunek dla ~b~bonusów~s~.
¡Encontraste 20 ~o~calabazas~s~ más! Revisa tu inventario para encontrar tu ~b~objeto de bonificación~s~.
Du hast 20 weitere ~o~Kürbisse~s~ gefunden! Überprüfe dein Inventat für deinen ~b~Bonus-Gegenstand~s~.
- Você encontrou 20 ~o~abóboras~s~! Verifique seu inventário para encontrar o item de bônus ~b~.~s~.
+ Você encontrou 20 ~o~abóboras~s~! Verifique seu inventário para encontrar o ~b~item de bônus~s~.
@@ -483,7 +483,7 @@
~r~Uwaga: ~s~Nie dostałeś cukierka halloweenowego z powodu błędu 0x88-{0}.
~r~Advertencia: ~s~No pudiste recibir un dulce de Halloween debido a un error 0x88-{0}.
~r~Achtung: ~s~Du konntest keine Halloween-Süßigkeiten erhalten aufgrund eines Fehlers: 0x88-{0}.
- ~r~Aviso: ~s~Não foi possível receber doces de Halloween devido ao erro 0x88-{0}.
+ ~r~Aviso: ~s~Não foi possível receber doces de Halloween devido ao erro 0x88-{0}.
diff --git a/validator.py b/validator.py
index d1c4fc4..67f1074 100644
--- a/validator.py
+++ b/validator.py
@@ -319,6 +319,7 @@ class Validator:
custom_xml_parser = None
preview_formatting = False
main_doc = None
+ warnings_as_errors = False
@staticmethod
def setup_xml_parser():
@@ -377,6 +378,7 @@ def print_error(error: str, location: list[str], custom_file_cursor: tuple[int]
print(f"{colorama.Fore.RED}{txt}{colorama.Fore.RESET}")
else:
print(txt)
+ print()
@staticmethod
@@ -395,11 +397,20 @@ def print_warning(warning: str, location: list[str], custom_file_cursor: tuple[i
print(f"{colorama.Fore.YELLOW}{txt}{colorama.Fore.RESET}")
else:
print(txt)
+ print()
+
+
+ @staticmethod
+ def print_warning_or_error(warning: str, location: list[str], custom_file_cursor: tuple[int] | None = None):
+ if Validator.warnings_as_errors:
+ Validator.print_error(warning, location, custom_file_cursor)
+ else:
+ Validator.print_warning(warning, location, custom_file_cursor)
@staticmethod
def entry_pretty_print(entry: xml.dom.minidom.Element) -> str:
- return f"{entry.tagName}"
+ return f"{entry.tagName}({repr(dict(entry.attributes.items()).get('Id'))})"
@staticmethod
@@ -613,12 +624,12 @@ def check_entries(entry: xml.dom.minidom.Element, path: list[str]):
if text_without_formatting.find("~") != -1:
Validator.print_error(f"Found invalid text formatting (~)", path1, string_entry.parse_position)
if re.findall(r"\s\s+", text_without_formatting):
- Validator.print_error(f"Found too many spaces between words", path1, string_entry.parse_position)
+ Validator.print_warning_or_error(f"Found too many spaces between words", path1, string_entry.parse_position)
if re.findall(WRONG_PUNCTUATION_REGEX, text_without_formatting):
- Validator.print_error(f"Found invalid punctuation mark placement", path1, string_entry.parse_position)
+ Validator.print_warning_or_error(f"Found invalid punctuation mark placement", path1, string_entry.parse_position)
if (Validator.show_lang is not None) and (Validator.show_lang not in found_langs):
if Validator.found_missing_lang <= Validator.display_limit:
- Validator.print_warning(f"Missing translation for {repr(Validator.show_lang)}!", path, element_location)
+ Validator.print_warning_or_error(f"Missing translation for {repr(Validator.show_lang)}!", path, element_location)
Validator.found_missing_lang += 1
@@ -628,6 +639,7 @@ def check_entries(entry: xml.dom.minidom.Element, path: list[str]):
parser = argparse.ArgumentParser(description='Validates localization files')
parser.add_argument('--show_lang', type=str, help='Show missing language localizations', choices=Validator.supported_langs)
parser.add_argument('--preview_formatting', action='store_true', help='Show formatted localizations as HTML file')
+ parser.add_argument('--treat_warnings_as_errors', action='store_true', help='Treat warnings as errors')
parser.add_argument('--display_limit', type=int, default=10, help='Set display limit for missing translations')
args = parser.parse_args()
Validator.custom_xml_parser = Validator.setup_xml_parser()
@@ -635,6 +647,7 @@ def check_entries(entry: xml.dom.minidom.Element, path: list[str]):
Validator.preview_formatting = True
Validator.setup_html_doc()
Validator.display_limit = args.display_limit
+ Validator.warnings_as_errors = args.treat_warnings_as_errors
Validator.show_lang = args.show_lang
with open("index.json", "r", encoding="utf-8") as index_file:
Validator.xml_files = json.load(index_file)