Skip to content

Commit be8488c

Browse files
committed
Improve translations processing logic
Now files are not validated if there are no changes in them. This change is necessary to correctly identify translation errors in pr.
1 parent 586f5f3 commit be8488c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

scripts/process_translations.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from utils import (
1414
convert_braces_to_percents,
1515
convert_percents_to_braces,
16+
file_updated,
1617
get_percent_placeholders,
1718
parse_resx_filename,
1819
)
@@ -53,6 +54,9 @@ def process_po_files(project_path):
5354
valid_po_files = []
5455
errors = []
5556
for file in project_path.glob("*.po"):
57+
if not file_updated(file):
58+
logger.info(f"File {file.name} is not changed")
59+
continue
5660
if not PO_FILE_REGEX.match(file.name):
5761
errors.append(f"PO file {file} have incorrect name.")
5862
continue
@@ -125,6 +129,9 @@ def process_lng_files(project_path):
125129
valid_lng_files = []
126130
errors = []
127131
for file in project_path.glob("*.lng"):
132+
if not file_updated(file):
133+
logger.info(f"File {file.name} is not changed")
134+
return
128135
if not LNG_FILE_REGEX.match(file.name):
129136
errors.append(f"lng file {file} have incorrect name.")
130137
continue
@@ -218,10 +225,10 @@ def validate_placeholders(original_string, translated_string):
218225

219226
def generate_resx_files(project_path):
220227
logger.info("Generating resx files")
221-
resx_files = []
228+
english_resx_files = []
222229
for file in project_path.glob("*.resx"):
223230
if parse_resx_filename(file.name)[1] is None:
224-
resx_files.append(file)
231+
english_resx_files.append(file)
225232
for lng_file in project_path.glob("*.lng"):
226233
if lng_file.name == "english.lng":
227234
continue
@@ -233,7 +240,10 @@ def generate_resx_files(project_path):
233240
# Let's not add this error again.
234241
continue
235242
errors = []
236-
for resx_file in resx_files:
243+
lng_updated = file_updated(lng_file)
244+
for resx_file in english_resx_files:
245+
if not (lng_updated or file_updated(resx_file)):
246+
continue
237247
errors.extend(generate_resx_from_lng(lng, resx_file))
238248
if errors:
239249
message_manager.add_list_message(
@@ -306,6 +316,10 @@ def convert_docs_po_to_md_file(po_file):
306316
return [
307317
f"Failed to find source file for {po_file}. File {source_md_file} not found."
308318
]
319+
if file_updated(po_file):
320+
logger.info("Converting because the po file has changed")
321+
elif file_updated(source_md_file):
322+
logger.info("Converting because the source file has changed")
309323
process = subprocess.Popen(
310324
[
311325
"po2md",

0 commit comments

Comments
 (0)