Skip to content

Commit

Permalink
Improve translations processing logic
Browse files Browse the repository at this point in the history
Now files are not validated if there are no changes in them.

This change is necessary to correctly identify translation errors in pr.
  • Loading branch information
Danstiv committed Sep 14, 2024
1 parent 586f5f3 commit be8488c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions scripts/process_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from utils import (
convert_braces_to_percents,
convert_percents_to_braces,
file_updated,
get_percent_placeholders,
parse_resx_filename,
)
Expand Down Expand Up @@ -53,6 +54,9 @@ def process_po_files(project_path):
valid_po_files = []
errors = []
for file in project_path.glob("*.po"):
if not file_updated(file):
logger.info(f"File {file.name} is not changed")
continue
if not PO_FILE_REGEX.match(file.name):
errors.append(f"PO file {file} have incorrect name.")
continue
Expand Down Expand Up @@ -125,6 +129,9 @@ def process_lng_files(project_path):
valid_lng_files = []
errors = []
for file in project_path.glob("*.lng"):
if not file_updated(file):
logger.info(f"File {file.name} is not changed")
return
if not LNG_FILE_REGEX.match(file.name):
errors.append(f"lng file {file} have incorrect name.")
continue
Expand Down Expand Up @@ -218,10 +225,10 @@ def validate_placeholders(original_string, translated_string):

def generate_resx_files(project_path):
logger.info("Generating resx files")
resx_files = []
english_resx_files = []
for file in project_path.glob("*.resx"):
if parse_resx_filename(file.name)[1] is None:
resx_files.append(file)
english_resx_files.append(file)
for lng_file in project_path.glob("*.lng"):
if lng_file.name == "english.lng":
continue
Expand All @@ -233,7 +240,10 @@ def generate_resx_files(project_path):
# Let's not add this error again.
continue
errors = []
for resx_file in resx_files:
lng_updated = file_updated(lng_file)
for resx_file in english_resx_files:
if not (lng_updated or file_updated(resx_file)):
continue
errors.extend(generate_resx_from_lng(lng, resx_file))
if errors:
message_manager.add_list_message(
Expand Down Expand Up @@ -306,6 +316,10 @@ def convert_docs_po_to_md_file(po_file):
return [
f"Failed to find source file for {po_file}. File {source_md_file} not found."
]
if file_updated(po_file):
logger.info("Converting because the po file has changed")
elif file_updated(source_md_file):
logger.info("Converting because the source file has changed")
process = subprocess.Popen(
[
"po2md",
Expand Down

0 comments on commit be8488c

Please sign in to comment.