Skip to content

Commit

Permalink
added more text formatting validation
Browse files Browse the repository at this point in the history
  • Loading branch information
piterson05 committed Sep 12, 2023
1 parent 57513e9 commit 14555ec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ def check_entries(entry: xml.dom.minidom.Element, path: list[str]):
found_langs: list[str] = []
lang_attrib = "xml:lang"
should_end_with_format = None
required_text_formatting = set()
required_variables = []
good_string_entries = []
FORMAT_REGEX = r"~.~"
Expand All @@ -562,6 +563,7 @@ def check_entries(entry: xml.dom.minidom.Element, path: list[str]):
if value == "en-US":
found_formats = re.findall(FORMAT_REGEX, get_text_from_node(string_entry))
if (len(found_formats)>0):
required_text_formatting = set(found_formats)
should_end_with_format = found_formats[-1]
required_variables = re.findall(VARIABLE_REGEX, get_text_from_node(string_entry))
found_langs.append(value)
Expand All @@ -576,6 +578,13 @@ def check_entries(entry: xml.dom.minidom.Element, path: list[str]):
Validator.add_formatted_text_to_html(text)
found_formats = re.findall(FORMAT_REGEX, text)
if len(found_formats)>0 and should_end_with_format is not None:
found_formats_set = set(found_formats)
invalid_text_formatting = found_formats_set.difference(required_text_formatting)
missing_text_formatting = required_text_formatting.difference(found_formats_set)
if invalid_text_formatting:
Validator.print_error(f"Found invalid text formatting: {', '.join(invalid_text_formatting)}", path, string_entry.parse_position)
if missing_text_formatting:
Validator.print_error(f"Missing text formatting: {', '.join(missing_text_formatting)}", path, string_entry.parse_position)
found_format = found_formats[-1]
if found_format != should_end_with_format:
Validator.print_error(f"String ends with a wrong format {repr(found_format)}, expected {repr(should_end_with_format)}", path, string_entry.parse_position)
Expand Down

0 comments on commit 14555ec

Please sign in to comment.